/** * @brief Initialize NFSd prerequisites * * @param[in] program_name Name of the program * @param[in] host_name Server host name * @param[in] debug_level Debug level * @param[in] log_path Log path */ void nfs_prereq_init(char *program_name, char *host_name, int debug_level, char *log_path) { /* Initialize logging */ SetNamePgm(program_name); SetNameFunction("main"); SetNameHost(host_name); InitLogging(); if (log_path) SetDefaultLogging(log_path); if (debug_level >= 0) SetLevelDebug(debug_level); ReadLogEnvironment(); /* Register error families */ AddFamilyError(ERR_POSIX, "POSIX Errors", tab_systeme_status); AddFamilyError(ERR_HASHTABLE, "HashTable related Errors", tab_errctx_hash); AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); AddFamilyError(ERR_CACHE_INODE, "Cache Inode related Errors", tab_errstatus_cache_inode); }
int main(int argc, char** argv) { InitLogging(argv, android::base::StderrLogger); std::vector<std::string> args; if (argc == 1) { args.push_back("help"); } else { for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { args.insert(args.begin(), "help"); } else { args.push_back(argv[i]); } } } Command* command = Command::FindCommandByName(args[0]); if (command == nullptr) { LOG(ERROR) << "malformed command line: unknown command " << args[0]; return 1; } std::string command_name = args[0]; LOG(DEBUG) << "command '" << command_name << "' starts running"; bool result = command->Run(args); LOG(DEBUG) << "command '" << command_name << "' " << (result ? "finished successfully" : "failed"); return result ? 0 : 1; }
void MainApp::Init(int argc, wxCmdLineArgsArray &argv) { gcTrace(""); if (argc > 0) { for (int x=0; x<argc; x++) { wxString str = argv[x].MakeLower(); if (str == "-dgl") m_bQuiteMode = true; if (str.StartsWith("desura://")) m_szDesuraCache = gcString(argv[x].ToStdString()); } } //char *comAppPath = nullptr; //UTIL::OS::getAppDataPath(&comAppPath); //UTIL::FS::recMakeFolder(comAppPath); //safe_delete(comAppPath); InitLogging(); cc_PrintVersion(); cc_CheckCert(); Msg("Logging Has started\n"); Msg("\n\n"); InitManagers(); InitLocalManagers(); std::string val = UTIL::OS::getConfigValue(REGRUN); gc_autostart.setValue( val.size() > 0 ); //because logging gets init first we need to man reg it RegLogWithWindow(); //because logging gets init before managers we need to reapply the color scheme. LoggingapplyTheme(); loadFrame(wxDEFAULT_FRAME_STYLE); #ifndef NIX if (!m_bQuiteMode) m_wxTBIcon = new TaskBarIcon(this); #endif m_wxTBIcon = nullptr; std::string szAppid = UTIL::OS::getConfigValue(APPID); uint32 appid = -1; if (szAppid.size() > 0) appid = Safe::atoi(szAppid.c_str()); if (appid == BUILDID_BETA || appid == BUILDID_INTERNAL) gc_uploaddumps.setValue(true); }
VOID InitializeLogging() { STATIC_CONTRACT_NOTHROW; if (bLoggingInitialized) return; bLoggingInitialized = true; InitLogging(); // You can call this in the debugger to fetch new settings }
bool loadDll() { #ifndef DEBUG #ifdef WIN32 char message[255] = {0}; if (UTIL::WIN::validateCert(L".\\bin\\scriptcore.dll", message, 255) != ERROR_SUCCESS) { Warning(gcString("Cert validation failed on scriptcore.dll: {0}\n", message)); return false; } #endif #endif #ifdef WIN32 #ifdef DEBUG if (!m_ScriptCore.load("scriptcore-d.dll")) return false; #else if (!m_ScriptCore.load("scriptcore.dll")) return false; #endif #else if (!m_ScriptCore.load("libscriptcore.so")) return false; #endif m_pFactory = m_ScriptCore.getFunction<FactoryFn>("FactoryBuilderScriptCore"); if (!m_pFactory) { unloadDll(); return false; } #ifndef IGNORE_DESURA_LOGGING RegLogFn regLog = m_ScriptCore.getFunction<RegLogFn>("RegDLLCB_SCRIPT"); if (regLog) InitLogging(regLog); else Warning("Failed to setup logging for scriptcore\n"); #endif m_pSetup = (ScriptCoreSetupI*)m_pFactory(SCRIPT_CORE_SETUP); if (!m_pSetup) { unloadDll(); return false; } m_pSetup->useInternalTaskRunner(); return m_pSetup->addItemExtender(&m_Extender); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int showCmd) { // We reserve space for temple.dll as early as possible to avoid rebasing of temple.dll auto& dll = temple::Dll::GetInstance(); dll.ReserveMemoryRange(); Breakpad breakpad; config.Load(); config.Save(); InitLogging(); logger->info("Starting Temple Plus"); logger->info("Version: {}", GetTemplePlusVersion()); logger->info("Commit: {}", GetTemplePlusCommitId()); try { bool userCancelled; auto toeeDir = GetInstallationDir(&userCancelled); if (userCancelled) { return 0; // Not an error, the user cancelled } dll.Load(toeeDir.GetDirectory()); if (dll.HasBeenRebased()) { auto moduleName = dll.FindConflictingModule(); auto msg = format(L"Module '{}' caused temple.dll to be loaded at a different address than usual.\n" L"This will most likely lead to crashes.", moduleName); MessageBox(nullptr, msg.c_str(), L"Module Conflict", MB_OK | MB_ICONWARNING); } TempleFixes::apply(); MH_EnableHook(MH_ALL_HOOKS); auto result = TempleMain(hInstance, lpCmdLine); config.Save(); return result; } catch (const std::exception& e) { logger->error("Uncaught exception: {}", e.what()); auto msg = format("Uncaught exception: {}", e.what()); MessageBoxA(nullptr, msg.c_str(), "Fatal Error", MB_OK | MB_ICONERROR); return 1; } }
int _tmain(int argc, LPTSTR argv[]) { SERVICE_TABLE_ENTRY ServiceTable[] = { {ServiceName, ServiceMain}, {NULL, NULL } }; InitLogging(); if (!StartServiceCtrlDispatcher(ServiceTable)) LogEvent(_T("failed to start the service control dispatcher"), GetLastError(), 101, LOG_ALL); return 0; }
int main(int argc, char** argv) { InitLogging(argv, android::base::StderrLogger); std::vector<std::string> args; android::base::LogSeverity log_severity = android::base::WARNING; if (argc == 1) { args.push_back("help"); } else { for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { args.insert(args.begin(), "help"); } else if (strcmp(argv[i], "--log") == 0) { if (i + 1 < argc) { ++i; auto it = log_severity_map.find(argv[i]); if (it != log_severity_map.end()) { log_severity = it->second; } else { LOG(ERROR) << "Unknown log severity: " << argv[i]; return 1; } } else { LOG(ERROR) << "Missing argument for --log option.\n"; return 1; } } else { args.push_back(argv[i]); } } } android::base::ScopedLogSeverity severity(log_severity); std::unique_ptr<Command> command = CreateCommandInstance(args[0]); if (command == nullptr) { LOG(ERROR) << "malformed command line: unknown command " << args[0]; return 1; } std::string command_name = args[0]; args.erase(args.begin()); LOG(DEBUG) << "command '" << command_name << "' starts running"; bool result = command->Run(args); LOG(DEBUG) << "command '" << command_name << "' " << (result ? "finished successfully" : "failed"); return result ? 0 : 1; }
void initFactory() { bool res = false; #if defined(WIN32) && !defined(DEBUG) && defined(DESURA_OFFICIAL_BUILD) && defined(WITH_CODESIGN) char message[255] = {0}; if (UTIL::WIN::validateCert(L".\\bin\\mcfcore.dll", message, 255) != ERROR_SUCCESS) { Warning(gcString("Cert validation failed on mcfcore.dll: {0}\n", message)); exit(-1); } #endif #ifdef WIN32 res = g_pMCFCore.load("mcfcore.dll"); #else res = g_pMCFCore.load("libmcfcore.so"); #endif if (!res) exit(-1); buildFactory = g_pMCFCore.getFunction<BFACT>("FactoryBuilder"); if (!buildFactory) exit(-1); delFactory = g_pMCFCore.getFunction<DFACT>("FactoryDelete"); if (!delFactory) exit(-1); RegDLLCB_MCF regMsg = g_pMCFCore.getFunction<RegDLLCB_MCF>("RegDLLCB_MCF"); if (regMsg) InitLogging(regMsg); }
main(int argc, char *argv[]) { char localmachine[256]; cache_inode_client_t client; LRU_parameter_t lru_param; LRU_status_t lru_status; cache_inode_fsal_data_t fsdata; fsal_status_t status; fsal_parameter_t init_param; fsal_name_t name; fsal_path_t path; fsal_attrib_mask_t mask; fsal_path_t pathroot; fsal_attrib_list_t attribs; fsal_handle_t root_handle; cache_inode_endofdir_t eod_met; cache_inode_dir_entry_t dirent_array[100]; cache_inode_dir_entry_t dirent_array_loop[5]; unsigned int nbfound; unsigned int begin_cookie = 0; hash_buffer_t key, value; uid_t uid; fsal_cred_t cred; cache_inode_status_t cache_status; cache_inode_parameter_t cache_param; cache_inode_client_parameter_t cache_client_param; hash_table_t *ht = NULL; fsal_attrib_list_t attrlookup; cache_entry_t *cache_entry_root = NULL; cache_entry_t *cache_entry_lookup = NULL; cache_entry_t *cache_entry_lookup2 = NULL; cache_entry_t *cache_entry_lookup3 = NULL; cache_entry_t *cache_entry_lookup4 = NULL; cache_entry_t *cache_entry_lookup5 = NULL; cache_entry_t *cache_entry_lookup6 = NULL; cache_entry_t *cache_entry_dircont = NULL; cache_inode_gc_policy_t gcpol; char *configfile = argv[1]; int i = 0; int rc = 0; /* Init the Buddy System allocation */ if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS) { LogTest("Error while initializing Buddy system allocator"); exit(1); } /* init debug */ SetNamePgm("test_cache_inode"); SetDefaultLogging("TEST"); SetNameFunction("main"); InitLogging(); #if defined( _USE_GHOSTFS ) if(argc != 2) { LogTest("Please set the configuration file as parameter"); exit(1); } #endif /* Obtention du nom de la machine */ if(gethostname(localmachine, sizeof(localmachine)) != 0) { LogError(COMPONENT_STDOUT, ERR_SYS, ERR_GETHOSTNAME, errno); exit(1); } else SetNameHost(localmachine); AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); AddFamilyError(ERR_CACHE_INODE, "FSAL related Errors", tab_errstatus_cache_inode); LogTest( "Starting the test"); LogTest( "-----------------"); #if defined( _USE_GHOSTFS ) if(FSAL_IS_ERROR(status = FSAL_str2path(configfile, strlen(configfile) + 1, &(init_param.fs_specific_info. definition_file)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); } #elif defined( _USE_HPSS ) FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, Flags); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugValue); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TransferType); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, NumRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TotalDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, GKTotalDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, LimitedRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, MaxConnections); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ReuseDataConnections); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, UsePortRange); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RetryStageInp); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DMAPWriteUpdates); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ServerName); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DescName); init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE; strncpy(init_param.fs_specific_info.hpss_config.PrincipalName, HPSS_SSM, HPSS_MAX_PRINCIPAL_NAME); init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; strncpy(init_param.fs_specific_info.hpss_config.KeytabPath, HPSS_KEYTAB, HPSS_MAX_PATH_NAME); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugPath); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, HostName); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RegistrySiteName); #endif /* 2-common info (default) */ FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite); /* Init */ if(FSAL_IS_ERROR(status = FSAL_Init(&init_param))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); } /* getting creds */ uid = getuid(); if(FSAL_IS_ERROR(status = FSAL_GetUserCred(uid, NULL, &cred))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); } /* Init of the cache inode module */ cache_param.hparam.index_size = 31; cache_param.hparam.alphabet_length = 10; /* Buffer seen as a decimal polynom */ cache_param.hparam.nb_node_prealloc = 100; cache_param.hparam.hash_func_key = cache_inode_fsal_hash_func; cache_param.hparam.hash_func_rbt = cache_inode_fsal_rbt_func; cache_param.hparam.hash_func_both = NULL ; /* BUGAZOMEU */ cache_param.hparam.compare_key = cache_inode_compare_key_fsal; cache_param.hparam.key_to_str = display_key; cache_param.hparam.val_to_str = display_value; if((ht = cache_inode_init(cache_param, &cache_status)) == NULL) { LogTest( "Error %d while init hash ", cache_status); } else LogTest( "Hash Table address = %p", ht); /* We need a cache_client to acces the cache */ cache_client_param.attrmask = FSAL_ATTRS_MANDATORY | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_ATIME; cache_client_param.nb_prealloc_entry = 1000; cache_client_param.nb_pre_dir_data = 200; cache_client_param.nb_pre_parent = 1200; cache_client_param.nb_pre_state_v4 = 100; cache_client_param.lru_param.nb_entry_prealloc = 1000; cache_client_param.lru_param.entry_to_str = lru_entry_to_str; cache_client_param.lru_param.clean_entry = lru_clean_entry; cache_client_param.grace_period_attr = 0; cache_client_param.grace_period_link = 0; cache_client_param.grace_period_dirent = 0; cache_client_param.expire_type_attr = CACHE_INODE_EXPIRE_NEVER; cache_client_param.expire_type_link = CACHE_INODE_EXPIRE_NEVER; cache_client_param.expire_type_dirent = CACHE_INODE_EXPIRE_NEVER; /* Init the cache_inode client */ if(cache_inode_client_init(&client, cache_client_param, 0) != 0) exit(1); /* Getting the root of the FS */ if((FSAL_IS_ERROR(status = FSAL_str2path("/", 2, &pathroot)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } attribs.asked_attributes = cache_client_param.attrmask; if((FSAL_IS_ERROR(status = FSAL_lookupPath(pathroot, &cred, &root_handle, &attribs)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } fsdata.cookie = 0; fsdata.handle = root_handle; /* Cache the root of the FS */ if((cache_entry_root = cache_inode_make_root(&fsdata, 1, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't init fs's root"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } /* Lookup a second time (entry should now be cached) */ if((cache_entry_lookup2 = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if(cache_entry_lookup2 != cache_entry_lookup) { LogTest("Error: lookup results should be the same"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup3 = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if((cache_entry_lookup4 = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if(cache_entry_lookup3 != cache_entry_lookup4) { LogTest("Error: lookup results should be the same"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name)))) { LogError(COMPONENT_STDOUT, ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } LogTest( "---------------------------------"); /* The end of all the tests */ LogTest( "All tests exited successfully"); exit(0); } /* main */
////////////////////////////////////////////////////////////////////////////// // // Start // bool AppInit(int argc, char* argv[]) { boost::thread_group threadGroup; CScheduler scheduler; bool fRet = false; // // Parameters // // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() ParseParameters(argc, argv); // Process help and version before taking care about datadir if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version")) { std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n"; if (mapArgs.count("-version")) { strUsage += FormatParagraph(LicenseInfo()); } else { strUsage += "\n" + _("Usage:") + "\n" + " bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n"; strUsage += "\n" + HelpMessage(HMM_BITCOIND); } fprintf(stdout, "%s", strUsage.c_str()); return false; } try { if (!boost::filesystem::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str()); return false; } try { ReadConfigFile(mapArgs, mapMultiArgs); } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); return false; } // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(ChainNameFromCommandLine()); } catch (const std::exception& e) { fprintf(stderr, "Error: %s\n", e.what()); return false; } // Command-line RPC bool fCommandLine = false; for (int i = 1; i < argc; i++) if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:")) fCommandLine = true; if (fCommandLine) { fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n"); exit(1); } #ifndef WIN32 fDaemon = GetBoolArg("-daemon", false); if (fDaemon) { fprintf(stdout, "Bitcoin server starting\n"); // Daemonize pid_t pid = fork(); if (pid < 0) { fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); return false; } if (pid > 0) // Parent process, pid is child process id { return true; } // Child process falls through to rest of initialization pid_t sid = setsid(); if (sid < 0) fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); } #endif SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console InitLogging(); InitParameterInteraction(); fRet = AppInit2(threadGroup, scheduler); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(NULL, "AppInit()"); } if (!fRet) { Interrupt(threadGroup); // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of // the startup-failure cases to make sure they don't result in a hang due to some // thread-blocking-waiting-for-another-thread-during-startup case } else { WaitForShutdown(&threadGroup); } Shutdown(); return fRet; }
////////////////////////////////////////////////////////////////////////////// // // Start // bool AppInit(int argc, char* argv[]) { boost::thread_group threadGroup; CScheduler scheduler; bool fRet = false; // // Parameters // // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() gArgs.ParseParameters(argc, argv); // Process help and version before taking care about datadir if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) { std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n"; if (gArgs.IsArgSet("-version")) { strUsage += FormatParagraph(LicenseInfo()); } else { strUsage += "\n" + _("Usage:") + "\n" + " bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n"; strUsage += "\n" + HelpMessage(HMM_BITCOIND); } fprintf(stdout, "%s", strUsage.c_str()); return true; } try { if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str()); return false; } try { gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)); } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); return false; } // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(ChainNameFromCommandLine()); } catch (const std::exception& e) { fprintf(stderr, "Error: %s\n", e.what()); return false; } // Error out when loose non-argument tokens are encountered on command line for (int i = 1; i < argc; i++) { if (!IsSwitchChar(argv[i][0])) { fprintf(stderr, "Error: Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]); return false; } } // -server defaults to true for bitcoind but not for the GUI so do this here gArgs.SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console InitLogging(); InitParameterInteraction(); if (!AppInitBasicSetup()) { // InitError will have been called with detailed error, which ends up on console return false; } if (!AppInitParameterInteraction()) { // InitError will have been called with detailed error, which ends up on console return false; } if (!AppInitSanityChecks()) { // InitError will have been called with detailed error, which ends up on console return false; } if (gArgs.GetBoolArg("-daemon", false)) { #if HAVE_DECL_DAEMON fprintf(stdout, "Bitcoin server starting\n"); // Daemonize if (daemon(1, 0)) { // don't chdir (1), do close FDs (0) fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno)); return false; } #else fprintf(stderr, "Error: -daemon is not supported on this operating system\n"); return false; #endif // HAVE_DECL_DAEMON } // Lock data directory after daemonization if (!AppInitLockDataDirectory()) { // If locking the data directory failed, exit immediately return false; } fRet = AppInitMain(threadGroup, scheduler); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(nullptr, "AppInit()"); } if (!fRet) { Interrupt(threadGroup); threadGroup.join_all(); } else { WaitForShutdown(&threadGroup); } Shutdown(); return fRet; }
extern "C" int main(int argc, char* argv[] ) { argc = argc; argv = argv; InitLogging(LF_ALWAYS, LL_INFO1); LogFacilityOff(LF_THREADING); printf("KW-Software embedded CLR Version %s for Linux.ARM\n", ECLR_VERSION_STRING); #ifdef PLATFORM_THREADING_SUPPORT //setPriorityScheme(); #endif if (ClrController::Create("Default", loc_object_heap, sizeof(loc_object_heap)) == NULL) { printf("setup controller failed\n"); return -1; } CDeviceInfo* pDeviceInfo = ClrController::getDeviceInfo(); pDeviceInfo->setAttribute(CDeviceInfo::Manufacturer, "KW"); pDeviceInfo->setAttribute(CDeviceInfo::ProductName, "eCLR2.2 for Linux-ARM"); pDeviceInfo->setAttribute(CDeviceInfo::HardwareVersion, "1.0"); pDeviceInfo->setAttribute(CDeviceInfo::FirmwareVersion, "1.0"); pDeviceInfo->setAttribute(CDeviceInfo::MaxApplRetainDataSize, (uint32)0); // pDeviceInfo->setAttribute(CDeviceInfo::TimerResolution, 1000); // pDeviceInfo->setAttribute(CDeviceInfo::ScheduleInterval, 1000); //ClrAppDomain* pAppDomain = ClrController::CreateDomain("Default", ClrAppDomain::CreationDefault); ClrAppDomain* pAppDomain = ClrController::CreateDomain("Default", ClrAppDomain::DownloadChangeSupport); if (pAppDomain == NULL) { printf("vorher setup default domain failed\n"); return -1; } pAppDomain->SetDataMemory(loc_data_heap, sizeof(loc_data_heap)); pAppDomain->SetCodeMemory(loc_code_heap, sizeof(loc_code_heap)); pAppDomain->SetImageStream(&appImgFile); CPcosDomain* pPcosDomain = pcoslib::CreateDomain(pAppDomain); if (pPcosDomain == NULL) { printf("setup default domain failed\n"); return -1; } #ifdef PLATFORM_THREADING_SUPPORT //pPcosDomain->SetTicksPerSecond(0); // scheduler is working with time base of EclrEnvironment #endif #if 0 pPcosDomain->SetCPUCapacity(1000, // int calcFreq_ms 30, // int minCPULoadPerCent 80, // int maxCPULoadPerCent 4 ); // int minFreeTicks #endif //liyamin begin // set the application retentive memory space (simulated by volatile ram) pPcosDomain->AnnounceRetentiveMemory(&g_retain, sizeof(g_retain)); // set a specific ProConOS callback to handle ProConOS state changes //pPcosDomain->setCallback(&myPcosCB); //liyamin end //LIYAMIN_BEGIN //function library loading // GT_LIB10::init(); // GT_LIB10::loadLibrary(); // //share memory loading // CONSEN_SHM::init(); // CONSEN_SHM::loadLibrary(); // // //driver library loading // CONSEN_IO::init(); // CONSEN_IO::loadLibrary(); //LIYAMIN END// // pPcosDomain->WarmStartBootReq(); pPcosDomain->ColdStartBootReq(); // pPcosDomain->AnnounceRetentiveMemory(g_pCshmInterface->m_pMapAddr, 2048); BsdSocket* pBsdSocket = new BsdSocket(); if (pBsdSocket != NULL) { if (pBsdSocket->Open(BsdSocket::Stream, CRemotingDeamon::ClrServerPort) == true) { CRemotingDeamon::addSocket(pBsdSocket); } pBsdSocket->release(); } // start remoting CRemotingDeamon::start(); // change the scheduling policy and priority of this thread struct sched_param zSchedParam; int policy; int nResult; nResult = pthread_getschedparam(pthread_self(), &policy, &zSchedParam); assert(nResult == 0); zSchedParam.sched_priority = SCHEDULER_PRIO; nResult = pthread_setschedparam(pthread_self(), SCHED_FIFO, &zSchedParam); assert(nResult == 0); while (true) { ClrController::Process(); usleep(1 * 1000); //check_timer_overflow(); } return 0; }
void init(int argc, char **argv) { FILE *fp; int daemon = FALSE; int i, ntoken, status, problems; BOOL debug; THREAD tid; char pwd[MAXPATHLEN+1], RunFile[MAXPATHLEN+1]; char *token[MAXTOKEN]; char *myname, *sta, *log, *user, *prefix, *dbspec = NULL; struct stat statbuf; struct isp_dascnf dascnf; LOGIO *lp = NULL; static char *fid = "init"; memset(DasCnf, 0, sizeof(struct isp_dascnf)); MUTEX_INIT(&DasCnf->mutex); /* Get my name without path prefix (if any) */ if ((myname = strdup(argv[0])) == NULL) { perror(argv[0]); exit(1); } ntoken = util_sparse(myname, token, "./", MAXTOKEN); myname = token[ntoken-1]; /* Parse command line for required input and selected overrides */ sta = (char *) NULL; user = ISPD_DEF_USER; log = NULL; debug = ISPD_DEF_DEBUG; for (i = 1; i < argc; i++) { if (strncasecmp(argv[i], "sta=", strlen("sta=")) == 0) { sta = argv[i] + strlen("sta="); } else if (strncasecmp(argv[i], "log=", strlen("log=")) == 0) { log = argv[i] + strlen("log="); } else if (strncasecmp(argv[i], "db=", strlen("db=")) == 0) { dbspec = argv[i] + strlen("db="); } else if (strncasecmp(argv[i], "user="******"user="******"user="******"-debug") == 0) { debug = TRUE; } else if (strcasecmp(argv[i], "-bd") == 0) { daemon = TRUE; } else if (sta == (char *) NULL) { sta = argv[i]; } else { help(myname); } } if (sta == NULL) { fprintf(stderr, "%s: system name must be specified\n", myname); help(myname); } if (log == NULL) log = daemon ? DEFAULT_BACKGROUND_LOG : DEFAULT_FOREGROUND_LOG; if (!isidlSetGlobalParameters(dbspec, argv[0], &Params->glob)) { fprintf(stderr, "%s: isidlSetGlobalParameters: %s\n", argv[0], strerror(errno)); exit(1); } sprintf(pwd, "%s/%s/%s", Params->glob.root, sta, ISP_SUBDIR); if (chdir(pwd) != 0) { fprintf(stderr, "%s: chdir: ", myname); perror(pwd); exit (1); } Home = strdup(Params->glob.root); Syscode = strdup(sta); prefix = strdup(sta); if (Home == (char *) NULL || Syscode == (char *) NULL || prefix == NULL) { perror(myname); exit(1); } Syscode = util_lcase(Syscode); /* Make sure we can find the various set up files now */ problems = 0; if ((fp = fopen(ISP_RUN_FILE, "r")) == (FILE *) NULL) { fprintf(stderr, "%s: fopen: %s/", myname, pwd); perror(ISP_RUN_FILE); ++problems; } else { fclose(fp); } if (problems) exit(1); /* Load run parameters */ sprintf(RunFile, "%s/%s", pwd, ISP_RUN_FILE); if (!ispLoadRunParam(RunFile, sta, Params, Server)) { fprintf(stderr, "%s: problems with parameter file\n", myname); exit(1); } /* By insuring that we can stat the output device now, we will later * be able to treat open failures as no-media-installed conditions. */ SetOutputMediaType(); if (OutputMediaType() == ISP_OUTPUT_TAPE && stat(Params->odev, &statbuf) != 0) { fprintf(stderr, "%s: can't stat: ", myname); perror(Params->odev); exit(1); } /* Check for digitizer specific support files */ if (Params->digitizer == ISP_DAS) { if (isp_getcnf(&dascnf) != 0) { fprintf(stderr, "%s: fopen: %s/", myname, pwd); perror(ISP_CNF_FILE); fprintf(stderr, "can't load DAS configuration... set default\n"); dascnf.flag = ISP_DASCNF_DEF; if (isp_setcnf(&dascnf) != 0 || isp_getcnf(&dascnf) != 0) { perror("can't load default DAS configuration either!\n"); ++problems; } } } if (problems) exit(1); /* Set user and group identity */ utilSetIdentity(user); /* Go into the background */ if (daemon && !utilBackGround()) { perror("utilBackGround"); exit(1); } /* Start logging facility */ util_ucase(prefix); if ((lp = InitLogging(myname, log, prefix, debug)) == NULL) { perror("InitLogging"); exit(1); } ispSetLogParameter(Params, lp); LogMsg(LOG_DEBUG, "uid=%d, euid=%d, gid=%d, egid=%d", getuid(), geteuid(), getgid(), getegid()); if (Params->rt593.present) { LogMsg(LOG_INFO, "Configured for RT593 with %d tic delay", Params->rt593.correct); } /* Initialize the message queues and massio buffers */ InitMsgqs(); /* Initialize the status structure */ status_init(); /* Start signal handling thread */ signals_init(); /* Initialize the output device */ InitMediaOps(); /* Start the ISI thread */ InitIsi(lp); sleep(1); /* Start the digitizer specific I/O thread */ if (Params->digitizer == ISP_DAS) { InitDasIO(); } else { InitSanIO(); } sleep(1); /* Start the DAS packet processor thread */ InitProcess(); sleep(1); /* Start the massio buffering thread */ InitMassio(); sleep(1); /* Start the DAS status request thread */ InitSoh(); sleep(1); /* Start the digitizer configuration verification process */ if (Params->digitizer == ISP_DAS) { VerifyDasConfig(0); } else { VerifySanConfig(0); } /* Start up auxiliary threads, if any */ if (Params->clock.enabled) { set_alarm(ISP_ALARM_AUXCLK); InitClock(); } if (Params->baro.enabled) { set_alarm(ISP_ALARM_AUX); InitBaro(); } if (Params->dpm.enabled) { set_alarm(ISP_ALARM_AUX); InitDPM(); } /* Start up ISP injection service */ if (Params->inject) isp_inject(); /* Command and control server */ server_init(); /* iboot watchdog */ StartIbootWatchdog(); return; }
int main(int argc, char *argv[]) { if (argc >= 2) { /* TEST 1 Standard */ if (!strcmp(argv[1], "STD")) { char *str = "No extra string provided"; char *file = NULL; if (argc >= 3) str = argv[2]; if (argc >= 4) file = argv[3]; SetNamePgm("test_liblog"); SetNameHost("localhost"); SetDefaultLogging("TEST"); InitLogging(); AddFamilyError(ERR_POSIX, "POSIX Errors", tab_systeme_status); LogTest("AddFamilyError = %d", AddFamilyError(ERR_DUMMY, "Family Dummy", tab_test_err)); LogTest("The family which was added is %s", ReturnNameFamilyError(ERR_DUMMY)); run_Tests(true, "monothread", str, file); } /* TEST 1 multithread */ else if (!strcmp(argv[1], "MT")) { /* multithread test */ pthread_attr_t th_attr[NB_THREADS]; pthread_t threads[NB_THREADS]; int th_index, i; void *result; SetNamePgm("test_liblog"); SetNameHost("localhost"); SetDefaultLogging("STDOUT"); InitLogging(); AddFamilyError(ERR_POSIX, "POSIX Errors", tab_systeme_status); LogTest("AddFamilyError = %d", AddFamilyError(ERR_DUMMY, "Family Dummy", tab_test_err)); LogTest("The family which was added is %s", ReturnNameFamilyError(ERR_DUMMY)); /* creation of attributes */ for (th_index = 0; th_index < NB_THREADS; th_index++) { pthread_attr_init(&th_attr[th_index]); pthread_attr_setdetachstate( &th_attr[th_index], PTHREAD_CREATE_JOINABLE); } /* creation of threads with their names */ for (i = 0; i < NB_THREADS; i++) { int rc; char *thread_name = gsh_malloc(256); snprintf(thread_name, 256, "thread %3d", i); rc = pthread_create(&(threads[i]), &th_attr[i], run_MT_Tests, (void *)thread_name); } /* waiting for threads termination */ for (i = 0; i < NB_THREADS; i++) { pthread_join(threads[i], &result); if (result) return 1; } return 0; } /* unknown test */ else { fprintf(stderr, "%s", usage); exit(1); } } else { fprintf(stderr, "%s", usage); exit(1); } return 0; }
int main(int argc, char **argv) { char localmachine[256]; char *test; fsal_parameter_t init_param; fsal_status_t st; uid_t uid; fsal_export_context_t export_ctx; fsal_op_context_t op_ctx; fsal_handle_t root_handle, handle; fsal_name_t name; fsal_path_t path; fsal_attrib_list_t attribs; fsal_attrib_mask_t mask; char tracebuff[256]; if(argc < 2) { usage(); exit(-1); } test = argv[1]; /* retrieving params */ #ifndef _NO_BUDDY_SYSTEM BuddyInit(NULL); #endif /* init debug */ SetNamePgm("test_fsal"); SetDefaultLogging("TEST"); SetNameFunction("main"); InitLogging(); /* Obtention du nom de la machine */ if(gethostname(localmachine, sizeof(localmachine)) != 0) { LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno); exit(1); } else SetNameHost(localmachine); AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); /* prepare fsal_init */ /* 1 - fs specific info */ #ifdef _USE_HPSS_51 init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE; strcpy(init_param.fs_specific_info.hpss_config.PrincipalName, "hpss_nfs"); init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; strcpy(init_param.fs_specific_info.hpss_config.KeytabPath, "/krb5/hpssserver.keytab"); #elif defined _USE_HPSS_62 init_param.fs_specific_info.behaviors.AuthnMech = FSAL_INIT_FORCE_VALUE; init_param.fs_specific_info.hpss_config.AuthnMech = hpss_authn_mech_krb5; init_param.fs_specific_info.behaviors.Principal = FSAL_INIT_FORCE_VALUE; strcpy(init_param.fs_specific_info.Principal, "hpssfs"); init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; strcpy(init_param.fs_specific_info.KeytabPath, "/var/hpss/etc/hpss.keytab"); #endif /* 2-common info (default) */ FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, supported_attrs); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, umask); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, auth_exportpath_xdev); /* 3- fsal info */ init_param.fsal_info.max_fs_calls = 0; /* Init */ if(FSAL_IS_ERROR(st = FSAL_Init(&init_param))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } /* getting creds */ uid = getuid(); LogTest("uid = %d", uid); st = FSAL_BuildExportContext(&export_ctx, NULL, NULL); if(FSAL_IS_ERROR(st)) LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); st = FSAL_InitClientContext(&op_ctx); if(FSAL_IS_ERROR(st)) LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); st = FSAL_GetClientContext(&op_ctx, &export_ctx, uid, -1, NULL, 0); if(FSAL_IS_ERROR(st)) LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); /* getting root handle */ if(FSAL_IS_ERROR(st = FSAL_lookup(NULL, NULL, &op_ctx, &root_handle, NULL))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &root_handle); LogTest("Root handle = %s", tracebuff); /* getting what are the supported attributes */ attribs.asked_attributes = 0; FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); LogTest("asked attributes :"); printmask(attribs.asked_attributes); if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } LogTest("supported attributes :"); printmask(attribs.supported_attributes); mask = attribs.supported_attributes; /* TEST 1 */ if(test[0] == '1') { attribs.asked_attributes = 0; FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); LogTest("asked attributes :"); printmask(attribs.asked_attributes); if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } LogTest("supported attributes :"); /* getting all spported attributes of root */ attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&root_handle, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } printattributes(attribs); } else /* TEST 2 */ if(test[0] == '2') { /* getting handle and attributes for subdirectory "OSF1_V5" */ if(FSAL_IS_ERROR(st = FSAL_str2name("cea", 4, &name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea handle = %s", tracebuff); /* displaying attributes */ printattributes(attribs); /* getting handle and attributes for subdirectory "bin" */ if(FSAL_IS_ERROR(st = FSAL_str2name("prot", 5, &name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } root_handle = handle; attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot handle = %s", tracebuff); /* displaying attributes */ printattributes(attribs); /* getting handle and attributes for symlink "AglaePwrSW" */ if(FSAL_IS_ERROR(st = FSAL_str2name("lama", 5, &name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } root_handle = handle; attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/lama handle = %s", tracebuff); /* displaying attributes */ printattributes(attribs); } else /* TEST 3 */ if(test[0] == '3') { /* lookup root */ if(FSAL_IS_ERROR(st = FSAL_str2path("/", 30, &path))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/ handle = %s", tracebuff); /* displaying attributes */ printattributes(attribs); /* lookup path */ if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/lama", 15, &path))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/lama handle = %s", tracebuff); /* displaying attributes */ printattributes(attribs); } else /* TEST 4 */ if(test[0] == '4') { /* readdir on root */ fsal_dir_t dir; fsal_cookie_t from, to; fsal_dirent_t entries[READDIR_SIZE]; fsal_count_t number; fsal_boolean_t eod = FALSE; int error = FALSE; attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } LogTest("'/' attributes :"); /* displaying attributes */ printattributes(attribs); from = FSAL_READDIR_FROM_BEGINNING; while(!error && !eod) { unsigned int i; char cookiebuff[256]; snprintCookie(cookiebuff, 256, &from); LogTest("\nReaddir cookie = %s", cookiebuff); if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, mask, READDIR_SIZE * sizeof(fsal_dirent_t), entries, &to, &number, &eod))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); error = TRUE; } for(i = 0; (!error) && (i < number); i++) { snprintHandle(tracebuff, 256, &entries[i].handle); snprintCookie(cookiebuff, 256, &entries[i].cookie); LogTest("\t%s : %s (cookie %s)", tracebuff, entries[i].name.name, cookiebuff); } /* preparing next call */ from = to; } LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); } else /* TEST 5 */ if(test[0] == '5') { /* readdir on root */ fsal_dir_t dir; fsal_cookie_t from, to; fsal_dirent_t entries[READDIR_SIZE]; fsal_count_t number; fsal_boolean_t eod = FALSE; int error = FALSE; attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } LogTest("'/' attributes :"); /* displaying attributes */ printattributes(attribs); from = FSAL_READDIR_FROM_BEGINNING; while(!error && !eod) { fsal_dirent_t *curr; char cookiebuff[256]; snprintCookie(cookiebuff, 256, &from); LogTest("\nReaddir cookie = %s", cookiebuff); if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, mask, READDIR_SIZE * sizeof(fsal_dirent_t), entries, &to, &number, &eod))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); error = TRUE; } if(number > 0) { curr = entries; do { snprintHandle(tracebuff, 256, &curr->handle); snprintCookie(cookiebuff, 256, &curr->cookie); LogTest("\t%s : %s (cookie %s)", tracebuff, curr->name.name, cookiebuff); } while(curr = curr->nextentry); } /* preparing next call */ from = to; } LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); } else /* TEST 6 */ if(test[0] == '6') { /* readdir on root */ fsal_dir_t dir; fsal_cookie_t from, to; fsal_dirent_t entries[READDIR_SIZE]; fsal_count_t number; fsal_boolean_t eod = FALSE; int error = FALSE; attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } LogTest("'/' attributes :"); /* displaying attributes */ printattributes(attribs); from = FSAL_READDIR_FROM_BEGINNING; while(!error && !eod) { unsigned int i; snprintCookie(tracebuff, 256, &from); LogTest("\nReaddir cookie = %s", tracebuff); st = FSAL_readdir(&dir, from, mask, READDIR_SIZE * sizeof(fsal_dirent_t), entries, &to, &number, &eod); if(FSAL_IS_ERROR(st)) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); error = TRUE; } /* for each entry, we compare the result of FSAL_access * to FSAL_test_access. */ for(i = 0; (!error) && (i < number); i++) { fsal_status_t st1, st2; char cookiebuff[256]; snprintHandle(tracebuff, 256, &entries[i].handle); snprintCookie(cookiebuff, 256, &entries[i].cookie); LogTest("\t%s : %s (cookie %s)", tracebuff, entries[i].name.name, cookiebuff); if(FSAL_IS_ERROR(st = ZFSFSAL_getattrs(&entries[i].handle, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } /* 1 - test R access */ st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_R_OK, NULL); st2 = FSAL_test_access(&op_ctx, FSAL_R_OK, &attribs); LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); if(st1.major != st2.major) { LogTest ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", st1.major, st2.major); } /* 2 - test W access */ st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_W_OK, NULL); st2 = FSAL_test_access(&op_ctx, FSAL_W_OK, &attribs); LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); if(st1.major != st2.major) { LogTest ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", st1.major, st2.major); } /* 3 - test X access */ st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_X_OK, NULL); st2 = FSAL_test_access(&op_ctx, FSAL_X_OK, &attribs); LogError(COMPONENT_STDOUT, ERR_FSAL, st1.major, st1.minor); LogError(COMPONENT_STDOUT, ERR_FSAL, st2.major, st2.minor); if(st1.major != st2.major) { LogTest ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d", st1.major, st2.major); } } /* preparing next call */ from = to; } LogTest("Fin de boucle : error=%d ; eod=%d", error, eod); } else /* TEST 7 */ if(test[0] == '7') { /* test snprintmem and sscanmem */ char test_string[] = "Ceci est une chaine d'essai.\nLes chiffres : 0123456789\nLes lettres : ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char buffer[256]; char string[200]; /* 200 suffit car test_string fait <100 */ int size1, size2, size3, i; /* we put bad values in string, to see if it is correctly set. */ for(i = 0; i < 200; i++) string[i] = (char)i; LogTest("Initial data (%d Bytes) = <<%s>>", strlen(test_string), test_string); /* Write test_string to a buffer. */ /* We don't give the final '\0'. */ snprintmem(buffer, 256, test_string, strlen(test_string)); LogTest("Dest_Buffer (%d Bytes) = <<%s>>", strlen(buffer), buffer); /* read the value from the buffer */ sscanmem(string, strlen(test_string), buffer); /* sets the final 0 to print the content of the buffer */ LogTest("Retrieved string : following byte = %d", (int)string[strlen(test_string)]); string[strlen(test_string)] = '\0'; LogTest("Retrieved string (%d Bytes) = <<%s>>", strlen(string), string); /* Automatic tests : */ size1 = strlen(test_string); size2 = strlen(buffer); size3 = strlen(string); LogTest("-------------------------------------"); if(size1 <= 0) LogTest("***** ERROR: source size=0 !!!"); if(size1 != size3) LogTest("***** ERROR: source size <> target size"); else LogTest("OK: source size = target size"); if((size1 * 2) != size2) LogTest("***** ERROR: hexa size <> 2 * source size"); else LogTest("OK: hexa size = 2 * source size"); if(strcmp(test_string, string)) LogTest("***** ERROR: source string <> target string"); else LogTest("OK: source string = target string"); } else /* TEST 8 */ if(test[0] == '8') { fsal_handle_t dir_hdl, subdir_hdl; fsal_name_t subdir_name; /* lookup on /cea/prot/S/lama/s8/leibovic */ if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); sleep(1); /* creates a directory */ LogTest("------- Create a directory -------"); if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA", 30, &name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_XUSR | FSAL_MODE_RGRP | FSAL_MODE_WGRP, &dir_hdl, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { snprintHandle(tracebuff, 256, &dir_hdl); LogTest("newly created dir handle = %s", tracebuff); printattributes(attribs); } sleep(1); /* Try to create it again */ LogTest("------- Try to create it again -------"); if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_XUSR | FSAL_MODE_RGRP | FSAL_MODE_WGRP, &dir_hdl, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { LogTest("**** Error: FSAL should have returned ERR_FSAL_EXIST"); } sleep(1); /* creates a subdirectory */ LogTest("------- Create a subdirectory -------"); if(FSAL_IS_ERROR(st = FSAL_str2name("subdir_GANESHA", 30, &subdir_name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } if(FSAL_IS_ERROR(st = FSAL_mkdir(&dir_hdl, &subdir_name, &op_ctx, FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_XUSR | FSAL_MODE_RGRP | FSAL_MODE_WGRP, &subdir_hdl, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { snprintHandle(tracebuff, 256, &subdir_hdl); LogTest("newly created subdir handle = %s", tracebuff); printattributes(attribs); } /* try to removes the parent directory */ LogTest("------- Try to removes the parent directory -------"); if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { LogTest("FSAL should not have unlinked %s because it is not empty", name.name); } sleep(1); /* removes the subdirectory */ LogTest("------- Removes the subdirectory -------"); if(FSAL_IS_ERROR(st = FSAL_unlink(&dir_hdl, &subdir_name, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { LogTest("New attributes for parent directory:"); printattributes(attribs); } /* removes the parent directory */ LogTest("------- Removes the parent directory -------"); if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { LogTest("Unlink %s OK", name.name); } } /* TEST 9 */ else if(test[0] == '9') { fsal_handle_t dir_hdl, subdir_hdl; fsal_name_t subdir_name; fsal_attrib_list_t attr_set; fsal_fsid_t set_fsid = { 1LL, 2LL }; #ifdef _LINUX struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0, 0, 0 }; #else struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0 }; #endif /* lookup on /cea/prot/S/lama/s8/leibovic */ if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); sleep(1); /* creates a file */ LogTest("------- Create a file -------"); if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA_setattrs", 30, &name))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_create(&handle, &name, &op_ctx, FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_XUSR | FSAL_MODE_RGRP | FSAL_MODE_WGRP, &dir_hdl, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { snprintHandle(tracebuff, 256, &dir_hdl); LogTest("newly created file handle = %s", tracebuff); printattributes(attribs); } sleep(1); LogTest("------- Try to change its attributes -------"); /* Macro that try to change the value for an attribute */ #define CHANGE_ATTRS( str_nom, nom, flag, new_val ) do {\ memset(&attr_set, 0, sizeof(fsal_attrib_list_t) ); \ LogTest("\nTry to change '%s' :",str_nom); \ FSAL_SET_MASK( attr_set.asked_attributes , flag ); \ attr_set.nom = new_val; \ attribs.asked_attributes = attr_set.asked_attributes; \ /* attribs.asked_attributes = mask; */\ st = FSAL_setattrs( &dir_hdl, &op_ctx, &attr_set, &attribs );\ if ( FSAL_IS_ERROR(st) ) \ LogError(COMPONENT_STDOUT,ERR_FSAL,st.major,st.minor);\ else \ printattributes( attribs ); \ } while(0) CHANGE_ATTRS("supported_attributes", supported_attributes, FSAL_ATTR_SUPPATTR, FSAL_ATTRS_MANDATORY); CHANGE_ATTRS("type", type, FSAL_ATTR_TYPE, FSAL_TYPE_LNK); sleep(1); /* to see mtime modification by truncate */ CHANGE_ATTRS("filesize", filesize, FSAL_ATTR_SIZE, (fsal_size_t) 12); sleep(1); /* to see mtime modification by truncate */ CHANGE_ATTRS("fsid", fsid, FSAL_ATTR_FSID, set_fsid); /* @todo : ACLs */ CHANGE_ATTRS("fileid", fileid, FSAL_ATTR_FILEID, (fsal_u64_t) 1234); CHANGE_ATTRS("mode", mode, FSAL_ATTR_MODE, (FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_RGRP)); CHANGE_ATTRS("numlinks", numlinks, FSAL_ATTR_NUMLINKS, 7); /* FSAL_ATTR_RAWDEV */ CHANGE_ATTRS("atime", atime.seconds, FSAL_ATTR_ATIME, mktime(&jour_heure)); jour_heure.tm_min++; CHANGE_ATTRS("creation", creation.seconds, FSAL_ATTR_CREATION, mktime(&jour_heure)); jour_heure.tm_min++; CHANGE_ATTRS("mtime", mtime.seconds, FSAL_ATTR_MTIME, mktime(&jour_heure)); jour_heure.tm_min++; CHANGE_ATTRS("ctime", ctime.seconds, FSAL_ATTR_CTIME, mktime(&jour_heure)); CHANGE_ATTRS("spaceused", spaceused, FSAL_ATTR_SPACEUSED, (fsal_size_t) 12345); CHANGE_ATTRS("mounted_on_fileid", mounted_on_fileid, FSAL_ATTR_MOUNTFILEID, (fsal_u64_t) 3210); CHANGE_ATTRS("owner", owner, FSAL_ATTR_OWNER, 3051); /* deniel */ CHANGE_ATTRS("group", group, FSAL_ATTR_GROUP, 5953); /* sr */ sleep(1); /* removes the parent directory */ LogTest("------- Removes the directory -------"); if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { LogTest("Unlink %s OK", name.name); } } else if(test[0] == 'A') { char digest_buff[FSAL_DIGEST_SIZE_HDLV3]; /* lookup on /cea/prot/S/lama/s8/leibovic */ if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } attribs.asked_attributes = mask; if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/S/lama/s8/leibovic: handle = %s", tracebuff); /* building digest */ st = FSAL_DigestHandle(&export_ctx, FSAL_DIGEST_NFSV3, &handle, digest_buff); if(FSAL_IS_ERROR(st)) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { /* print digest */ snprintmem(tracebuff, 256, digest_buff, FSAL_DIGEST_SIZE_HDLV3); LogTest("/cea/prot/S/lama/s8/leibovic: handle_digest = %s", tracebuff); } memset(&handle, 0, sizeof(fsal_handle_t)); /* expend digest */ st = FSAL_ExpandHandle(&export_ctx, FSAL_DIGEST_NFSV3, digest_buff, &handle); if(FSAL_IS_ERROR(st)) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); } else { /* print expended handle */ snprintHandle(tracebuff, 256, &handle); LogTest("/cea/prot/S/lama/s8/leibovic: handle expended = %s", tracebuff); } } else if(test[0] == 'B') { fsal_dynamicfsinfo_t dyninfo; if(FSAL_IS_ERROR(st = FSAL_dynamic_fsinfo(&root_handle, &op_ctx, &dyninfo))) { LogError(COMPONENT_STDOUT, ERR_FSAL, st.major, st.minor); exit(st.major); } LogTest("total_bytes = %llu", dyninfo.total_bytes); LogTest("free_bytes = %llu", dyninfo.free_bytes); LogTest("avail_bytes = %llu", dyninfo.avail_bytes); LogTest("total_files = %llu", dyninfo.total_files); LogTest("free_files = %llu", dyninfo.free_files); LogTest("avail_files = %llu", dyninfo.avail_files); LogTest("time_delta = %u.%u", dyninfo.time_delta.seconds, dyninfo.time_delta.nseconds); } else LogTest("%s : test inconnu", test); return 0; }
////////////////////////////////////////////////////////////////////////////// // // Start // bool AppInit(int argc, char *argv[]) { shutdown_threads.store(false); thread_group threadGroup(&shutdown_threads); bool fRet = false; // // Parameters // gArgs.ParseParameters(argc, argv); // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { CheckParams(ChainNameFromCommandLine()); } catch (const std::exception &e) { fprintf(stderr, "Error: %s\n", e.what()); return false; } try { gArgs.ReadConfigFile(); } catch (const std::exception &e) { fprintf(stderr, "Error reading configuration file: %s\n", e.what()); return false; } GenerateNetworkTemplates(); // Process help and version before taking care about datadir if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) { std::string strUsage = "Eccoind version " + FormatFullVersion() + "\n"; if (gArgs.IsArgSet("-version")) { strUsage += LicenseInfo(); } else { strUsage += "\nUsage:\neccoind [options] Start Eccoind\n"; strUsage += "\n" + HelpMessage(); } fprintf(stdout, "%s", strUsage.c_str()); return false; } try { if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str()); return false; } // Command-line RPC bool fCommandLine = false; for (int i = 1; i < argc; i++) { if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "ECC:")) { fCommandLine = true; } } if (fCommandLine) { int ret = CommandLineRPC(argc, argv); exit(ret); } #ifndef WIN32 fDaemon = gArgs.GetBoolArg("-daemon", false); if (fDaemon) { fprintf(stdout, "Eccoind server starting\n"); // Daemonize pid_t pid = fork(); if (pid < 0) { fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); return false; } if (pid > 0) // Parent process, pid is child process id { return true; } // Child process falls through to rest of initialization pid_t sid = setsid(); if (sid < 0) fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); } #endif gArgs.SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console InitLogging(); InitParameterInteraction(); fRet = AppInit2(threadGroup); } catch (const std::exception &e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(NULL, "AppInit()"); } if (!fRet) { Interrupt(threadGroup); } else { WaitForShutdown(&threadGroup); } Shutdown(); return fRet; }
////////////////////////////////////////////////////////////////////////////// // // Start // static bool AppInit(int argc, char* argv[]) { bool fRet = false; // // Parameters // // If Qt is used, parameters/digibyte.conf are parsed in qt/digibyte.cpp's main() SetupServerArgs(); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str()); return false; } // Process help and version before taking care about datadir if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { std::string strUsage = strprintf("%s Daemon", PACKAGE_NAME) + " version " + FormatFullVersion() + "\n"; if (gArgs.IsArgSet("-version")) { strUsage += FormatParagraph(LicenseInfo()); } else { strUsage += "\nUsage:\n" " digibyted [options] " + strprintf("Start %s Daemon", PACKAGE_NAME) + "\n"; strUsage += "\n" + gArgs.GetHelpMessage(); } fprintf(stdout, "%s", strUsage.c_str()); return true; } try { if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str()); return false; } if (!gArgs.ReadConfigFiles(error, true)) { fprintf(stderr, "Error reading configuration file: %s\n", error.c_str()); return false; } // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(gArgs.GetChainName()); } catch (const std::exception& e) { fprintf(stderr, "Error: %s\n", e.what()); return false; } // Error out when loose non-argument tokens are encountered on command line for (int i = 1; i < argc; i++) { if (!IsSwitchChar(argv[i][0])) { fprintf(stderr, "Error: Command line contains unexpected token '%s', see digibyted -h for a list of options.\n", argv[i]); return false; } } // -server defaults to true for digibyted but not for the GUI so do this here gArgs.SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console InitLogging(); InitParameterInteraction(); if (!AppInitBasicSetup()) { // InitError will have been called with detailed error, which ends up on console return false; } if (!AppInitParameterInteraction()) { // InitError will have been called with detailed error, which ends up on console return false; } if (!AppInitSanityChecks()) { // InitError will have been called with detailed error, which ends up on console return false; } if (gArgs.GetBoolArg("-daemon", false)) { #if HAVE_DECL_DAEMON #if defined(MAC_OSX) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif fprintf(stdout, "DigiByte server starting\n"); // Daemonize if (daemon(1, 0)) { // don't chdir (1), do close FDs (0) fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno)); return false; } #if defined(MAC_OSX) #pragma GCC diagnostic pop #endif #else fprintf(stderr, "Error: -daemon is not supported on this operating system\n"); return false; #endif // HAVE_DECL_DAEMON } // Lock data directory after daemonization if (!AppInitLockDataDirectory()) { // If locking the data directory failed, exit immediately return false; } fRet = AppInitMain(); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(nullptr, "AppInit()"); } if (!fRet) { Interrupt(); } else { WaitForShutdown(); } Shutdown(); return fRet; }
int init(int argc, char **argv, struct param *param) { unsigned long tictol = 0; void *opt; int i, status, flags, rev; char *home = NULL; char *iname = NULL; #ifdef WIN32 char *log = NULL; #else char *log = "syslogd"; #endif char *syscode = NULL; char *SYSCODE = NULL; int debug = NRTS_DEFLOG; int background = 1; int stamp_year = 1; int ctsrts = 0; int leapfix = 0; int strict = 1; int addseqno = 1; int forcettst = 0; float minseg = 0.0; time_t now; struct tm *gmt; struct nrts_files *file; char *dbspec = (char *) NULL; DBIO *db = NULL; char *mapname = NULL; LOGIO *lp; static struct nrts_sys *sys; static struct nrts_ida *info; static struct nrts_mmap mmap, *map; static char *fid = "init"; XferLibInit(); param->sys = NULL; param->beg = NRTS_OLDEST; param->end = NRTS_YNGEST; param->keeparg = NULL; param->timeout = -1; param->tto = 0; param->retry = 1; param->port = -1; param->tapfile = (char *) NULL; param->ida = (IDA *) NULL; param->fwd = 60; param->dbgpath = NULL; param->IsiStatPath = NULL; param->blksiz = 512; /* ASL network block size */ param->tolerance = 1; /* largest tolerated time tear in samples */ param->req.protocol = 0x01; param->req.type = XFER_WAVREQ; param->req.timeout = NRTS_DEFTCPTO; param->req.sndbuf = 0; param->req.rcvbuf = 0; param->req.preamble.ver01.client_id = getpid(); param->req.preamble.ver01.format = XFER_CNFNRTS; param->wavreq = ¶m->req.request.wav.ver01; param->wavreq->keepup = 0; param->wavreq->comp = XFER_CMPIGPP; /* Get command line arguments */ for (i = 1; i < argc; i++) { if (strncmp(argv[i], "home=", strlen("home=")) == 0) { home = argv[i] + strlen("home="); } else if (strncmp(argv[i], "debug=", strlen("debug=")) == 0) { debug = atoi(argv[i]+strlen("debug=")); } else if (strncmp(argv[i], "fwd=", strlen("fwd=")) == 0) { param->fwd = atoi(argv[i]+strlen("fwd=")); } else if (strncmp(argv[i], "log=", strlen("log=")) == 0) { log = argv[i] + strlen("log="); } else if (strncmp(argv[i], "dbgpath=", strlen("dbgpath=")) == 0) { param->dbgpath = argv[i] + strlen("dbgpath="); } else if (strncmp(argv[i], "to=", strlen("to=")) == 0) { param->timeout = atoi(argv[i] + strlen("to=")); param->req.timeout = param->timeout; } else if (strncmp(argv[i], "tto=", strlen("tto=")) == 0) { param->tto = atoi(argv[i] + strlen("tto=")); } else if (strncmp(argv[i], "minseg=", strlen("minseg=")) == 0) { minseg = atof(argv[i] + strlen("minseg=")); } else if (strncmp(argv[i], "bg=", strlen("bg=")) == 0) { background = atoi(argv[i] + strlen("bg=")); } else if (strncmp(argv[i], "port=", strlen("port=")) == 0) { param->port = atoi(argv[i] + strlen("port=")); } else if (strncmp(argv[i], "tcpbuf=", strlen("tcpbuf=")) == 0){ param->req.sndbuf = atoi(argv[i] + strlen("tcpbuf=")); param->req.rcvbuf = param->req.sndbuf; } else if (strncmp(argv[i], "snd=", strlen("snd=")) == 0) { param->req.sndbuf = atoi(argv[i] + strlen("snd=")); } else if (strncmp(argv[i], "rcv=", strlen("rcv=")) == 0) { param->req.rcvbuf = atoi(argv[i] + strlen("rcv=")); } else if (strncmp(argv[i], "bs=", strlen("bs=")) == 0) { param->blksiz = atoi(argv[i] + strlen("bs=")); } else if (strncmp(argv[i], "comp=", strlen("comp=")) == 0) { param->wavreq->comp = atoi(argv[i] + strlen("comp=")); } else if (strncmp(argv[i], "tolerance=", strlen("tolerance=")) == 0) { param->tolerance = atoi(argv[i] + strlen("tolerance=")); } else if (strcmp(argv[i], "+retry") == 0) { param->retry = 1; } else if (strcmp(argv[i], "-retry") == 0) { param->retry = 0; } else if (strcmp(argv[i], "++retry") == 0) { param->retry = -1; } else if (strcmp(argv[i], "+keepup") == 0) { param->wavreq->keepup = 1; } else if (strcmp(argv[i], "-keepup") == 0) { param->wavreq->keepup = 0; } else if (strncmp(argv[i], "tap=", strlen("tap=")) == 0) { param->tapfile = strdup(argv[i] + strlen("tap=")); } else if (strncmp(argv[i], "chan=", strlen("chan=")) == 0) { param->keeparg = strdup(argv[i] + strlen("chan=")); } else if (strcmp(argv[i], "+ctsrts") == 0) { ctsrts = 1; } else if (strcmp(argv[i], "-ctsrts") == 0) { ctsrts = 0; } else if (strcmp(argv[i], "+strict") == 0) { strict = 1; } else if (strcmp(argv[i], "-strict") == 0) { strict = 0; } else if (strcmp(argv[i], "+forcettst") == 0) { forcettst = 1; } else if (strcmp(argv[i], "-forcettst") == 0) { forcettst = 0; } else if (strcmp(argv[i], "+seqno") == 0) { addseqno = 1; } else if (strcmp(argv[i], "-seqno") == 0) { addseqno = 0; } else if (strcmp(argv[i], "+leapfix") == 0) { leapfix = 1; } else if (strcmp(argv[i], "-leapfix") == 0) { leapfix = 0; } else if (strcmp(argv[i], "+year") == 0) { stamp_year = 1; } else if (strcmp(argv[i], "-year") == 0) { stamp_year = 0; } else if (strncmp(argv[i], "if=", strlen("if=")) == 0) { iname = argv[i] + strlen("if="); } else if (strncmp(argv[i], "beg=", strlen("beg=")) == 0) { param->beg = util_attodt(argv[i] + strlen("beg=")); } else if (strncmp(argv[i], "end=", strlen("end=")) == 0) { param->end = util_attodt(argv[i] + strlen("end=")); param->wavreq->keepup = 0; } else if (strncmp(argv[i], "db=", strlen("db=")) == 0) { dbspec = argv[i] + strlen("db="); } else if (strncmp(argv[i], "tictol=", strlen("tictol=")) == 0) { tictol = (unsigned long) atol(argv[i] + strlen("tictol=")); } else if (strncmp(argv[i], "isilog=", strlen("isilog=")) == 0) { param->IsiStatPath = strdup(argv[i] + strlen("isilog=")); } else { if (syscode != NULL) { help(argv[0]); } else { syscode = argv[i]; } } } flags = NRTS_TODISK; if (strict) flags |= NRTS_STRICT; if (addseqno) flags |= NRTS_ADDSEQNO; if (forcettst) flags |= NRTS_FORCETTST; if (syscode == NULL) { fprintf(stderr,"%s: missing system code\n", argv[0]); help(argv[0]); } /* Get file names */ file = nrts_files(&home, syscode); /* Switch from stderr to log file */ if (log == NULL) log = file->log; SYSCODE = (strcmp(log, "syslogd")==0) ? util_ucase(strdup(syscode)) : NULL; util_logopen(log, 1, NRTS_MAXLOG, debug, SYSCODE, argv[0]); util_log(1, VersionIdentString); lp = InitLogging(argv[0], log, debug == NRTS_DEFLOG ? FALSE : TRUE); /* Get system map */ map = &mmap; if (nrts_mmap(file->sys, "r+", NRTS_SYSTEM, map) != 0) { util_log(1, "%s: nrts_mmap failed", fid); return -1; } param->sys = sys = (struct nrts_sys *) map->ptr; /* Load the database */ if ((db = dbioOpen(dbspec, NULL)) == NULL) { if (dbspec == NULL) { fprintf(stderr, "%s: undefined database. Set DBIO_DATABASE or use db=spec\n", argv[0]); } else { fprintf(stderr, "%s: can't load database `%s': %s\n", argv[0], dbspec, syserrmsg(errno)); } return -1; } util_log(1, "%s database loaded OK\n", db->dbid); /* Lock system file and check for consistency */ util_log(2, "locking system"); /* This is not applicable for WIN32 */ #ifndef WIN32 if (sys->pid != 0 && kill(sys->pid, SIGHUP) == 0) { util_log(1, "system is already active (pid %d)", sys->pid); return -1; } #endif if (nrts_wlock(map) == -1) { if (errno == EACCES) { util_log(1,"exit: system is locked (pid=%d)\n", argv[0], sys->pid); exit(1); } else { util_log(1,"%s: nrts_wlock: %s", fid, syserrmsg(errno)); return -1; } } util_log(2, "checking disk loop integrity"); if ((status = nrts_chksys(sys)) != 0) { util_log(1, "correcting disk loop (status %d)", status); if ((status = nrts_fixsys(sys)) != 0) { util_log(1,"FATAL: unable to repair disk loop (status %d)", status); return -1; } } util_log(2, "disk loop is intact"); /* Store our process id */ sys->pid = getpid(); /* Load system specific information */ if (sys->type == NRTS_IDA) { info = (struct nrts_ida *) sys->info; param->wavreq->format = XFER_WAVIDA; rev = info->rev; mapname = info->map; } else if (sys->type == NRTS_IDA10) { param->wavreq->format = XFER_WAVIDA; rev = 10; mapname = NULL; } else { util_log(1, "%s: unsupported system type = %d", fid, sys->type); return -1; } if ((param->ida = idaCreateHandle(sys->sta[0].name, rev, mapname, db, NULL, flags)) == NULL) { util_log(1, "idaCreateHandle failed"); return -1; } /* Insure the binary wfdiscs are current */ if ((status = nrts_fixwd(file, map, home, syscode, param->ida)) != 0) { util_log(1, "nrts_fixwd: status %d", status); return -1; } /* Allocate read buffers */ util_log(2, "allocating read buffers"); param->len = sys->reclen; if ((param->prev = (char *) calloc(param->len, sizeof(char))) == NULL) { util_log(1, "malloc: %s", syserrmsg(errno)); return -1; } if ((param->crnt = (char *) calloc(param->len, sizeof(char))) == NULL) { util_log(1, "malloc: %s", syserrmsg(errno)); return -1; } /* Initialize data input routine */ util_log(2, "initializing data input routines"); if (init_getrec(home,syscode,iname,param,ctsrts,leapfix,&flags) != 0) { util_log(1, "%s: init_getrec failed", fid); return -1; } /* Initialize the disk writer */ util_log(2, "initializing disk i/o routines"); opt = (void *) &tictol; if (nrts_iniwrtdl(home, syscode, sys, flags, param->ida, opt) != 0) { util_log(1, "%s: nrts_iniwrtdl failed", fid); return -1; } /* For IDA rev 3 (aka MK4) data, determine initial year value */ /* This assumes that the system clock is more or less correct */ if (sys->type == NRTS_IDA && param->ida->rev.value == 3) { if (stamp_year) { now = time(NULL); gmt = gmtime(&now); info->mk4_year = gmt->tm_year + 1900; util_log(1, "IDA MK4 system... will use %hd for year", info->mk4_year); } else { info->mk4_year = -1; util_log(1, "IDA MK4 system... will believe datalogger year stamp"); } } /* Finally (sigh) announce if we are using Fels' shifts or not */ if (sys->type == NRTS_IDA && info->shift) util_log(1, "fels' shifts will be applied (sigh)"); /* Go into the background and update process id */ util_log(1, "initialization complete"); util_logclose(); #ifndef WIN32 if (background && util_bground(0, 0) < 0) { util_logopen(log, 1, NRTS_MAXLOG, debug, SYSCODE, argv[0]); util_log(1, "util_bground: %s", syserrmsg(errno)); return -1; } #endif util_logopen(log, 1, NRTS_MAXLOG, debug, SYSCODE, argv[0]); util_log(2, "updating pid"); param->req.preamble.ver01.client_id = sys->pid = getpid(); /* start signal handler and wfdisc flush threads */ SetSys(sys); StartSignalHandler(); StartFlushThread(param); /* begin data acquistion */ util_log(1, "starting data acquisition"); sys->start = time(NULL); return 0; }
main(int argc, char *argv[]) { char localmachine[256]; cache_inode_client_t client; LRU_parameter_t lru_param; LRU_status_t lru_status; cache_inode_fsal_data_t fsdata; fsal_status_t status; fsal_parameter_t init_param; fsal_name_t name; fsal_path_t path; fsal_attrib_mask_t mask; fsal_path_t pathroot; fsal_attrib_list_t attribs; fsal_handle_t root_handle; cache_inode_endofdir_t eod_met; cache_inode_dir_entry_t dirent_array[100]; cache_inode_dir_entry_t dirent_array_loop[5]; unsigned int nbfound; unsigned int begin_cookie = 0; hash_buffer_t key, value; uid_t uid; fsal_cred_t cred; cache_inode_status_t cache_status; cache_inode_parameter_t cache_param; cache_inode_client_parameter_t cache_client_param; hash_table_t *ht = NULL; fsal_attrib_list_t attrlookup; cache_entry_t *cache_entry_root = NULL; cache_entry_t *cache_entry_lookup = NULL; cache_entry_t *cache_entry_lookup2 = NULL; cache_entry_t *cache_entry_lookup3 = NULL; cache_entry_t *cache_entry_lookup4 = NULL; cache_entry_t *cache_entry_dircont = NULL; cache_inode_gc_policy_t gcpol; char *configfile = argv[1]; int i = 0; int rc = 0; /* Init the Buddy System allocation */ if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS) { LogTest("Error initializing memory allocator"); exit(1); } /* init debug */ SetDefaultLogging("TEST"); SetNamePgm("test_cache_inode"); SetNameFunction("main"); InitLogging(); #if defined( _USE_GHOSTFS ) if(argc != 2) { LogTest("Please set the configuration file as parameter"); exit(1); } #endif /* Obtention du nom de la machine */ if(gethostname(localmachine, sizeof(localmachine)) != 0) { LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno); exit(1); } else SetNameHost(localmachine); AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); AddFamilyError(ERR_CACHE_INODE, "FSAL related Errors", tab_errstatus_cache_inode); /* creating log */ LogTest( "Starting the test"); LogTest( "-----------------"); #if defined( _USE_GHOSTFS ) if(FSAL_IS_ERROR(status = FSAL_str2path(configfile, strlen(configfile) + 1, &(init_param.fs_specific_info. definition_file)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); } #elif defined( _USE_HPSS ) FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, Flags); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugValue); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TransferType); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, NumRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TotalDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, GKTotalDelay); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, LimitedRetries); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, MaxConnections); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ReuseDataConnections); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, UsePortRange); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RetryStageInp); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DMAPWriteUpdates); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ServerName); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DescName); init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE; strncpy(init_param.fs_specific_info.hpss_config.PrincipalName, HPSS_SSM, HPSS_MAX_PRINCIPAL_NAME); init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; strncpy(init_param.fs_specific_info.hpss_config.KeytabPath, HPSS_KEYTAB, HPSS_MAX_PATH_NAME); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugPath); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, HostName); FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RegistrySiteName); #endif /* 2-common info (default) */ FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread); FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite); /* Init */ if(FSAL_IS_ERROR(status = FSAL_Init(&init_param))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); } /* getting creds */ uid = getuid(); if(FSAL_IS_ERROR(status = FSAL_GetUserCred(uid, NULL, &cred))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); } /* Init of the cache inode module */ cache_param.hparam.index_size = 31; cache_param.hparam.alphabet_length = 10; /* Buffer seen as a decimal polynom */ cache_param.hparam.nb_node_prealloc = 100; cache_param.hparam.hash_func_key = cache_inode_fsal_hash_func; cache_param.hparam.hash_func_rbt = cache_inode_fsal_rbt_func; cache_param.hparam.hash_func_both = NULL ; /* BUGAZOMEU */ cache_param.hparam.compare_key = cache_inode_compare_key_fsal; cache_param.hparam.key_to_str = display_key; cache_param.hparam.val_to_str = display_value; if((ht = cache_inode_init(cache_param, &cache_status)) == NULL) { LogTest( "Error %d while init hash ", cache_status); } else LogTest( "Hash Table address = %p", ht); /* We need a cache_client to acces the cache */ cache_client_param.attrmask = FSAL_ATTRS_MANDATORY | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_ATIME; cache_client_param.nb_prealloc_entry = 1000; cache_client_param.nb_pre_dir_data = 200; cache_client_param.nb_pre_parent = 1200; cache_client_param.nb_pre_state_v4 = 100; cache_client_param.lru_param.nb_entry_prealloc = 1000; cache_client_param.lru_param.entry_to_str = lru_entry_to_str; cache_client_param.lru_param.clean_entry = lru_clean_entry; cache_client_param.grace_period_attr = 0; cache_client_param.grace_period_link = 0; cache_client_param.grace_period_dirent = 0; cache_client_param.expire_type_attr = CACHE_INODE_EXPIRE_NEVER; cache_client_param.expire_type_link = CACHE_INODE_EXPIRE_NEVER; cache_client_param.expire_type_dirent = CACHE_INODE_EXPIRE_NEVER; /* Init the cache_inode client */ if(cache_inode_client_init(&client, cache_client_param, 0, NULL) != 0) exit(1); /* Init the gc */ gcpol.file_expiration_delay = 3; gcpol.directory_expiration_delay = 4; gcpol.hwmark_nb_entries = 6; gcpol.lwmark_nb_entries = 3; gcpol.run_interval = 4; cache_inode_set_gc_policy(gcpol); /* Getting the root of the FS */ if((FSAL_IS_ERROR(status = FSAL_str2path("/", 2, &pathroot)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } if((FSAL_IS_ERROR(status = FSAL_lookupPath(&pathroot, &cred, &root_handle, &attribs)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } fsdata.cookie = 0; fsdata.handle = root_handle; /* Cache the root of the FS */ if((cache_entry_root = cache_inode_make_root(&fsdata, 1, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't init fs's root"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } /* Lookup a second time (entry should now be cached) */ if((cache_entry_lookup2 = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if(cache_entry_lookup2 != cache_entry_lookup) { LogTest("Error: lookup results should be the same"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup3 = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if((cache_entry_lookup4 = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } if(cache_entry_lookup3 != cache_entry_lookup4) { LogTest("Error: lookup results should be the same"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("SunOS_5", 10, &name)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } cache_inode_print_dir(cache_entry_root); /* Test readdir */ if(cache_inode_readdir(cache_entry_root, 0, 100, &nbfound, &eod_met, dirent_array, ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS) { LogTest( "Error: cache_inode_readdir failed"); exit(1); } LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met); for(i = 0; i < nbfound; i++) LogTest( "dirent_array[%d] ==> %s | %p", i, dirent_array[i].name.name, dirent_array[i].pentry); cache_inode_print_dir(cache_entry_root); /* looping on readir */ LogTest( "Loop directory in several pass"); eod_met = TO_BE_CONTINUED; begin_cookie = 0; do { if(cache_inode_readdir(cache_entry_root, begin_cookie, 2, &nbfound, &eod_met, dirent_array_loop, ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS) { LogTest("Error: cache_inode_readdir failed: %d", cache_status); exit(1); } for(i = 0; i < nbfound; i++) LogTest( " ==> %s | %p", dirent_array_loop[i].name.name, dirent_array_loop[i].pentry); begin_cookie += nbfound; } while(eod_met == TO_BE_CONTINUED); LogTest( "---------------------------------"); /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } /* A lookup in the root fsal */ if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name)))) { LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor); exit(1); } if((cache_entry_lookup = cache_inode_lookup(cache_entry_root, &name, &attrlookup, ht, &client, &cred, &cache_status)) == NULL) { LogTest( "Error: can't lookup"); exit(1); } /* Print the Hash Table */ HashTable_Log(COMPONENT_STDOUT, ht); #ifdef _ADDITIONAL_TEST /* Trying to lookup from a DIR_CONTINUE */ fsdata.handle = cache_entry_root->object.dir_begin.handle; fsdata.cookie = 3 * CHILDREN_ARRAY_SIZE; LogTest("Input key: (Handle=%p, Cookie=%d)", fsdata.handle, fsdata.cookie); /* Turn the input to a hash key */ if(cache_inode_fsaldata_2_key(&key, &fsdata, NULL)) { LogTest( "Impossible to allocate a key to that value"); exit(1); } if(HashTable_Get(ht, &key, &value) != HASHTABLE_SUCCESS) { LogTest( "Key could not be found"); exit(1); } /* pentry for the dir cont */ cache_entry_dircont = (cache_entry_t *) value.pdata; /* Test readdir */ if(cache_inode_readdir(cache_entry_dircont, fsdata.cookie, 100, &nbfound, &eod_met, dirent_array, ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS) { LogTest( "Error: cache_inode_readdir failed"); exit(1); } #endif LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met); for(i = 0; i < nbfound; i++) LogTest( "dirent_array[%d] ==> %s | %p ", i, dirent_array[i].name.name, dirent_array[i].pentry); /* Call the GC */ LogTest( "Sleeping %d second before gc (for gc invalidation)", gcpol.file_expiration_delay + 2); sleep(gcpol.file_expiration_delay + 2); if(cache_inode_gc(ht, &client, &cache_status) != CACHE_INODE_SUCCESS) { LogTest( "Error: cache_inode_gc failed"); exit(1); } LogTest( "GC performed successfully"); /* Print the Hash Table */ HashTable_Log(COMPONENT_STDOUT, ht); /* Another readdir, after gc is made */ eod_met = TO_BE_CONTINUED; begin_cookie = 0; LogTest( "ANOTHER READDIR AFTER GC"); do { if(cache_inode_readdir(cache_entry_root, begin_cookie, 2, &nbfound, &eod_met, dirent_array_loop, ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS) { LogTest("Error: cache_inode_readdir failed: %d", cache_status); exit(1); } for(i = 0; i < nbfound; i++) LogTest( " ==> %s | %p", dirent_array_loop[i].name.name, dirent_array_loop[i].pentry); begin_cookie += nbfound; } while(eod_met == TO_BE_CONTINUED); LogTest( "---------------------------------"); /* Print the Hash Table */ HashTable_Log(COMPONENT_STDOUT, ht); LogTest( "---------------------------------"); /* The end of all the tests */ LogTest( "All tests exited successfully"); exit(0); } /* main */
int main(int argc, char **argv) { unsigned int i; struct timeval tv1, tv2, tv3, tvdiff; int count, rc; char *dir; handle_map_param_t param; time_t now; /* Init logging */ SetNamePgm("test_handle_mapping"); SetDefaultLogging("TEST"); SetNameFunction("main"); SetNameHost("localhost"); InitLogging(); if(argc != 3 || (count = atoi(argv[2])) == 0) { LogTest("usage: test_handle_mapping <db_dir> <db_count>"); exit(1); } #ifndef _NO_BUDDY_SYSTEM if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS) { /* Failed init */ LogCrit(COMPONENT_FSAL, "ERROR: Could not initialize memory manager"); exit(rc); } #endif dir = argv[1]; strcpy(param.databases_directory, dir); strcpy(param.temp_directory, "/tmp"); param.database_count = count; param.hashtable_size = 27; param.nb_handles_prealloc = 1024; param.nb_db_op_prealloc = 1024; param.synchronous_insert = FALSE; rc = HandleMap_Init(¶m); LogTest("HandleMap_Init() = %d", rc); if(rc) exit(rc); gettimeofday(&tv1, NULL); /* Now insert a set of handles */ now = time(NULL); for(i = 0; i < 10000; i++) { nfs23_map_handle_t nfs23_digest; fsal_handle_t handle; memset(&handle, i, sizeof(fsal_handle_t)); nfs23_digest.object_id = 12345 + i; nfs23_digest.handle_hash = (1999 * i + now) % 479001599; rc = HandleMap_SetFH(&nfs23_digest, &handle); if(rc && (rc != HANDLEMAP_EXISTS)) exit(rc); } gettimeofday(&tv2, NULL); timersub(&tv2, &tv1, &tvdiff); LogTest("%u threads inserted 10000 handles in %d.%06ds", count, (int)tvdiff.tv_sec, (int)tvdiff.tv_usec); /* Now get them ! */ for(i = 0; i < 10000; i++) { nfs23_map_handle_t nfs23_digest; fsal_handle_t handle; nfs23_digest.object_id = 12345 + i; nfs23_digest.handle_hash = (1999 * i + now) % 479001599; rc = HandleMap_GetFH(&nfs23_digest, &handle); if(rc) { LogTest("Error %d retrieving handle !", rc); exit(rc); } rc = HandleMap_DelFH(&nfs23_digest); if(rc) { LogTest("Error %d deleting handle !", rc); exit(rc); } } gettimeofday(&tv3, NULL); timersub(&tv3, &tv2, &tvdiff); LogTest("Retrieved and deleted 10000 handles in %d.%06ds", (int)tvdiff.tv_sec, (int)tvdiff.tv_usec); rc = HandleMap_Flush(); gettimeofday(&tv3, NULL); timersub(&tv3, &tv1, &tvdiff); LogTest("Total time with %u threads (including flush): %d.%06ds", count, (int)tvdiff.tv_sec, (int)tvdiff.tv_usec); exit(0); }
////////////////////////////////////////////////////////////////////////////// // // Start // bool AppInit(int argc, char* argv[]) { boost::thread_group threadGroup; CScheduler scheduler; bool fRet = false; // // Parameters // // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() ParseParameters(argc, argv); // Process help and version before taking care about datadir if (IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version")) { std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n"; if (IsArgSet("-version")) { strUsage += FormatParagraph(LicenseInfo()); } else { strUsage += "\n" + _("Usage:") + "\n" + " bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n"; strUsage += "\n" + HelpMessage(HMM_BITCOIND); } fprintf(stdout, "%s", strUsage.c_str()); return true; } try { if (!fs::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str()); return false; } try { ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)); } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); return false; } // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(ChainNameFromCommandLine()); } catch (const std::exception& e) { fprintf(stderr, "Error: %s\n", e.what()); return false; } // Command-line RPC bool fCommandLine = false; for (int i = 1; i < argc; i++) if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:")) fCommandLine = true; if (fCommandLine) { fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n"); exit(EXIT_FAILURE); } // -server defaults to true for bitcoind but not for the GUI so do this here SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console InitLogging(); InitParameterInteraction(); if (!AppInitBasicSetup()) { // InitError will have been called with detailed error, which ends up on console exit(EXIT_FAILURE); } if (!AppInitParameterInteraction()) { // InitError will have been called with detailed error, which ends up on console exit(EXIT_FAILURE); } if (!AppInitSanityChecks()) { // InitError will have been called with detailed error, which ends up on console exit(EXIT_FAILURE); } if (GetBoolArg("-daemon", false)) { #if HAVE_DECL_DAEMON fprintf(stdout, "Bitcoin server starting\n"); // Daemonize if (daemon(1, 0)) { // don't chdir (1), do close FDs (0) fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno)); return false; } #else fprintf(stderr, "Error: -daemon is not supported on this operating system\n"); return false; #endif // HAVE_DECL_DAEMON } fRet = AppInitMain(threadGroup, scheduler); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { PrintExceptionContinue(NULL, "AppInit()"); } if (!fRet) { Interrupt(threadGroup); // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of // the startup-failure cases to make sure they don't result in a hang due to some // thread-blocking-waiting-for-another-thread-during-startup case } else { WaitForShutdown(&threadGroup); } Shutdown(); return fRet; }
int main(int argc, char **argv) { int rc, i; ns_testset_t *p_test; char path[FSAL_MAX_PATH_LEN]; unsigned int gen = 0; unsigned int dev = DEV; /* Init logging */ SetNamePgm("test_ns"); SetDefaultLogging("TEST"); SetNameFunction("main"); InitLogging(); /* namespace init */ rc = NamespaceInit(ROOT_INODE, DEV, &gen); if(rc) { LogTest("NamespaceInit rc=%d\n", rc); exit(1); } for(i = 0; i < 2; i++) { /* creation des entrees */ for(p_test = testset; p_test->name != NULL; p_test++) { rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name, p_test->entry_inode, DEV, &gen); LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode, p_test->name, p_test->entry_inode, rc); if(rc) exit(1); /* This is an error */ } /* tentative de recreation */ for(p_test = testset; p_test->name != NULL; p_test++) { rc = NamespaceAdd(p_test->parent_inode, DEV, gen, p_test->name, p_test->entry_inode, DEV, &gen); LogTest("Redundant NamespaceAdd(%lu,%s->%lu) = %d\n", p_test->parent_inode, p_test->name, p_test->entry_inode, rc); if(rc) exit(1); /* This is an error */ } /* recolte du chemin complet de root */ rc = NamespacePath(ROOT_INODE, DEV, gen, path); if(rc) { LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE, rc); exit(1); } else LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE, path); /* recolte du chemin complet des entrees */ for(p_test = testset; p_test->name != NULL; p_test++) { rc = NamespacePath(p_test->entry_inode, DEV, gen, path); if(rc) { LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc); exit(1); } else LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path); } /* on efface les entrees en ordre inverse */ for(p_test--; p_test >= testset; p_test--) { rc = NamespaceRemove(p_test->parent_inode, DEV, gen, p_test->name); LogTest("NamespaceRemove(%lu,%s) = %d\n", p_test->parent_inode, p_test->name, rc); } /* on essaye d'obtenir leur nom */ for(p_test = testset; p_test->name != NULL; p_test++) { rc = NamespacePath(p_test->entry_inode, DEV, gen, path); if(rc == 0) { LogTest("NamespacePath(%lu) => \"%s\"\n", p_test->entry_inode, path); exit(1); } else if(rc != ENOENT) { LogTest("NamespacePath(%lu) rc=%d\n", p_test->entry_inode, rc); exit(1); } else LogTest("NamespacePath(%lu) rc=%d (ENOENT)\n", p_test->entry_inode, rc); } } /* now create/remove a hardlink to a file N times */ rc = NamespaceAdd(ROOT_INODE, DEV, gen, "dir", ROOT_INODE + 1, DEV, &gen); if(rc) { LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1); exit(1); } rc = NamespaceAdd(ROOT_INODE + 1, DEV, gen, "subdir", ROOT_INODE + 2, DEV, &gen); if(rc) { LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1); exit(1); } rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, "entry", ROOT_INODE + 3, DEV, &gen); if(rc) { LogTest("NamespaceAdd error %d line %d\n", rc, __LINE__ - 1); exit(1); } /* create hardlinks and lookup */ for(i = 0; i < 3; i++) { char name[FSAL_MAX_NAME_LEN]; sprintf(name, "entry.hl%d", i); rc = NamespaceAdd(ROOT_INODE + 2, DEV, gen, name, ROOT_INODE + 3, DEV, &gen); LogTest("NamespaceAdd(%lu,%s->%lu) = %d\n", ROOT_INODE + 2, name, ROOT_INODE + 3, rc); if(rc) exit(1); rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path); if(rc) { LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc); exit(1); } else LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path); } /* delete hardlinks and lookup */ for(i = 0; i < 3; i++) { char name[FSAL_MAX_NAME_LEN]; sprintf(name, "entry.hl%d", i); rc = NamespaceRemove(ROOT_INODE + 2, DEV, gen, name); LogTest("NamespaceRemove(%lu,%s) = %d\n", ROOT_INODE + 2, name, rc); if(rc) exit(1); rc = NamespacePath(ROOT_INODE + 3, DEV, gen, path); if(rc) { LogTest("NamespacePath(%lu) rc=%d\n", ROOT_INODE + 3, rc); exit(1); } else LogTest("NamespacePath(%lu) => \"%s\"\n", ROOT_INODE + 3, path); } return 0; }