int main(int const argc, const char ** const argv) { struct xmlrpc_method_info3 const methodInfo = { .methodName = "sample.add", .methodFunction = &sample_add, .serverInfo = NULL }; TServer abyssServer; xmlrpc_registry * registryP; xmlrpc_env env; int terminationRequested; /* A boolean value */ const char * error; if (argc-1 != 1) { fprintf(stderr, "You must specify 1 argument: The TCP port number " "on which to listen for XML-RPC calls. " "You specified %d.\n", argc-1); exit(1); } AbyssInit(&error); xmlrpc_env_init(&env); registryP = xmlrpc_registry_new(&env); xmlrpc_registry_add_method3(&env, registryP, &methodInfo); xmlrpc_registry_set_shutdown(registryP, &requestShutdown, &terminationRequested); ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]), NULL, NULL); xmlrpc_server_abyss_set_handlers2(&abyssServer, "/RPC2", registryP); ServerInit(&abyssServer); setupSignalHandlers(); terminationRequested = 0; while (!terminationRequested) { printf("Waiting for next RPC...\n"); ServerRunOnce(&abyssServer); /* This waits for the next connection, accepts it, reads the HTTP POST request, executes the indicated RPC, and closes the connection. */ } ServerFree(&abyssServer); AbyssTerm(); return 0; }
int main(int const argc, const char ** const argv) { const char * const serverUrl = "http://localhost:8080/RPC2"; xmlrpc_env env; struct xmlrpc_clientparms clientParms; xmlrpc_client * clientP; if (argc-1 > 0) { fprintf(stderr, "This program has no arguments\n"); exit(1); } setupSignalHandlers(); /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* Required before any use of Xmlrpc-c client library: */ xmlrpc_client_setup_global_const(&env); die_if_fault_occurred(&env); clientParms.transport = "curl"; /* Create a client object */ xmlrpc_client_create(&env, 0, NULL, NULL, &clientParms, XMLRPC_CPSIZE(transport), &clientP); die_if_fault_occurred(&env); xmlrpc_client_set_interrupt(clientP, &interrupt); /* If our server is running 'xmlrpc_sample_add_server' normally, the RPC will finish almost instantly. UNLESS the adder is 1, in which case said server is programmed to take 3 seconds to do the computation, thus allowing us to demonstrate a timeout or CTL-C. */ addInterruptibly(clientP, serverUrl, 5, 7); /* Should finish instantly */ addInterruptibly(clientP, serverUrl, 5, 1); /* Should time out after 2 seconds */ xmlrpc_env_clean(&env); xmlrpc_client_destroy(clientP); xmlrpc_client_teardown_global_const(); return 0; }
int main (int argc, char **argv) { /* Signal * -TERM : Gracefully shutdown * -HUP : Reload configuration file */ signal (SIGPIPE, SIG_IGN); setupSignalHandlers (); initConfig (argc, argv); if (initServer () == -1) exit (EXIT_FAILURE); if (runServer () == -1) exit (EXIT_FAILURE); finalizeServer (); exit (EXIT_SUCCESS); }
// init server void initServer(void) { int j; // ignore sighup, sigpipe signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); // 设置信号处理函数 setupSignalHandlers(); if (server.syslog_enabled) { openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT, server.syslog_facility); } // 当前客户端相关状态 server.current_client = NULL; // 创建一个链表, 用于存储客户端 server.clients = listCreate(); // 创建客户端关闭链表 server.clients_to_close = listCreate(); // 从redis链表 server.slaves = listCreate(); // 监控链表 server.monitors = listCreate(); server.slaveseldb = -1; // 未锁定客户端链表 server.unblocked_clients = listCreate(); // 准备key链表 server.ready_keys = listCreate(); // 创建共享对象 createSharedObjects(); // 打开文件描述符限制 adjustOpenFilesLimit(); }
int bridgeMain(int argc, char** argv, char** envp) { static StaticObserver staticObserver; registerShutdownTask([&] { // NOTE: This function may be called at any time. It must not // depend on the prior execution of mongo initializers or the // existence of threads. ListeningSockets::get()->closeAll(); listener->shutdownAll(); }); setupSignalHandlers(); runGlobalInitializersOrDie(argc, argv, envp); startSignalProcessingThread(LogFileStatus::kNoLogFileToRotate); listener = stdx::make_unique<BridgeListener>(); listener->setupSockets(); listener->initAndListen(); return EXIT_CLEAN; }
int Tool::main( int argc , char ** argv, char ** envp ) { setupSignalHandlers(true); static StaticObserver staticObserver; mongo::runGlobalInitializersOrDie(argc, argv, envp); // hide password from ps output for (int i=0; i < (argc-1); ++i) { if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--password")) { char* arg = argv[i+1]; while (*arg) { *arg++ = 'x'; } } } if (!toolGlobalParams.useDirectClient) { if (toolGlobalParams.noconnection) { // do nothing } else { string errmsg; ConnectionString cs = ConnectionString::parse(toolGlobalParams.connectionString, errmsg); if ( ! cs.isValid() ) { toolError() << "invalid hostname [" << toolGlobalParams.connectionString << "] " << errmsg << std::endl; ::_exit(-1); } _conn = cs.connect( errmsg ); if ( ! _conn ) { toolError() << "couldn't connect to [" << toolGlobalParams.connectionString << "] " << errmsg << std::endl; ::_exit(-1); } toolInfoOutput() << "connected to: " << toolGlobalParams.connectionString << std::endl; } } else { verify( lastError.get( true ) ); Client::initThread("tools"); _conn = new DBDirectClient(); storageGlobalParams.dbpath = toolGlobalParams.dbpath; try { acquirePathLock(); } catch ( DBException& ) { toolError() << std::endl << "If you are running a mongod on the same " "path you should connect to that instead of direct data " "file access" << std::endl << std::endl; dbexit( EXIT_FS ); ::_exit(EXIT_FAILURE); } FileAllocator::get()->start(); dur::startup(); } int ret = -1; try { if (!toolGlobalParams.useDirectClient && !toolGlobalParams.noconnection) auth(); ret = run(); } catch ( DBException& e ) { toolError() << "assertion: " << e.toString() << std::endl; ret = -1; } catch(const boost::filesystem::filesystem_error &fse) { /* https://jira.mongodb.org/browse/SERVER-2904 Simple tools that don't access the database, such as bsondump, aren't throwing DBExceptions, but are throwing boost exceptions. The currently available set of error codes don't seem to match boost documentation. boost::filesystem::not_found_error (from http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm) doesn't seem to exist in our headers. Also, fse.code() isn't boost::system::errc::no_such_file_or_directory when this happens, as you would expect. And, determined from experimentation that the command-line argument gets turned into "\\?" instead of "/?" !!! */ #if defined(_WIN32) if (/*(fse.code() == boost::system::errc::no_such_file_or_directory) &&*/ (fse.path1() == "\\?")) printHelp(cerr); else #endif // _WIN32 toolError() << "error: " << fse.what() << std::endl; ret = -1; } if ( currentClient.get() ) currentClient.get()->shutdown(); if (toolGlobalParams.useDirectClient) dbexit( EXIT_CLEAN ); fflush(stdout); fflush(stderr); ::_exit(ret); }
void ServerUtil::setupSignalHandlers(const SignalHandler& handler) { registerSignalHandler(handler); setupSignalHandlers(); }
static void initServer() { signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); setupSignalHandlers(); }
void init() { serverID.init(); setupSignalHandlers(); Logstream::get().addGlobalTee( new RamLog("global") ); }
int main(int argc, char* argv[]) { #ifdef Q_OS_WIN _setmode(1, _O_BINARY); _setmode(2, _O_BINARY); #endif // Suppress debug output from Qt if not started with -v bool suppressQtDebugOutput = true; for (int i = 1; i < argc; ++i) { if (!qstrcmp(argv[i], "-v")) { suppressQtDebugOutput = false; break; } } // Has to be done before QApplication is constructed in case // QApplication itself produces debug output. if (suppressQtDebugOutput) qInstallMsgHandler(messageHandler); WebKit::initializeTestFonts(); QApplication::setGraphicsSystem("raster"); QApplication::setStyle(new QWindowsStyle); QApplication app(argc, argv); app.setQuitOnLastWindowClosed(false); #if HAVE(QT5) QCoreApplication::setAttribute(Qt::AA_Use96Dpi, true); #else #ifdef Q_WS_X11 QX11Info::setAppDpiY(0, 96); QX11Info::setAppDpiX(0, 96); #endif /* * QApplication will initialize the default application font based * on the application DPI at construction time, which might be * different from the DPI we explicitly set using QX11Info above. * See: https://bugreports.qt.nokia.com/browse/QTBUG-21603 * * To ensure that the application font DPI matches the application * DPI, we override the application font using the font we get from * a QWidget, which has already been resolved against the existing * default font, but with the correct paint-device DPI. */ QApplication::setFont(QWidget().font()); #endif #if HAVE(SIGNAL_H) setupSignalHandlers(&crashHandler); WTFSetCrashHook(&WTFCrashHook); #endif QStringList args = app.arguments(); if (args.count() < (!suppressQtDebugOutput ? 3 : 2)) { printUsage(); exit(1); } // Remove the first arguments, it is application name itself args.removeAt(0); WebCore::DumpRenderTree dumper; int index = args.indexOf(QLatin1String("--pixel-tests")); if (index != -1) { dumper.setDumpPixels(true); args.removeAt(index); } index = args.indexOf(QLatin1String("--stdout")); if (index != -1) { QString fileName = takeOptionValue(args, index); dumper.setRedirectOutputFileName(fileName); if (fileName.isEmpty() || !freopen(qPrintable(fileName), "w", stdout)) { fprintf(stderr, "STDOUT redirection failed."); exit(1); } } index = args.indexOf(QLatin1String("--stderr")); if (index != -1) { QString fileName = takeOptionValue(args, index); dumper.setRedirectErrorFileName(fileName); if (!freopen(qPrintable(fileName), "w", stderr)) { fprintf(stderr, "STDERR redirection failed."); exit(1); } } QWebDatabase::removeAllDatabases(); index = args.indexOf(QLatin1String("--timeout")); if (index != -1) { int timeout = takeOptionValue(args, index).toInt(); dumper.setTimeout(timeout); args.removeAt(index); } index = args.indexOf(QLatin1String("--no-timeout")); if (index != -1) { dumper.setShouldTimeout(false); args.removeAt(index); } index = args.indexOf(QLatin1String("-")); if (index != -1) { args.removeAt(index); // Continue waiting in STDIN for more test case after process one test case QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection); // Read and only read the first test case, ignore the others if (args.size() > 0) { // Process the argument first dumper.processLine(args[0]); } else QTimer::singleShot(0, &dumper, SLOT(readLine())); } else { // Go into standalone mode // Standalone mode need at least one test case if (args.count() < 1) { printUsage(); exit(1); } dumper.processArgsLine(args); } return app.exec(); }
static void WTFCrashHook() { setupSignalHandlers(SIG_DFL); }
int main(int argc, char *argv[]) { struct configOption *confOpt; char tmpstr[ALLOW_PATH_SIZE] = {""}; pthread_t ntid; g_logdir = NULL; g_logF = stderr; g_logFInt = STDERR_FILENO; setlocale(LC_ALL,""); zmalloc_enable_thread_safeness(); snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../", argv[0]); if (NULL == realpath(tmpstr, g_basedir)) { trvExit(0, "获取当前路径失败"); } g_conf = initConfig(); snprintf(tmpstr, ALLOW_PATH_SIZE, "%s/../conf/default.conf", g_basedir); configRead(g_conf, tmpstr); if (argc > 1) configRead(g_conf, argv[1]); /* argv[1] 是配置文件路径 */ if (NULL == g_conf->contents) { trvExit(0, "请选择配置文件"); } confOpt = configGet(g_conf, "log", "dir"); if (confOpt) { g_logdir = (char *)zmalloc(confOpt->valueLen+1); memcpy(g_logdir, confOpt->value, confOpt->valueLen); g_logdir[confOpt->valueLen] = 0x00; g_logF = fopen(g_logdir, "a+"); g_logFInt = fileno(g_logF); } signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); setupSignalHandlers(); /** * 主线程睡眠,等待网络就绪 * 单独开一个线程处理网路 */ pthread_mutex_lock(&g_rootThreadMutex); pthread_create(&ntid, NULL, _NTInit, NULL); pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex); pthread_mutex_unlock(&g_rootThreadMutex); _STInitPlanet(NULL); /* 主线程睡眠,避免退出进程 */ pthread_cond_wait(&g_rootThreadCond, &g_rootThreadMutex); pthread_mutex_unlock(&g_rootThreadMutex); return 0; }