static int copy_paths(pool *p, const char *from, const char *to) { struct stat st; int res; xaset_t *set; set = get_dir_ctxt(p, (char *) to); res = pr_filter_allow_path(set, to); switch (res) { case 0: break; case PR_FILTER_ERR_FAILS_ALLOW_FILTER: pr_log_debug(DEBUG7, MOD_COPY_VERSION ": path '%s' denied by PathAllowFilter", to); errno = EPERM; return -1; case PR_FILTER_ERR_FAILS_DENY_FILTER: pr_log_debug(DEBUG7, MOD_COPY_VERSION ": path '%s' denied by PathDenyFilter", to); errno = EPERM; return -1; } /* Check whether from is a file, a directory, a symlink, or something * unsupported. */ res = pr_fsio_lstat(from, &st); if (res < 0) { int xerrno = errno; pr_log_debug(DEBUG7, MOD_COPY_VERSION ": error checking '%s': %s", from, strerror(xerrno)); errno = xerrno; return -1; } if (S_ISREG(st.st_mode)) { char *abs_path; pr_fs_clear_cache2(to); res = pr_fsio_stat(to, &st); if (res == 0) { unsigned char *allow_overwrite; allow_overwrite = get_param_ptr(CURRENT_CONF, "AllowOverwrite", FALSE); if (allow_overwrite == NULL || *allow_overwrite == FALSE) { pr_log_debug(DEBUG6, MOD_COPY_VERSION ": AllowOverwrite permission denied for '%s'", to); errno = EACCES; return -1; } } res = pr_fs_copy_file(from, to); if (res < 0) { int xerrno = errno; pr_log_debug(DEBUG7, MOD_COPY_VERSION ": error copying file '%s' to '%s': %s", from, to, strerror(xerrno)); errno = xerrno; return -1; } pr_fs_clear_cache2(to); if (pr_fsio_stat(to, &st) < 0) { pr_trace_msg(trace_channel, 3, "error stat'ing '%s': %s", to, strerror(errno)); } /* Write a TransferLog entry as well. */ abs_path = dir_abs_path(p, to, TRUE); if (session.sf_flags & SF_ANON) { xferlog_write(0, session.c->remote_name, st.st_size, abs_path, (session.sf_flags & SF_ASCII ? 'a' : 'b'), 'd', 'a', session.anon_user, 'c', "_"); } else { xferlog_write(0, session.c->remote_name, st.st_size, abs_path, (session.sf_flags & SF_ASCII ? 'a' : 'b'), 'd', 'r', session.user, 'c', "_"); } } else if (S_ISDIR(st.st_mode)) { res = create_path(p, to); if (res < 0) { int xerrno = errno; pr_log_debug(DEBUG7, MOD_COPY_VERSION ": error creating path '%s': %s", to, strerror(xerrno)); errno = xerrno; return -1; } res = copy_dir(p, from, to); if (res < 0) { int xerrno = errno; pr_log_debug(DEBUG7, MOD_COPY_VERSION ": error copying directory '%s' to '%s': %s", from, to, strerror(xerrno)); errno = xerrno; return -1; } } else if (S_ISLNK(st.st_mode)) { pr_fs_clear_cache2(to); res = pr_fsio_stat(to, &st); if (res == 0) { unsigned char *allow_overwrite; allow_overwrite = get_param_ptr(CURRENT_CONF, "AllowOverwrite", FALSE); if (allow_overwrite == NULL || *allow_overwrite == FALSE) { pr_log_debug(DEBUG6, MOD_COPY_VERSION ": AllowOverwrite permission denied for '%s'", to); errno = EACCES; return -1; } } res = copy_symlink(p, from, to); if (res < 0) { int xerrno = errno; pr_log_debug(DEBUG7, MOD_COPY_VERSION ": error copying symlink '%s' to '%s': %s", from, to, strerror(xerrno)); errno = xerrno; return -1; } } else { pr_log_debug(DEBUG7, MOD_COPY_VERSION ": unsupported file type for '%s'", from); errno = EINVAL; return -1; } return 0; }
int run_haggle() { srand(time(NULL)); #ifdef ENABLE_DEBUG_MANAGER DebugManager *db = NULL; #endif ApplicationManager *am = NULL; DataManager *dm = NULL; // SW: START: SendPriorityManager SendPriorityManager *spm = NULL; // SW: END: SendPriorityManager NodeManager *nm = NULL; ProtocolManager *pm = NULL; ForwardingManager *fm = NULL; SecurityManager *sm = NULL; ConnectivityManager *cm = NULL; LossEstimateManager *lm = NULL; NetworkCodingManager* networkCodingManager = NULL; FragmentationManager* fragmentationManager = NULL; //JM ReplicationManager *replicationManager = NULL; BenchmarkManager *bm = NULL; ResourceManager *rm = NULL; // SW: START: interest manager InterestManager *im = NULL; // SW: END: interest manager ProtocolSocket *p = NULL; #ifdef OS_WINDOWS_MOBILE // For testing we force the deletion of the data store //recreateDataStore = true; #endif int retval = EXIT_FAILURE; #if defined(OS_ANDROID) //mallopt(-1, -1); // MOS - avoid trimming #elif defined(OS_LINUX) mallopt(M_TRIM_THRESHOLD, -1); // MOS - avoid trimming #endif xmlInitParser(); // MOS - this need to be called here for thread-safe libxml use #ifdef DEBUG Trace::trace.enableFileTrace(); #endif HAGGLE_LOG("\n\n****************** HAGGLE STARTUP *********************\n\n"); if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) { HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH); return -1; } retval = write_pid_file(getpid()); if (retval != HAGGLE_PROCESS_NO_ERROR) { switch (retval) { case HAGGLE_PROCESS_BAD_PID: HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_CANNOT_WRITE_PID: HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_ALREADY_RUNNING: HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str()); break; default: HAGGLE_ERR("Unknown PID file error\n"); } shouldCleanupPidFile = false; return -1; } #if defined(OS_UNIX) && !defined(OS_ANDROID) setrawtty(); #endif /* Seed the random number generator */ prng_init(); // SW: START CONFIG PATH (instead of hardcoded ~/.Haggle/config.xml), if (useMemoryDB) { kernel = new HaggleKernel(configFile, new MemoryDataStore(recreateDataStore)); } else { kernel = new HaggleKernel(configFile, new SQLDataStore(recreateDataStore)); } // SW: END CONFIG PATH. if (!kernel || !kernel->init()) { fprintf(stderr, "Kernel initialization error!\n"); return -1; } // Build a Haggle configuration am = new ApplicationManager(kernel); if (!am || !am->init()) { HAGGLE_ERR("Could not initialize application manager\n"); goto finish; } dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate); if (!dm || !dm->init()) { HAGGLE_ERR("Could not initialize data manager\n"); goto finish; } // SW: START: SendPriorityManager spm = new SendPriorityManager(kernel); if (!spm || !spm->init()) { HAGGLE_ERR("Could not initialize send priority manager\n"); goto finish; } // SW: END: SendPriorityManager nm = new NodeManager(kernel); if (!nm || !nm->init()) { HAGGLE_ERR("Could not initialize node manager\n"); goto finish; } pm = new ProtocolManager(kernel); if (!pm || !pm->init()) { HAGGLE_ERR("Could not initialize protocol manager\n"); goto finish; } fm = new ForwardingManager(kernel); if (!fm || !fm->init()) { HAGGLE_ERR("Could not initialize forwarding manager\n"); goto finish; } sm = new SecurityManager(kernel, securityLevel); if (!sm || !sm->init()) { HAGGLE_ERR("Could not initialize security manager\n"); goto finish; } fragmentationManager = new FragmentationManager(kernel); if(!fragmentationManager || !fragmentationManager->init()) { HAGGLE_ERR("Could not initialize fragmentationManager\n"); goto finish; } networkCodingManager = new NetworkCodingManager(kernel); if(!networkCodingManager || !networkCodingManager->init()) { HAGGLE_ERR("Could not initialize networkCodingManager \n"); goto finish; } //JM replicationManager = new ReplicationManager(kernel); if (!replicationManager || !replicationManager->init()) { HAGGLE_ERR("Could not initialize replication manager\n"); goto finish; } lm = new LossEstimateManager(kernel); if(!lm || !lm->init()){ HAGGLE_ERR("Could not initialize LossEstimateManager \n"); goto finish; } #ifdef USE_UNIX_APPLICATION_SOCKET p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm); if (!p || !p->init()) { HAGGLE_ERR("Could not initialize LOCAL protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); #endif p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm); /* Add ConnectivityManager last since it will start to * discover interfaces and generate events. At that * point the other managers should already be * running. */ if (!p || !p->init()) { HAGGLE_ERR("Could not initialize UDP Application protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); // SW: start interest manager im = new InterestManager(kernel); if (!im || !im->init()) { HAGGLE_ERR("Could not initialize interest manager\n"); goto finish; } // SW: end interest manager /* MOS - disable resource mananager due high cpu utilization bug on Android rm = new ResourceManager(kernel); if (!rm || !rm->init()) { HAGGLE_ERR("Could not initialize resource manager\n"); goto finish; } */ if (!isBenchmarking) { cm = new ConnectivityManager(kernel); if (!cm || !cm->init()) { HAGGLE_ERR("Could not initialize connectivity manager\n"); goto finish; } } else { bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num); if (!bm || !bm->init()) { HAGGLE_ERR("Could not initialize benchmark manager\n"); goto finish; } } #if defined(ENABLE_DEBUG_MANAGER) // It seems as if there can be only one accept() per // thread... we need to make the DebugManager register // protocol or something with the ProtocolTCPServer // somehow db = new DebugManager(kernel, runAsInteractive); if (!db || !db->init()) { HAGGLE_ERR("Could not initialize debug manager\n"); /* Treat as non critical error. */ } #endif HAGGLE_DBG("Starting Haggle...\n"); #ifdef OS_WINDOWS_MOBILE if (platform_type(current_platform()) == platform_windows_mobile_professional) tray_notification_add(g_hInstance, kernel); #endif kernel->run(); if(kernel->hasFatalError()) retval = EXIT_FAILURE; else retval = EXIT_SUCCESS; HAGGLE_DBG("Haggle finished...\n"); finish: if (bm) delete bm; if (lm) delete lm; if (fragmentationManager) { delete fragmentationManager; fragmentationManager = NULL; } if (networkCodingManager) delete networkCodingManager; //JM if (replicationManager) delete replicationManager; if (cm) delete cm; if (sm) delete sm; if (fm) delete fm; if (pm) delete pm; if (nm) delete nm; if (dm) delete dm; // SW: START: SendPriorityManager if (spm) delete spm; // SW: END: SendPriorityManager if (am) delete am; // SW: start interest manager if (im) delete im; // SW: end interest manager #if defined(ENABLE_DEBUG_MANAGER) if (db) delete db; #endif if (rm) delete rm; #ifdef OS_WINDOWS_MOBILE tray_notification_remove(); #endif delete kernel; kernel = NULL; xmlCleanupParser(); // MOS return retval; }
static int copy_dir(pool *p, const char *src_dir, const char *dst_dir) { DIR *dh = NULL; struct dirent *dent = NULL; int res = 0; pool *iter_pool = NULL; dh = opendir(src_dir); if (dh == NULL) { pr_log_pri(PR_LOG_WARNING, MOD_COPY_VERSION ": error reading directory '%s': %s", src_dir, strerror(errno)); return -1; } while ((dent = readdir(dh)) != NULL) { struct stat st; char *src_path, *dst_path; pr_signals_handle(); /* Skip "." and ".." */ if (strncmp(dent->d_name, ".", 2) == 0 || strncmp(dent->d_name, "..", 3) == 0) { continue; } if (iter_pool != NULL) { destroy_pool(iter_pool); } iter_pool = pr_pool_create_sz(p, 128); src_path = pdircat(iter_pool, src_dir, dent->d_name, NULL); dst_path = pdircat(iter_pool, dst_dir, dent->d_name, NULL); if (pr_fsio_lstat(src_path, &st) < 0) { pr_log_debug(DEBUG3, MOD_COPY_VERSION ": unable to stat '%s' (%s), skipping", src_path, strerror(errno)); continue; } /* Is this path to a directory? */ if (S_ISDIR(st.st_mode)) { if (create_path(iter_pool, dst_path) < 0) { res = -1; break; } if (copy_dir(iter_pool, src_path, dst_path) < 0) { res = -1; break; } continue; /* Is this path to a regular file? */ } else if (S_ISREG(st.st_mode)) { cmd_rec *cmd; /* Dispatch fake COPY command, e.g. for mod_quotatab */ cmd = pr_cmd_alloc(iter_pool, 4, pstrdup(iter_pool, "SITE"), pstrdup(iter_pool, "COPY"), pstrdup(iter_pool, src_path), pstrdup(iter_pool, dst_path)); cmd->arg = pstrcat(iter_pool, "COPY ", src_path, " ", dst_path, NULL); cmd->cmd_class = CL_WRITE; pr_response_clear(&resp_list); pr_response_clear(&resp_err_list); if (pr_cmd_dispatch_phase(cmd, PRE_CMD, 0) < 0) { int xerrno = errno; pr_log_debug(DEBUG3, MOD_COPY_VERSION ": COPY of '%s' to '%s' blocked by COPY handler: %s", src_path, dst_path, strerror(xerrno)); pr_cmd_dispatch_phase(cmd, POST_CMD_ERR, 0); pr_cmd_dispatch_phase(cmd, LOG_CMD_ERR, 0); pr_response_clear(&resp_err_list); errno = xerrno; res = -1; break; } else { if (pr_fs_copy_file(src_path, dst_path) < 0) { pr_cmd_dispatch_phase(cmd, POST_CMD_ERR, 0); pr_cmd_dispatch_phase(cmd, LOG_CMD_ERR, 0); pr_response_clear(&resp_err_list); res = -1; break; } else { char *abs_path; pr_cmd_dispatch_phase(cmd, POST_CMD, 0); pr_cmd_dispatch_phase(cmd, LOG_CMD, 0); pr_response_clear(&resp_list); /* Write a TransferLog entry as well. */ pr_fs_clear_cache2(dst_path); pr_fsio_stat(dst_path, &st); abs_path = dir_abs_path(p, dst_path, TRUE); if (session.sf_flags & SF_ANON) { xferlog_write(0, session.c->remote_name, st.st_size, abs_path, (session.sf_flags & SF_ASCII ? 'a' : 'b'), 'd', 'a', session.anon_user, 'c', "_"); } else { xferlog_write(0, session.c->remote_name, st.st_size, abs_path, (session.sf_flags & SF_ASCII ? 'a' : 'b'), 'd', 'r', session.user, 'c', "_"); } } } continue; /* Is this path a symlink? */ } else if (S_ISLNK(st.st_mode)) { if (copy_symlink(iter_pool, src_path, dst_path) < 0) { res = -1; break; } continue; /* All other file types are skipped */ } else { pr_log_debug(DEBUG3, MOD_COPY_VERSION ": skipping supported file '%s'", src_path); continue; } } if (iter_pool != NULL) { destroy_pool(iter_pool); } closedir(dh); return res; }
int set_configfs_members(char *name, int new_count, int *new_members, int renew_count, int *renew_members) { char path[PATH_MAX]; char buf[32]; int i, w, fd, rv, id, old_count, *old_members; int do_renew; /* * create lockspace dir if it doesn't exist yet */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s", SPACES_DIR, name); if (!path_exists(path)) { if (create_path(path)) return -1; } /* * remove/add lockspace members */ rv = update_dir_members(name); if (rv) return rv; old_members = dir_members; old_count = dir_members_count; for (i = 0; i < old_count; i++) { id = old_members[i]; if (id_exists(id, new_count, new_members)) continue; memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s/nodes/%d", SPACES_DIR, name, id); log_debug("set_members rmdir \"%s\"", path); rv = rmdir(path); if (rv) { log_error("%s: rmdir failed: %d", path, errno); goto out; } } /* * remove lockspace dir after we've removed all the nodes * (when we're shutting down and adding no new nodes) */ if (!new_count) { memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s", SPACES_DIR, name); log_debug("set_members lockspace rmdir \"%s\"", path); rv = rmdir(path); if (rv) log_error("%s: rmdir failed: %d", path, errno); } for (i = 0; i < new_count; i++) { id = new_members[i]; do_renew = 0; if (id_exists(id, renew_count, renew_members)) do_renew = 1; else if (id_exists(id, old_count, old_members)) continue; if (!is_cluster_member(id)) update_cluster(); /* * create node's dir */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s/nodes/%d", SPACES_DIR, name, id); if (do_renew) { log_debug("set_members renew rmdir \"%s\"", path); rv = rmdir(path); if (rv) { log_error("%s: renew rmdir failed: %d", path, errno); /* don't quit here, there's a case where * this can happen, where a node identified * for renewal was not really added * previously */ } } log_debug("set_members mkdir \"%s\"", path); rv = create_path(path); if (rv) goto out; /* * set node's nodeid */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s/nodes/%d/nodeid", SPACES_DIR, name, id); rv = fd = open(path, O_WRONLY); if (rv < 0) { log_error("%s: open failed: %d", path, errno); goto out; } memset(buf, 0, 32); snprintf(buf, 32, "%d", id); rv = do_write(fd, buf, strlen(buf)); if (rv < 0) { log_error("%s: write failed: %d, %s", path, errno, buf); close(fd); goto out; } close(fd); /* * set node's weight */ w = get_weight(id, name); memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%s/nodes/%d/weight", SPACES_DIR, name, id); rv = fd = open(path, O_WRONLY); if (rv < 0) { log_error("%s: open failed: %d", path, errno); goto out; } memset(buf, 0, 32); snprintf(buf, 32, "%d", w); rv = do_write(fd, buf, strlen(buf)); if (rv < 0) { log_error("%s: write failed: %d, %s", path, errno, buf); close(fd); goto out; } close(fd); } rv = 0; out: return rv; }
static void test_IWbemPath_GetText(void) { static const WCHAR serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.','N','a','m','e','=', '\"','S','e','r','v','i','c','e','\"',0}; static const WCHAR classW[] = {'W','i','n','3','2','_','C','l','a','s','s',0}; static const WCHAR expected1W[] = {'r','o','o','t','\\','c','i','m','v','2',':','W','i','n','3','2','_', 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','d','=', '"','C',':','"',0}; static const WCHAR expected2W[] = {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k','.', 'D','e','v','i','c','e','I','d','=','"','C',':','"',0}; static const WCHAR expected3W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0}; WCHAR buf[128]; ULONG len, count; IWbemPath *path; HRESULT hr; if (!(path = create_path())) return; hr = IWbemPath_GetText( path, 0, NULL, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); hr = IWbemPath_GetText( path, 0, &len, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == 1, "unexpected length %u\n", len ); hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, NULL, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); ok( len == sizeof(buf)/sizeof(buf[0]), "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); todo_wine ok( !buf[0], "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); todo_wine ok( len == 1, "unexpected length %u\n", len ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path8 ); ok( hr == S_OK, "got %08x\n", hr ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 2, "got %u\n", count ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path9 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path9 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path13 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path13 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path14 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path14 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path15 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path15 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path12 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path12 ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 ); ok( hr == S_OK, "got %08x\n", hr ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( !count, "got %u\n", count ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path6 ); ok( hr == S_OK, "got %08x\n", hr ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 2, "got %u\n", count ); len = 0; hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, NULL ); ok( hr == S_OK, "got %08x\n", hr ); ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path16 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path16 ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 ); ok( hr == S_OK, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, path17 ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( path17 ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, expected1W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( expected1W ) + 1, "unexpected length %u\n", len ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, expected2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( expected2W ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path15 ); ok( hr == S_OK, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_SERVER_TOO, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, expected3W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( expected3W ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path18 ); ok( hr == S_OK, "got %08x\n", hr ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path19 ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path20 ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); IWbemPath_Release( path ); if (!(path = create_path())) return; hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, serviceW ); ok( hr == S_OK, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, serviceW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( serviceW ) + 1, "unexpected length %u\n", len ); IWbemPath_Release( path ); if (!(path = create_path())) return; hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, classW ); ok( hr == S_OK, "got %08x\n", hr ); len = sizeof(buf)/sizeof(buf[0]); memset( buf, 0x55, sizeof(buf) ); hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, classW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( classW ) + 1, "unexpected length %u\n", len ); IWbemPath_Release( path ); }
int devtmpfs_create_node(struct device *dev) { const char *tmp = NULL; const char *nodename; const struct cred *curr_cred; mode_t mode = 0; struct nameidata nd; struct dentry *dentry; int err; if (!dev_mnt) return 0; nodename = device_get_devnode(dev, &mode, &tmp); if (!nodename) return -ENOMEM; if (mode == 0) mode = 0600; if (is_blockdev(dev)) mode |= S_IFBLK; else mode |= S_IFCHR; curr_cred = override_creds(&init_cred); err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, nodename, LOOKUP_PARENT, &nd); if (err == -ENOENT) { create_path(nodename); err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, nodename, LOOKUP_PARENT, &nd); } if (err) goto out; dentry = lookup_create(&nd, 0); if (!IS_ERR(dentry)) { err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, dev->devt); if (!err) { struct iattr newattrs; /* fixup possibly umasked mode */ newattrs.ia_mode = mode; newattrs.ia_valid = ATTR_MODE; mutex_lock(&dentry->d_inode->i_mutex); notify_change(dentry, &newattrs); mutex_unlock(&dentry->d_inode->i_mutex); /* mark as kernel-created inode */ dentry->d_inode->i_private = &dev_mnt; } dput(dentry); } else { err = PTR_ERR(dentry); } mutex_unlock(&nd.path.dentry->d_inode->i_mutex); path_put(&nd.path); out: kfree(tmp); revert_creds(curr_cred); return err; }
static int mhdd_readdir( const char *dirname, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info * fi) { int i, j, found; mhdd_debug(MHDD_MSG, "mhdd_readdir: %s\n", dirname); char **dirs = (char **) calloc(mhdd.cdirs+1, sizeof(char *)); struct stat st; typedef struct dir_item { char *name; struct stat *st; } dir_item; // find all dirs for(i = j = found = 0; i<mhdd.cdirs; i++) { char *path = create_path(mhdd.dirs[i], dirname); if (stat(path, &st) == 0) { found++; if (S_ISDIR(st.st_mode)) { dirs[j] = path; j++; continue; } } free(path); } // dirs not found if (dirs[0] == 0) { errno = ENOENT; if (found) errno = ENOTDIR; free(dirs); return -errno; } GHashTable* hash = g_hash_table_new(g_str_hash, g_str_equal); // read directories for (i = 0; dirs[i]; i++) { struct dirent *de; DIR * dh = opendir(dirs[i]); if (!dh) continue; while((de = readdir(dh))) { // find dups if(g_hash_table_lookup(hash, de->d_name)) { continue; } // add item char *object_name = create_path(dirs[i], de->d_name); struct dir_item *new_item = calloc(1, sizeof(struct dir_item)); new_item->name = strdup(de->d_name); new_item->st = calloc(1, sizeof(struct stat)); lstat(object_name, new_item->st); g_hash_table_insert(hash, new_item->name, new_item); free(object_name); } closedir(dh); } dir_item *item; gpointer key, value; GHashTableIter iter; g_hash_table_iter_init(&iter, hash); while(g_hash_table_iter_next (&iter, &key, &value)) { item = (dir_item*) value; int result = filler(buf, item->name, item->st, 0); free(item->name); free(item->st); free(item); if(result) break; } g_hash_table_destroy(hash); for (i = 0; dirs[i]; i++) free(dirs[i]); free(dirs); return 0; }
void init_wire(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, size = MI_SIZE(mi), n; circuitstruct *wp; XGCValues gcv; if (circuits == NULL) { if ((circuits = (circuitstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (circuitstruct))) == NULL) return; } wp = &circuits[MI_SCREEN(mi)]; wp->redrawing = 0; if ((MI_NPIXELS(mi) <= 2) && (wp->init_bits == 0)) { if (wp->stippledGC == None) { gcv.fill_style = FillOpaqueStippled; if ((wp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_wire(display, wp); return; } } WIREBITS(stipples[NUMSTIPPLES - 1], STIPPLESIZE, STIPPLESIZE); WIREBITS(stipples[NUMSTIPPLES - 3], STIPPLESIZE, STIPPLESIZE); WIREBITS(stipples[2], STIPPLESIZE, STIPPLESIZE); } if (MI_NPIXELS(mi) > 2) { wp->colors[0] = (NRAND(MI_NPIXELS(mi))); wp->colors[1] = (wp->colors[0] + MI_NPIXELS(mi) / 6 + NRAND(MI_NPIXELS(mi) / 4 + 1)) % MI_NPIXELS(mi); wp->colors[2] = (wp->colors[1] + MI_NPIXELS(mi) / 6 + NRAND(MI_NPIXELS(mi) / 4 + 1)) % MI_NPIXELS(mi); } free_list(wp); wp->generation = 0; if (MI_IS_FULLRANDOM(mi)) { wp->vertical = (Bool) (LRAND() & 1); } else { wp->vertical = vertical; } wp->width = MI_WIDTH(mi); wp->height = MI_HEIGHT(mi); for (i = 0; i < NEIGHBORKINDS; i++) { if (neighbors == plots[i]) { wp->neighbors = plots[i]; break; } if (i == NEIGHBORKINDS - 1) { i = NRAND(NEIGHBORKINDS - 3) + 1; /* Skip triangular ones */ wp->neighbors = plots[i]; break; } } wp->prob_array[wp->neighbors - 1] = 100; if (wp->neighbors == 3) { wp->prob_array[1] = 67; wp->prob_array[0] = 33; } else { int incr = 24 / wp->neighbors; for (i = wp->neighbors - 2; i >= 0; i--) { wp->prob_array[i] = wp->prob_array[i + 1] - incr - incr * ((i + 1) != wp->neighbors / 2); } } if (wp->neighbors == 6) { int nccols, ncrows; wp->polygon = 6; if (!wp->vertical) { wp->height = MI_WIDTH(mi); wp->width = MI_HEIGHT(mi); } if (wp->width < 8) wp->width = 8; if (wp->height < 8) wp->height = 8; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = wp->ys; nccols = MAX(wp->width / wp->xs - 2, 16); ncrows = MAX(wp->height / wp->ys - 1, 16); wp->ncols = nccols / 2; wp->nrows = ncrows / 2; wp->nrows -= !(wp->nrows & 1); /* Must be odd */ wp->xb = (wp->width - wp->xs * nccols) / 2 + wp->xs; wp->yb = (wp->height - wp->ys * ncrows) / 2 + wp->ys; for (i = 0; i < 6; i++) { if (wp->vertical) { wp->shape.hexagon[i].x = (wp->xs - 1) * hexagonUnit[i].x; wp->shape.hexagon[i].y = ((wp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3; } else { wp->shape.hexagon[i].y = (wp->xs - 1) * hexagonUnit[i].x; wp->shape.hexagon[i].x = ((wp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3; } } } else if (wp->neighbors == 4 || wp->neighbors == 8) { wp->polygon = 4; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = wp->ys; wp->ncols = MAX(wp->width / wp->xs, 8); wp->nrows = MAX(wp->height / wp->ys, 8); wp->xb = (wp->width - wp->xs * wp->ncols) / 2; wp->yb = (wp->height - wp->ys * wp->nrows) / 2; } else { /* TRI */ int orient; wp->polygon = 3; if (!wp->vertical) { wp->height = MI_WIDTH(mi); wp->width = MI_HEIGHT(mi); } if (wp->width < 4) wp->width = 4; if (wp->height < 2) wp->height = 2; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = (int) (1.52 * wp->ys); wp->ncols = (MAX(wp->width / wp->xs - 1, 8) / 2) * 2; wp->nrows = (MAX(wp->height / wp->ys - 1, 8) / 2) * 2 - 1; wp->xb = (wp->width - wp->xs * wp->ncols) / 2 + wp->xs / 2; wp->yb = (wp->height - wp->ys * wp->nrows) / 2 + wp->ys; for (orient = 0; orient < 2; orient++) { for (i = 0; i < 3; i++) { if (wp->vertical) { wp->shape.triangle[orient][i].x = (wp->xs - 2) * triangleUnit[orient][i].x; wp->shape.triangle[orient][i].y = (wp->ys - 2) * triangleUnit[orient][i].y; } else { wp->shape.triangle[orient][i].y = (wp->xs - 2) * triangleUnit[orient][i].x; wp->shape.triangle[orient][i].x = (wp->ys - 2) * triangleUnit[orient][i].y; } } } } /* * I am being a bit naughty here wasting a little bit of memory * but it will give me a real headache to figure out the logic * and to refigure the mappings to save a few bytes * ncols should only need a border of 2 and nrows should only need * a border of 4 when in the neighbors = 9 or 12 */ wp->bncols = wp->ncols + 4; wp->bnrows = wp->nrows + 4; if (MI_IS_VERBOSE(mi)) (void) fprintf(stdout, "neighbors %d, ncols %d, nrows %d\n", wp->neighbors, wp->ncols, wp->nrows); MI_CLEARWINDOW(mi); if (wp->oldcells != NULL) { free(wp->oldcells); wp->oldcells = (unsigned char *) NULL; } if ((wp->oldcells = (unsigned char *) calloc(wp->bncols * wp->bnrows, sizeof (unsigned char))) == NULL) { free_wire(display, wp); return; } if (wp->newcells != NULL) { free(wp->newcells); wp->newcells = (unsigned char *) NULL; } if ((wp->newcells = (unsigned char *) calloc(wp->bncols * wp->bnrows, sizeof (unsigned char))) == NULL) { free_wire(display, wp); return; } n = MI_COUNT(mi); i = (1 + (wp->neighbors == 6)) * wp->ncols * wp->nrows / 4; if (n < -MINWIRES && i > MINWIRES) { n = NRAND(MIN(-n, i) - MINWIRES + 1) + MINWIRES; } else if (n < MINWIRES) { n = MINWIRES; } else if (n > i) { n = MAX(MINWIRES, i); } create_path(wp, n); }
int devtmpfs_create_node(struct device *dev) { const char *tmp = NULL; const char *nodename; const struct cred *curr_cred; struct user_beancounter *curr_ub; mode_t mode = 0; struct nameidata nd; struct dentry *dentry; int err; struct vfsmount *dev_mnt = ve_devmnt(); if (!dev_mnt) return 0; nodename = device_get_devnode(dev, &mode, &tmp); if (!nodename) return -ENOMEM; if (mode == 0) mode = 0600; if (is_blockdev(dev)) mode |= S_IFBLK; else mode |= S_IFCHR; curr_ub = set_exec_ub(&ub0); curr_cred = override_creds(&init_cred); err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, nodename, LOOKUP_PARENT, &nd); if (err == -ENOENT) { /* create missing parent directories */ create_path(nodename); err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt, nodename, LOOKUP_PARENT, &nd); if (err) goto out; } dentry = lookup_create(&nd, 0); if (!IS_ERR(dentry)) { int umask; umask = sys_umask(0000); err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, dev->devt); sys_umask(umask); /* mark as kernel created inode */ if (!err) dentry->d_inode->i_private = &dev_mnt; dput(dentry); } else { err = PTR_ERR(dentry); } mutex_unlock(&nd.path.dentry->d_inode->i_mutex); path_put(&nd.path); out: kfree(tmp); revert_creds(curr_cred); (void)set_exec_ub(curr_ub); return err; }
static void test_IWbemPath_SetText(void) { static const struct { const WCHAR *path; ULONG mode; HRESULT ret; BOOL todo; } test[] = { { path1, 0, WBEM_E_INVALID_PARAMETER }, { path1, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path2, 0, WBEM_E_INVALID_PARAMETER }, { path2, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path3, 0, WBEM_E_INVALID_PARAMETER }, { path3, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path4, 0, WBEM_E_INVALID_PARAMETER }, { path4, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path5, 0, WBEM_E_INVALID_PARAMETER }, { path5, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path6, 0, WBEM_E_INVALID_PARAMETER }, { path6, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path7, 0, WBEM_E_INVALID_PARAMETER }, { path7, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK }, { path7, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }, { path7, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, TRUE }, { path7, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK }, { path8, WBEMPATH_CREATE_ACCEPT_RELATIVE, S_OK }, { path8, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, TRUE }, { path8, WBEMPATH_CREATE_ACCEPT_ALL, S_OK }, { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS, WBEM_E_INVALID_PARAMETER, TRUE }, { path8, WBEMPATH_TREAT_SINGLE_IDENT_AS_NS + 1, S_OK }, { path9, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }, { path10, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, WBEM_E_INVALID_PARAMETER, TRUE }, { path11, WBEMPATH_CREATE_ACCEPT_ABSOLUTE, S_OK }, { path15, WBEMPATH_CREATE_ACCEPT_ALL, S_OK } }; IWbemPath *path; HRESULT hr; UINT i; if (!(path = create_path())) return; hr = IWbemPath_SetText( path, 0, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); for (i = 0; i < sizeof(test)/sizeof(test[0]); i++) { hr = IWbemPath_SetText( path, test[i].mode, test[i].path ); todo_wine_if (test[i].todo) ok( hr == test[i].ret, "%u got %08x\n", i, hr ); if (test[i].ret == S_OK) { WCHAR buf[128]; ULONG len; memset( buf, 0x55, sizeof(buf) ); len = sizeof(buf)/sizeof(buf[0]); hr = IWbemPath_GetText( path, WBEMPATH_GET_ORIGINAL, &len, buf ); ok( hr == S_OK, "%u got %08x\n", i, hr ); ok( !lstrcmpW( buf, test[i].path ), "%u unexpected path %s\n", i, wine_dbgstr_w(buf) ); ok( len == lstrlenW( test[i].path ) + 1, "%u unexpected length %u\n", i, len ); } } IWbemPath_Release( path ); }
int init_data() { OBJECT *tree; long value; if (! get_cookie ('STiK', (long *) & sting_drivers)) { form_alert (1, "[1][ | STinG is not loaded or enabled ! ][ Hmmm ]"); return (0); } if (sting_drivers == 0L) { form_alert (1, "[1][ | STinG is not loaded or enabled ! ][ Hmmm ]"); return (0); } if (strcmp (sting_drivers->magic, MAGIC) != 0) { form_alert (1, "[1][ | STinG structures corrupted ! ][ F**k ]"); return (0); } log_this = (LOG_IT *) (*sting_drivers->get_dftab) ("LOGSTING : QUERY"); if (log_this == NULL) { form_alert (1, "[1][ | LogSTinG is not installed ! ][ Ooops ]"); return (0); } rsrc_gaddr (R_TREE, LOGCTRL, & tree); strncpy (& tree[VERSION].ob_spec.free_string[1], log_this->version, 3); tree[ACTIVE ].ob_state = (log_this->generic[0]) ? SELECTED : NORMAL; tree[PARAS ].ob_state = (log_this->generic[1]) ? SELECTED : NORMAL; tree[POINTER ].ob_state = (log_this->generic[2]) ? SELECTED : NORMAL; tree[BUFFER ].ob_state = (log_this->generic[3]) ? SELECTED : NORMAL; tree[INTERNAL].ob_state = (log_this->generic[4]) ? SELECTED : NORMAL; tree[CACHE ].ob_state = (log_this->generic[5]) ? SELECTED : NORMAL; tree[FILE ].ob_state = (log_this->generic[6]) ? NORMAL : SELECTED; tree[PIPE ].ob_state = (log_this->generic[6]) ? SELECTED : NORMAL; strcpy (path, log_this->path); create_path(); if (cli_num > log_this->cli_num) cli_num = log_this->cli_num; if (mod_num > log_this->mod_num) mod_num = log_this->mod_num; memcpy (cli_set, log_this->client_itf, cli_num); memcpy (mod_set, log_this->module_itf, mod_num); if (get_cookie ('MagX', & value)) { if ((value = * (long *) (value + 8) + 12 * sizeof (long)) > 100) { if (* (int *) value >= 0x300) return (1); } } if (get_cookie ('MiNT', & value)) { if (value >= 0x100) return (1); } tree[PIPE].ob_state &= ~SELECTED; tree[PIPE].ob_state |= DISABLED; tree[PIPENAM].ob_state |= DISABLED; tree[FILE].ob_state |= SELECTED; return (1); }
static void test_IWbemPath_SetNamespaceAt(void) { static const ULONGLONG expected_flags = WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_V1_COMPLIANT | WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY; static const WCHAR rootW[] = {'r','o','o','t',0}; static const WCHAR cimv2W[] = {'c','i','m','v','2',0}; IWbemPath *path; WCHAR buf[16]; ULONG len, count; ULONGLONG flags; HRESULT hr; if (!(path = create_path())) return; hr = IWbemPath_SetNamespaceAt( path, 0, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_SetNamespaceAt( path, 1, cimv2W ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_SetNamespaceAt( path, 0, cimv2W ); ok( hr == S_OK, "got %08x\n", hr ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 1, "got %u\n", count ); flags = 0; hr = IWbemPath_GetInfo( path, 0, &flags ); ok( hr == S_OK, "got %08x\n", hr ); ok( flags == expected_flags, "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags ); buf[0] = 0; len = sizeof(buf) / sizeof(buf[0]); hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_SetNamespaceAt( path, 0, rootW ); ok( hr == S_OK, "got %08x\n", hr ); flags = 0; hr = IWbemPath_GetInfo( path, 0, &flags ); ok( hr == S_OK, "got %08x\n", hr ); ok( flags == expected_flags, "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 2, "got %u\n", count ); buf[0] = 0; len = sizeof(buf) / sizeof(buf[0]); hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, rootW ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( rootW ) + 1, "unexpected length %u\n", len ); buf[0] = 0; len = sizeof(buf) / sizeof(buf[0]); hr = IWbemPath_GetNamespaceAt( path, 1, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len ); IWbemPath_Release( path ); }
static void test_IWbemPath_RemoveNamespaceAt(void) { static const ULONGLONG expected_flags = WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF | WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER; static const WCHAR cimv2W[] = {'c','i','m','v','2',0}; IWbemPath *path; WCHAR buf[16]; ULONG len, count; ULONGLONG flags; HRESULT hr; if (!(path = create_path())) return; hr = IWbemPath_RemoveNamespaceAt( path, 0 ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 ); ok( hr == S_OK, "got %08x\n", hr ); flags = 0; hr = IWbemPath_GetInfo( path, 0, &flags ); ok( hr == S_OK, "got %08x\n", hr ); ok( flags == expected_flags, "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 2, "got %u\n", count ); hr = IWbemPath_RemoveNamespaceAt( path, 0 ); ok( hr == S_OK, "got %08x\n", hr ); flags = 0; hr = IWbemPath_GetInfo( path, 0, &flags ); ok( hr == S_OK, "got %08x\n", hr ); ok( flags == expected_flags, "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( count == 1, "got %u\n", count ); buf[0] = 0; len = sizeof(buf) / sizeof(buf[0]); hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf ); ok( hr == S_OK, "got %08x\n", hr ); ok( !lstrcmpW( buf, cimv2W ), "unexpected buffer contents %s\n", wine_dbgstr_w(buf) ); ok( len == lstrlenW( cimv2W ) + 1, "unexpected length %u\n", len ); hr = IWbemPath_RemoveNamespaceAt( path, 0 ); ok( hr == S_OK, "got %08x\n", hr ); flags = 0; hr = IWbemPath_GetInfo( path, 0, &flags ); ok( hr == S_OK, "got %08x\n", hr ); ok( flags == expected_flags, "got %lx%08lx\n", (unsigned long)(flags >> 32), (unsigned long)flags ); count = 0xdeadbeef; hr = IWbemPath_GetNamespaceCount( path, &count ); ok( hr == S_OK, "got %08x\n", hr ); ok( !count, "got %u\n", count ); buf[0] = 0; len = sizeof(buf) / sizeof(buf[0]); hr = IWbemPath_GetNamespaceAt( path, 0, &len, buf ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); IWbemPath_Release( path ); }
static void test_IWbemPath_GetInfo(void) { IWbemPath *path; HRESULT hr; ULONGLONG resp; if (!(path = create_path())) return; hr = IWbemPath_GetInfo( path, 0, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_GetInfo( path, 1, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); resp = 0xdeadbeef; hr = IWbemPath_GetInfo( path, 0, &resp ); ok( hr == S_OK, "got %08x\n", hr ); ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY), "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path17 ); ok( hr == S_OK, "got %08x\n", hr ); hr = IWbemPath_GetInfo( path, 0, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); hr = IWbemPath_GetInfo( path, 1, NULL ); ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr ); resp = 0xdeadbeef; hr = IWbemPath_GetInfo( path, 0, &resp ); ok( hr == S_OK, "got %08x\n", hr ); ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_INST_REF | WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT | WBEMPATH_INFO_PATH_HAD_SERVER), "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp ); IWbemPath_Release( path ); if (!(path = create_path())) return; hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path12 ); ok( hr == S_OK, "got %08x\n", hr ); resp = 0xdeadbeef; hr = IWbemPath_GetInfo( path, 0, &resp ); ok( hr == S_OK, "got %08x\n", hr ); ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_IS_CLASS_REF | WBEMPATH_INFO_HAS_SUBSCOPES | WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT), "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp ); hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, path1 ); ok( hr == S_OK, "got %08x\n", hr ); resp = 0xdeadbeef; hr = IWbemPath_GetInfo( path, 0, &resp ); ok( hr == S_OK, "got %08x\n", hr ); ok( resp == (WBEMPATH_INFO_ANON_LOCAL_MACHINE | WBEMPATH_INFO_SERVER_NAMESPACE_ONLY), "got %lx%08lx\n", (unsigned long)(resp >> 32), (unsigned long)resp ); IWbemPath_Release( path ); }
int open_file(const char *file_name, bool for_reading, uint64_t write_length) { static bool created_path_to_save_files = false; int fd = -1; char full_filename[MAX_FILENAME_LENGTH] = {0}; int write_flags = O_CREAT | O_WRONLY | O_TRUNC; #ifndef WINDOWSPC struct stat fileInfo; #endif if (file_name == 0 || file_name[0] == 0) { dbg(LOG_ERROR, "Invalid file name"); return fd; } if (for_reading) { #ifdef WINDOWSPC _sopen_s(&fd, file_name, O_RDONLY | _O_BINARY, _SH_DENYNO, 0); #else fd = open(file_name, O_RDONLY); #endif } else { if (strlcpy(full_filename, kickstart_options.path_to_save_files, sizeof(full_filename)) >= sizeof(full_filename) || strlcat(full_filename, kickstart_options.saved_file_prefix, sizeof(full_filename)) >= sizeof(full_filename) || strlcat(full_filename, file_name, sizeof(full_filename)) >= sizeof(full_filename)) { dbg(LOG_ERROR, "String was truncated while concatenating"); return fd; } if(false == created_path_to_save_files && strlen(kickstart_options.path_to_save_files) > 0) { if(create_path(kickstart_options.path_to_save_files) != true) { dbg(LOG_ERROR, "Could not create directory \"%s\" to save files into", kickstart_options.path_to_save_files); return fd; } created_path_to_save_files = true; } dbg(LOG_STATUS, "Opening file '%s' for writing", full_filename); #ifdef WINDOWSPC _sopen_s (&fd, full_filename, write_flags | _O_BINARY, _SH_DENYNO, _S_IREAD | _S_IWRITE); #else if (stat(full_filename, &fileInfo) == 0 && S_ISBLK(fileInfo.st_mode)) { // If the file is a block device if (0 == write_length % fileInfo.st_blksize) { write_flags = write_flags | O_DIRECT; } } fd = open (full_filename, write_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); #endif } if (-1 == fd) { dbg(LOG_ERROR, "Unable to open input file %s. Error %d: %s", full_filename, errno, strerror (errno)); } return fd; }
// rename static int mhdd_rename(const char *from, const char *to) { mhdd_debug(MHDD_MSG, "mhdd_rename: from = %s to = %s\n", from, to); int i, res; struct stat sto, sfrom; char *obj_from, *obj_to; int from_is_dir = 0, to_is_dir = 0, from_is_file = 0, to_is_file = 0; int to_dir_is_empty = 1; if (strcmp(from, to) == 0) return 0; /* seek for possible errors */ for (i = 0; i < mhdd.cdirs; i++) { obj_to = create_path(mhdd.dirs[i], to); obj_from = create_path(mhdd.dirs[i], from); if (stat(obj_to, &sto) == 0) { if (S_ISDIR(sto.st_mode)) { to_is_dir++; if (!dir_is_empty(obj_to)) to_dir_is_empty = 0; } else to_is_file++; } if (stat(obj_from, &sfrom) == 0) { if (S_ISDIR (sfrom.st_mode)) from_is_dir++; else from_is_file++; } free(obj_from); free(obj_to); if (to_is_file && from_is_dir) return -ENOTDIR; if (to_is_file && to_is_dir) return -ENOTEMPTY; if (from_is_dir && !to_dir_is_empty) return -ENOTEMPTY; } /* parent 'to' path doesn't exists */ char *pto = get_parent_path (to); if (find_path_id(pto) == -1) { free (pto); return -ENOENT; } free (pto); int *renamed_on = calloc(mhdd.cdirs, sizeof(int)); if (!renamed_on) return -ENOMEM; /* rename first, then unlink, so we never see a nonexistent file */ for (i = 0; i < mhdd.cdirs; i++) { obj_to = create_path(mhdd.dirs[i], to); obj_from = create_path(mhdd.dirs[i], from); if (stat(obj_from, &sfrom) == 0) { /* if from is dir and at the same time file, we only rename dir */ if (from_is_dir && from_is_file) { if (!S_ISDIR(sfrom.st_mode)) { free(obj_from); free(obj_to); continue; } } create_parent_dirs(i, to); mhdd_debug(MHDD_MSG, "mhdd_rename: rename %s -> %s\n", obj_from, obj_to); res = rename(obj_from, obj_to); if (res == -1) { free(obj_from); free(obj_to); free(renamed_on); return -errno; } renamed_on[i] = 1; } free(obj_from); free(obj_to); } /* now unlink */ for (i = 0; i < mhdd.cdirs; i++) { /* don't delete if we already renamed. */ if (renamed_on[i]) continue; obj_to = create_path(mhdd.dirs[i], to); obj_from = create_path(mhdd.dirs[i], from); if (stat(obj_from, &sfrom) != 0) { /* from and to are files, so we must remove to files */ if (from_is_file && to_is_file && !from_is_dir) { if (stat(obj_to, &sto) == 0) { mhdd_debug(MHDD_MSG, "mhdd_rename: unlink %s\n", obj_to); if (unlink(obj_to) == -1) { free(obj_from); free(obj_to); return -errno; } } } } free(obj_from); free(obj_to); } free(renamed_on); return 0; }
/** * ffmpeg_open * Opens an mpeg file using the new libavformat method. Both mpeg1 * and mpeg4 are supported. However, if the current ffmpeg version doesn't allow * mpeg1 with non-standard framerate, the open will fail. Timelapse is a special * case and is tested separately. * * Returns * A new allocated ffmpeg struct or NULL if any error happens. */ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, unsigned char *y, unsigned char *u, unsigned char *v, int width, int height, int rate, int bps, int vbr, int tlapse) { AVCodecContext *c; AVCodec *codec; struct ffmpeg *ffmpeg; int ret; char errstr[128]; /* * Allocate space for our ffmpeg structure. This structure contains all the * codec and image information we need to generate movies. */ ffmpeg = mymalloc(sizeof(struct ffmpeg)); ffmpeg->vbr = vbr; ffmpeg->tlapse = tlapse; /* Store codec name in ffmpeg->codec, with buffer overflow check. */ snprintf(ffmpeg->codec, sizeof(ffmpeg->codec), "%s", ffmpeg_video_codec); /* Allocation the output media context. */ ffmpeg->oc = avformat_alloc_context(); if (!ffmpeg->oc) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not allocate output context"); ffmpeg_cleanups(ffmpeg); return NULL; } /* Setup output format */ if (ffmpeg->tlapse == TIMELAPSE_APPEND){ ffmpeg->oc->oformat = get_oformat("tlapse", filename); } else { ffmpeg->oc->oformat = get_oformat(ffmpeg_video_codec, filename); } if (!ffmpeg->oc->oformat) { ffmpeg_cleanups(ffmpeg); return NULL; } snprintf(ffmpeg->oc->filename, sizeof(ffmpeg->oc->filename), "%s", filename); ffmpeg->video_st = NULL; if (ffmpeg->oc->oformat->video_codec != MY_CODEC_ID_NONE) { codec = avcodec_find_encoder(ffmpeg->oc->oformat->video_codec); if (!codec) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } ffmpeg->video_st = avformat_new_stream(ffmpeg->oc, codec); if (!ffmpeg->video_st) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not alloc stream"); ffmpeg_cleanups(ffmpeg); return NULL; } } else { /* We did not get a proper video codec. */ MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not get the codec"); ffmpeg_cleanups(ffmpeg); return NULL; } ffmpeg->c = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st); c->codec_id = ffmpeg->oc->oformat->video_codec; c->codec_type = AVMEDIA_TYPE_VIDEO; c->bit_rate = bps; c->width = width; c->height = height; c->time_base.num = 1; c->time_base.den = rate; c->gop_size = 12; c->pix_fmt = PIX_FMT_YUV420P; c->max_b_frames = 0; if (strcmp(ffmpeg_video_codec, "ffv1") == 0) c->strict_std_compliance = -2; if (vbr) c->flags |= CODEC_FLAG_QSCALE; if (!strcmp(ffmpeg->oc->oformat->name, "mp4") || !strcmp(ffmpeg->oc->oformat->name, "mov") || !strcmp(ffmpeg->oc->oformat->name, "3gp")) { c->flags |= CODEC_FLAG_GLOBAL_HEADER; } pthread_mutex_lock(&global_lock); ret = avcodec_open2(c, codec, NULL); pthread_mutex_unlock(&global_lock); if (ret < 0) { if (codec->supported_framerates) { const AVRational *fps = codec->supported_framerates; while (fps->num) { MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s Reported FPS Supported %d/%d", fps->num, fps->den); fps++; } } int chkrate = 1; pthread_mutex_lock(&global_lock); while ((chkrate < 36) && (ret != 0)) { c->time_base.den = chkrate; ret = avcodec_open2(c, codec, NULL); chkrate++; } pthread_mutex_unlock(&global_lock); if (ret < 0){ av_strerror(ret, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not open codec %s",errstr); ffmpeg_cleanups(ffmpeg); return NULL; } } MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s Selected Output FPS %d", c->time_base.den); ffmpeg->video_outbuf = NULL; if (!(ffmpeg->oc->oformat->flags & AVFMT_RAWPICTURE)) { ffmpeg->video_outbuf_size = ffmpeg->c->width * 512; ffmpeg->video_outbuf = mymalloc(ffmpeg->video_outbuf_size); } ffmpeg->picture = my_frame_alloc(); if (!ffmpeg->picture) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: could not alloc frame"); ffmpeg_cleanups(ffmpeg); return NULL; } /* Set variable bitrate if requested. */ if (ffmpeg->vbr) ffmpeg->picture->quality = ffmpeg->vbr; /* Set the frame data. */ ffmpeg->picture->data[0] = y; ffmpeg->picture->data[1] = u; ffmpeg->picture->data[2] = v; ffmpeg->picture->linesize[0] = ffmpeg->c->width; ffmpeg->picture->linesize[1] = ffmpeg->c->width / 2; ffmpeg->picture->linesize[2] = ffmpeg->c->width / 2; /* Open the output file, if needed. */ if ((timelapse_exists(filename) == 0) || (ffmpeg->tlapse != TIMELAPSE_APPEND)) { if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { if (avio_open(&ffmpeg->oc->pb, filename, MY_FLAG_WRITE) < 0) { if (errno == ENOENT) { if (create_path(filename) == -1) { ffmpeg_cleanups(ffmpeg); return NULL; } if (avio_open(&ffmpeg->oc->pb, filename, MY_FLAG_WRITE) < 0) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: error opening file %s", filename); ffmpeg_cleanups(ffmpeg); return NULL; } /* Permission denied */ } else if (errno == EACCES) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO,"%s: Permission denied. %s",filename); ffmpeg_cleanups(ffmpeg); return NULL; } else { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", filename); ffmpeg_cleanups(ffmpeg); return NULL; } } } /* Write the stream header, For the TIMELAPSE_APPEND * we write the data via standard file I/O so we close the * items here */ avformat_write_header(ffmpeg->oc, NULL); if (ffmpeg->tlapse == TIMELAPSE_APPEND) { av_write_trailer(ffmpeg->oc); avio_close(ffmpeg->oc->pb); } } return ffmpeg; }
status_t find_directory(directory_which which, dev_t device, bool createIt, char *returnedPath, int32 pathLength) { status_t err = B_OK; dev_t bootDevice = -1; struct fs_info fsInfo; struct stat st; char *buffer = NULL; const char *home = NULL; const char *templatePath = NULL; /* as with the R5 version, no on-stack buffer */ buffer = (char *)malloc(pathLength); memset(buffer, 0, pathLength); /* fiddle with non-boot volume for items that need it */ switch (which) { case B_DESKTOP_DIRECTORY: case B_TRASH_DIRECTORY: bootDevice = dev_for_path("/boot"); if (device <= 0) device = bootDevice; if (fs_stat_dev(device, &fsInfo) < B_OK) { free(buffer); return ENODEV; } if (device != bootDevice) { #ifdef _KERNEL_MODE err = _user_entry_ref_to_path(device, fsInfo.root, /*"."*/ NULL, buffer, pathLength); #else err = _kern_entry_ref_to_path(device, fsInfo.root, /*"."*/ NULL, buffer, pathLength); #endif } else { /* use the user id to find the home folder */ /* done later */ strlcat(buffer, "/boot", pathLength); } break; case B_PACKAGE_LINKS_DIRECTORY: // this is a directory living in rootfs break; default: strlcat(buffer, "/boot", pathLength); break; } if (err < B_OK) { free(buffer); return err; } switch (which) { /* Per volume directories */ case B_DESKTOP_DIRECTORY: if (device == bootDevice || !strcmp(fsInfo.fsh_name, "bfs")) templatePath = "$h/Desktop"; break; case B_TRASH_DIRECTORY: // TODO: eventually put that into the file system API? if (device == bootDevice || !strcmp(fsInfo.fsh_name, "bfs")) templatePath = "trash"; // TODO: add suffix for current user else if (!strcmp(fsInfo.fsh_name, "fat")) templatePath = "RECYCLED/_BEOS_"; break; /* Haiku system directories */ case B_SYSTEM_DIRECTORY: case B_BEOS_SYSTEM_DIRECTORY: case B_SYSTEM_ADDONS_DIRECTORY: case B_SYSTEM_BOOT_DIRECTORY: case B_SYSTEM_FONTS_DIRECTORY: case B_SYSTEM_LIB_DIRECTORY: case B_SYSTEM_SERVERS_DIRECTORY: case B_SYSTEM_APPS_DIRECTORY: case B_SYSTEM_BIN_DIRECTORY: case B_BEOS_ETC_DIRECTORY: case B_SYSTEM_DOCUMENTATION_DIRECTORY: case B_SYSTEM_PREFERENCES_DIRECTORY: case B_SYSTEM_TRANSLATORS_DIRECTORY: case B_SYSTEM_MEDIA_NODES_DIRECTORY: case B_SYSTEM_SOUNDS_DIRECTORY: case B_SYSTEM_DATA_DIRECTORY: case B_SYSTEM_DEVELOP_DIRECTORY: case B_SYSTEM_PACKAGES_DIRECTORY: case B_SYSTEM_HEADERS_DIRECTORY: templatePath = kSystemDirectories[which - B_SYSTEM_DIRECTORY]; break; /* Common directories, shared among users */ case B_COMMON_DIRECTORY: case B_COMMON_SYSTEM_DIRECTORY: case B_COMMON_ADDONS_DIRECTORY: case B_COMMON_BOOT_DIRECTORY: case B_COMMON_FONTS_DIRECTORY: case B_COMMON_LIB_DIRECTORY: case B_COMMON_SERVERS_DIRECTORY: case B_COMMON_BIN_DIRECTORY: case B_COMMON_ETC_DIRECTORY: case B_COMMON_DOCUMENTATION_DIRECTORY: case B_COMMON_SETTINGS_DIRECTORY: case B_COMMON_DEVELOP_DIRECTORY: case B_COMMON_LOG_DIRECTORY: case B_COMMON_SPOOL_DIRECTORY: case B_COMMON_TEMP_DIRECTORY: case B_COMMON_VAR_DIRECTORY: case B_COMMON_TRANSLATORS_DIRECTORY: case B_COMMON_MEDIA_NODES_DIRECTORY: case B_COMMON_SOUNDS_DIRECTORY: case B_COMMON_DATA_DIRECTORY: case B_COMMON_CACHE_DIRECTORY: case B_COMMON_PACKAGES_DIRECTORY: case B_COMMON_HEADERS_DIRECTORY: case B_COMMON_NONPACKAGED_DIRECTORY: case B_COMMON_NONPACKAGED_ADDONS_DIRECTORY: case B_COMMON_NONPACKAGED_TRANSLATORS_DIRECTORY: case B_COMMON_NONPACKAGED_MEDIA_NODES_DIRECTORY: case B_COMMON_NONPACKAGED_BIN_DIRECTORY: case B_COMMON_NONPACKAGED_DATA_DIRECTORY: case B_COMMON_NONPACKAGED_FONTS_DIRECTORY: case B_COMMON_NONPACKAGED_SOUNDS_DIRECTORY: case B_COMMON_NONPACKAGED_DOCUMENTATION_DIRECTORY: case B_COMMON_NONPACKAGED_LIB_DIRECTORY: case B_COMMON_NONPACKAGED_HEADERS_DIRECTORY: templatePath = kCommonDirectories[which - B_COMMON_DIRECTORY]; break; /* User directories */ case B_USER_DIRECTORY: case B_USER_CONFIG_DIRECTORY: case B_USER_ADDONS_DIRECTORY: case B_USER_BOOT_DIRECTORY: case B_USER_FONTS_DIRECTORY: case B_USER_LIB_DIRECTORY: case B_USER_SETTINGS_DIRECTORY: case B_USER_DESKBAR_DIRECTORY: case B_USER_PRINTERS_DIRECTORY: case B_USER_TRANSLATORS_DIRECTORY: case B_USER_MEDIA_NODES_DIRECTORY: case B_USER_SOUNDS_DIRECTORY: case B_USER_DATA_DIRECTORY: case B_USER_CACHE_DIRECTORY: case B_USER_PACKAGES_DIRECTORY: case B_USER_HEADERS_DIRECTORY: case B_USER_NONPACKAGED_DIRECTORY: case B_USER_NONPACKAGED_ADDONS_DIRECTORY: case B_USER_NONPACKAGED_TRANSLATORS_DIRECTORY: case B_USER_NONPACKAGED_MEDIA_NODES_DIRECTORY: case B_USER_NONPACKAGED_BIN_DIRECTORY: case B_USER_NONPACKAGED_DATA_DIRECTORY: case B_USER_NONPACKAGED_FONTS_DIRECTORY: case B_USER_NONPACKAGED_SOUNDS_DIRECTORY: case B_USER_NONPACKAGED_DOCUMENTATION_DIRECTORY: case B_USER_NONPACKAGED_LIB_DIRECTORY: case B_USER_NONPACKAGED_HEADERS_DIRECTORY: templatePath = kUserDirectories[which - B_USER_DIRECTORY]; break; /* Global directories */ case B_APPS_DIRECTORY: templatePath = "apps"; break; case B_PREFERENCES_DIRECTORY: templatePath = "preferences"; break; case B_UTILITIES_DIRECTORY: templatePath = "utilities"; break; case B_PACKAGE_LINKS_DIRECTORY: templatePath = "packages"; break; default: free(buffer); return EINVAL; } err = B_OK; if (templatePath) { if (!strncmp(templatePath, "$h", 2)) { if (bootDevice > -1 && device != bootDevice) { int l = pathLength - strlen(buffer); if (l > 5) strncat(buffer, "/home", 5); } else { #ifndef _KERNEL_MODE #ifdef USE_PWENTS struct passwd pwBuffer; char pwStringBuffer[MAX_PASSWD_BUFFER_SIZE]; struct passwd *pw; if (getpwuid_r(geteuid(), &pwBuffer, pwStringBuffer, sizeof(pwStringBuffer), &pw) == 0) { home = pw->pw_dir; } #endif // USE_PWENTS if (!home) { /* use env var */ home = getenv("HOME"); } #endif // !_KERNEL_MODE if (!home) home = kUserDirectory; strncpy(buffer, home, pathLength); } templatePath += 2; } else strlcat(buffer, "/", pathLength); if (!err && strlen(buffer) + 2 + strlen(templatePath) < (uint32)pathLength) { strcat(buffer, templatePath); } else err = err ? err : E2BIG; } else err = err ? err : ENOENT; if (!err && createIt && stat(buffer, &st) < 0) err = create_path(buffer, 0755); if (!err) strlcpy(returnedPath, buffer, pathLength); free(buffer); return err; }
/** * Tries to create all directories that lead to 'name' with * system("mkdir ..."); */ int create_path_to_file(const char* name) { char path[FILENAME_MAX]; get_path(name,path); return create_path(path); }
static int mhdd_readdir( const char *dirname, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info * fi) { int i, j, found; mhdd_debug(MHDD_MSG, "mhdd_readdir: %s\n", dirname); char **dirs = (char **) calloc(mhdd.cdirs+1, sizeof(char *)); typedef struct dir_item { char *name; struct stat *st; UT_hash_handle hh; } dir_item; dir_item * items_ht = NULL; struct stat st; // find all dirs for(i = j = found = 0; i<mhdd.cdirs; i++) { char *path = create_path(mhdd.dirs[i], dirname); if (stat(path, &st) == 0) { found++; if (S_ISDIR(st.st_mode)) { dirs[j] = path; j++; continue; } } free(path); } // dirs not found if (dirs[0] == 0) { errno = ENOENT; if (found) errno = ENOTDIR; free(dirs); return -errno; } // read directories for (i = 0; dirs[i]; i++) { struct dirent *de; DIR * dh = opendir(dirs[i]); if (!dh) continue; while((de = readdir(dh))) { // find dups struct dir_item *prev; HASH_FIND_STR(items_ht, de->d_name, prev); if (prev) { continue; } // add item char *object_name = create_path(dirs[i], de->d_name); struct dir_item *new_item = calloc(1, sizeof(struct dir_item)); new_item->name = strdup(de->d_name); new_item->st = calloc(1, sizeof(struct stat)); lstat(object_name, new_item->st); HASH_ADD_KEYPTR( hh, items_ht, new_item->name, strlen(new_item->name), new_item ); free(object_name); } closedir(dh); } dir_item *item, *tmp; // fill list HASH_ITER(hh, items_ht, item, tmp) { if (filler(buf, item->name, item->st, 0)) break; } // free memory HASH_ITER(hh, items_ht, item, tmp) { free(item->name); free(item->st); free(item); }
// rename static int mhdd_rename(const char *from, const char *to) { mhdd_debug(MHDD_MSG, "mhdd_rename: from = %s to = %s\n", from, to); int i, res; struct stat sto, sfrom; char *obj_from, *obj_to; int from_is_dir = 0, to_is_dir = 0, from_is_file = 0, to_is_file = 0; int to_dir_is_empty = 1, to_is_link = 0; if (strcmp(from, to) == 0) return 0; /* seek for possible errors */ for (i = 0; i < mhdd.cdirs; i++) { obj_to = create_path(mhdd.dirs[i], to); obj_from = create_path(mhdd.dirs[i], from); if (stat(obj_to, &sto) == 0) { if (S_ISDIR(sto.st_mode)) { to_is_dir++; if (!dir_is_empty(obj_to)) to_dir_is_empty = 0; } else to_is_file++; if (lstat(obj_to, &sto) == 0) { if ((sto.st_mode & S_IFMT) == S_IFLNK) to_is_link++; } } if (stat(obj_from, &sfrom) == 0) { if (S_ISDIR (sfrom.st_mode)) from_is_dir++; else from_is_file++; } free(obj_from); free(obj_to); if (to_is_file && from_is_dir) return -ENOTDIR; if (to_is_file && to_is_dir) return -ENOTEMPTY; if (from_is_dir && !to_dir_is_empty && !to_is_link) return -ENOTEMPTY; } /* parent 'to' path doesn't exists */ char *pto = get_parent_path (to); if (find_path_id(pto) == -1) { free (pto); return -ENOENT; } free (pto); /* rename cycle */ for (i = 0; i < mhdd.cdirs; i++) { obj_to = create_path(mhdd.dirs[i], to); obj_from = create_path(mhdd.dirs[i], from); if (lstat(obj_from, &sfrom) == 0) { /* if from is dir and at the same time file, we only rename dir, using lstat because we should handle symlinks here as well */ if (from_is_dir && from_is_file) { if (!S_ISDIR(sfrom.st_mode)) { free(obj_from); free(obj_to); continue; } } create_parent_dirs(i, to); mhdd_debug(MHDD_MSG, "mhdd_rename: rename %s -> %s\n", obj_from, obj_to); res = rename(obj_from, obj_to); if (res == -1) { free(obj_from); free(obj_to); return -errno; } } else { /* from and to are files, so we must remove to files */ if (from_is_file && to_is_file && !from_is_dir) { if (stat(obj_to, &sto) == 0) { mhdd_debug(MHDD_MSG, "mhdd_rename: unlink %s\n", obj_to); if (unlink(obj_to) == -1) { free(obj_from); free(obj_to); return -errno; } } } } free(obj_from); free(obj_to); } return 0; }
static int write_pid_file(const pid_t pid) { #define BUFLEN 50 char buf[BUFLEN]; string pidfile = PID_FILE; if (!create_path(DEFAULT_DATASTORE_PATH)) { HAGGLE_ERR("Could not create directory path \'%s\'\n", DEFAULT_DATASTORE_PATH); return false; } FILE *fp = fopen(pidfile.c_str(), "r"); if (fp) { pid_t old_pid; bool old_instance_is_running = false; HAGGLE_DBG("Detected old PID file, checking if a daemon is already running...\n"); // The Pid file already exists. Check if the PID in that file is a // running process. int ret = fscanf(fp, "%u", &old_pid); fclose(fp); if (ret == 0 || old_pid == 0) { return HAGGLE_PROCESS_BAD_PID; } #if defined(OS_LINUX) snprintf(buf, BUFLEN, "/proc/%d/cmdline", old_pid); fp = fopen(buf, "r"); if (fp != NULL) { size_t nitems = fread(buf, 1, BUFLEN, fp); if (nitems && strstr(buf, "haggle") != NULL) old_instance_is_running = true; fclose(fp); } #elif defined(OS_UNIX) int res = kill(old_pid, 0); old_instance_is_running = (res != -1); #elif defined(OS_WINDOWS) HANDLE p; p = OpenProcess(0, FALSE, old_pid); old_instance_is_running = (p != NULL); if (p != NULL) CloseHandle(p); #endif if (old_instance_is_running) return HAGGLE_PROCESS_ALREADY_RUNNING; } HAGGLE_DBG("A Haggle daemon is not running, creating new PID file\n"); snprintf(buf, 20, "%u\n", pid); // Ok, open and create the file fp = fopen(pidfile.c_str(), "w+"); if (!fp) return HAGGLE_PROCESS_CANNOT_WRITE_PID; // Write the pid number to the file size_t ret = fwrite(buf, strlen(buf), 1, fp); fclose(fp); if (ret != 1) return HAGGLE_PROCESS_CANNOT_WRITE_PID; return HAGGLE_PROCESS_NO_ERROR; }
int add_configfs_node(int nodeid, char *addr, int addrlen, int local) { char path[PATH_MAX]; char padded_addr[sizeof(struct sockaddr_storage)]; char buf[32]; int rv, fd; log_debug("set_configfs_node %d %s local %d", nodeid, str_ip(addr), local); /* * create comm dir for this node */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d", COMMS_DIR, nodeid); rv = create_path(path); if (rv) return -1; /* * set the nodeid */ memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/nodeid", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } memset(buf, 0, sizeof(buf)); snprintf(buf, 32, "%d", nodeid); rv = do_write(fd, buf, strlen(buf)); if (rv < 0) { log_error("%s: write failed: %d, %s", path, errno, buf); close(fd); return -1; } close(fd); /* * set the address */ memset(padded_addr, 0, sizeof(padded_addr)); memcpy(padded_addr, addr, addrlen); memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/addr", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } rv = do_write(fd, padded_addr, sizeof(struct sockaddr_storage)); if (rv < 0) { log_error("%s: write failed: %d %d", path, errno, rv); close(fd); return -1; } close(fd); /* * set local */ if (!local) goto out; memset(path, 0, PATH_MAX); snprintf(path, PATH_MAX, "%s/%d/local", COMMS_DIR, nodeid); fd = open(path, O_WRONLY); if (fd < 0) { log_error("%s: open failed: %d", path, errno); return -1; } rv = do_write(fd, (void *)"1", strlen("1")); if (rv < 0) { log_error("%s: write failed: %d", path, errno); close(fd); return -1; } close(fd); out: return 0; }
int run_haggle() { #ifdef ENABLE_DEBUG_MANAGER DebugManager *db = NULL; #endif ApplicationManager *am = NULL; DataManager *dm = NULL; NodeManager *nm = NULL; ProtocolManager *pm = NULL; ForwardingManager *fm = NULL; SecurityManager *sm = NULL; ConnectivityManager *cm = NULL; #ifdef BENCHMARK BenchmarkManager *bm = NULL; //recreateDataStore = true; #endif ResourceManager *rm = NULL; ProtocolSocket *p = NULL; #ifdef OS_WINDOWS_MOBILE // For testing we force the deletion of the data store //recreateDataStore = true; #endif int retval = EXIT_FAILURE; if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) { HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH); return -1; } retval = write_pid_file(getpid()); if (retval != HAGGLE_PROCESS_NO_ERROR) { switch (retval) { case HAGGLE_PROCESS_BAD_PID: HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_CANNOT_WRITE_PID: HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_ALREADY_RUNNING: HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str()); break; default: HAGGLE_ERR("Unknown PID file error\n"); } shouldCleanupPidFile = false; return -1; } #if defined(OS_UNIX) && !defined(OS_ANDROID) setrawtty(); #endif /* Seed the random number generator */ prng_init(); kernel = new HaggleKernel(new SQLDataStore(recreateDataStore)); if (!kernel || !kernel->init()) { fprintf(stderr, "Kernel initialization error!\n"); return -1; } // Build a Haggle configuration am = new ApplicationManager(kernel); if (!am || !am->init()) { HAGGLE_ERR("Could not initialize application manager\n"); goto finish; } dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate); if (!dm || !dm->init()) { HAGGLE_ERR("Could not initialize data manager\n"); goto finish; } nm = new NodeManager(kernel); if (!nm || !nm->init()) { HAGGLE_ERR("Could not initialize node manager\n"); goto finish; } pm = new ProtocolManager(kernel); if (!pm || !pm->init()) { HAGGLE_ERR("Could not initialize protocol manager\n"); goto finish; } fm = new ForwardingManager(kernel); if (!fm || !fm->init()) { HAGGLE_ERR("Could not initialize forwarding manager\n"); goto finish; } sm = new SecurityManager(kernel, securityLevel); if (!sm || !sm->init()) { HAGGLE_ERR("Could not initialize security manager\n"); goto finish; } #ifdef USE_UNIX_APPLICATION_SOCKET p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm); if (!p || !p->init()) { HAGGLE_ERR("Could not initialize LOCAL protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); #endif p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm); /* Add ConnectivityManager last since it will start to * discover interfaces and generate events. At that * point the other managers should already be * running. */ if (!p || !p->init()) { HAGGLE_ERR("Could not initialize UDP Application protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); rm = new ResourceManager(kernel); if (!rm || !rm->init()) { HAGGLE_ERR("Could not initialize resource manager\n"); goto finish; } #ifdef BENCHMARK if (!isBenchmarking) { #endif cm = new ConnectivityManager(kernel); if (!cm || !cm->init()) { HAGGLE_ERR("Could not initialize connectivity manager\n"); goto finish; } #ifdef BENCHMARK } else { bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num); if (!bm || !bm->init()) { HAGGLE_ERR("Could not initialize benchmark manager\n"); goto finish; } } #endif #if defined(ENABLE_DEBUG_MANAGER) // It seems as if there can be only one accept() per // thread... we need to make the DebugManager register // protocol or something with the ProtocolTCPServer // somehow db = new DebugManager(kernel, runAsInteractive); if (!db || !db->init()) { HAGGLE_ERR("Could not initialize debug manager\n"); /* Treat as non critical error. */ } #endif HAGGLE_DBG("Starting Haggle...\n"); #ifdef OS_WINDOWS_MOBILE if (platform_type(current_platform()) == platform_windows_mobile_professional) tray_notification_add(g_hInstance, kernel); #endif kernel->run(); retval = EXIT_SUCCESS; HAGGLE_DBG("Haggle finished...\n"); finish: #ifdef BENCHMARK if (bm) delete bm; #endif if (cm) delete cm; if (sm) delete sm; if (fm) delete fm; if (pm) delete pm; if (nm) delete nm; if (dm) delete dm; if (am) delete am; #if defined(ENABLE_DEBUG_MANAGER) if (db) delete db; #endif if (rm) delete rm; #ifdef OS_WINDOWS_MOBILE tray_notification_remove(); #endif delete kernel; kernel = NULL; return retval; }