这篇教程C++ write_pidfile函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中write_pidfile函数的典型用法代码示例。如果您正苦于以下问题:C++ write_pidfile函数的具体用法?C++ write_pidfile怎么用?C++ write_pidfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了write_pidfile函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ev_irc_connect/** internal functions implementation starts here **/int ev_irc_connect(void* dummy1, void* dummy2){ int cr; stdlog(L_INFO, "Connecting to IRC server %s:%i", RemoteServer, RemotePort); cr = irc_FullConnect(RemoteServer, RemotePort, ServerPass, 0); if(cr < 0) { errlog("Could not connect to IRC server: %s", irc_GetLastMsg()); exit(1); } stdlog(L_INFO, "Netjoin complete, %.1d Kbs received", irc_InByteCount()/1024); /* not sure if this fork should be on the irc module for now lets leave it like this to make sure we only fork after the connection is fully established */ if( nofork == 0 ) { fork_process(); write_pidfile(); } irc_LoopWhileConnected(); errlog("Disconnected:%s/n", irc_GetLastMsg()); /* stdlog(L_INFO, "PTlink IRC Services Terminated"); */ return 0;}
开发者ID:joaompinto,项目名称:ptlink.irc.services,代码行数:30,
示例2: startvoidstart(const char *cmd, monitor_t *monitor) {exec: { pid = fork(); int status; switch (pid) { case -1: perror("fork()"); exit(1); case 0: log("sh -c /"%s/"", cmd); execl("/bin/bash", "bash", "-c", cmd, 0); perror("execl()"); exit(1); default: log("pid %d", pid); // write pidfile if (monitor->pidfile) { log("write pid to %s", monitor->pidfile); write_pidfile(monitor->pidfile, pid); } // wait for exit waitpid(pid, &status, 0); // signalled if (WIFSIGNALED(status)) { log("signal(%s)", strsignal(WTERMSIG(status))); log("sleep(%d)", monitor->sleepsec); sleep(monitor->sleepsec); goto error; } // check status if (WEXITSTATUS(status)) { log("exit(%d)", WEXITSTATUS(status)); log("sleep(%d)", monitor->sleepsec); sleep(monitor->sleepsec); goto error; } // alerts error: { if (monitor->on_error) { log("on error /"%s/"", monitor->on_error); int status = system(monitor->on_error); if (status) { log("exit(%d)", status); log("shutting down"); exit(status); } } goto exec; } }}}
开发者ID:guybrush,项目名称:nexus,代码行数:60,
示例3: daemonizeint daemonize(){ pid_t pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); } if (pid > 0) { exit(EXIT_SUCCESS); } if (write_pidfile() != 0) { return -1; } int ret = setsid(); if (ret == -1) { XLOG_ERR("failed to set session id: %s", strerror(errno)); unlink(PIDFILE); return -1; } for (int fd = getdtablesize(); fd >= 0; --fd) { close(fd); } chdir("/"); int fd = open("/dev/null", O_RDWR); dup(fd); dup(fd); return 0;}
开发者ID:afett,项目名称:rarpd,代码行数:34,
示例4: client_backgroundstatic void client_background(void){ bb_daemonize(0); logmode &= ~LOGMODE_STDIO; /* rewrite pidfile, as our pid is different now */ write_pidfile(client_config.pidfile);}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:7,
示例5: daemonizevoid daemonize(const char *pidfile){ pid_t pid, sid; /* Return if already a daemon */ if (getppid() == 1) return; /* Fork off the parent process */ pid = fork(); if (pid < 0) { PERROR("fork", errno); exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { exit(EXIT_SUCCESS); } /* At this point we are executing as the child process */ write_pidfile(pidfile); /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { PERROR("setsid", errno); exit(EXIT_FAILURE); } /* Change the current working directory. This prevents the current directory from being locked; hence not being able to remove it. */ if ((chdir("/")) < 0) { PERROR("chdir", errno); exit(EXIT_FAILURE); } /* Redirect standard files to /dev/null */ if (freopen( "/dev/null", "r", stdin) == NULL) { PERROR("freopen: stdin", errno); } if (freopen( "/dev/null", "w", stdout) == NULL) { PERROR("freopen: stdout", errno); } if (freopen( "/dev/null", "w", stderr) == NULL) { PERROR("freopen: stderr", errno); }}
开发者ID:esben,项目名称:dupdate,代码行数:51,
示例6: mainint main(int argc, char *argv[]){ char *password; int port = DEFAULT_LISTEN_PORT; parameters_t pars; struct sched_param sched_par; openlog("tcpconsole", LOG_CONS|LOG_NDELAY|LOG_NOWAIT|LOG_PID, LOG_DAEMON); if (getuid()) error_exit("This program must be invoked with root-rights."); password = read_password("/etc/tcpconsole.pw"); if (signal(SIGTERM, SIG_IGN) == SIG_ERR) error_exit("signal(SIGTERM) failed"); if (signal(SIGHUP, SIG_IGN) == SIG_ERR) error_exit("signal(SIGHUP) failed"); pars.sysrq_fd = open_file("/proc/sysrq-trigger", O_WRONLY); pars.vcsa0_fd = open_file("/dev/vcsa", O_RDONLY); if (setpriority(PRIO_PROCESS, 0, -10) == -1) error_exit("Setpriority failed"); if (nice(-20) == -1) error_exit("Failed to set nice-value to -20"); if (mlockall(MCL_CURRENT) == -1 || mlockall(MCL_FUTURE) == -1) error_exit("Failed to lock program in core"); memset(&sched_par, 0x00, sizeof(sched_par)); sched_par.sched_priority = sched_get_priority_max(SCHED_RR); if (sched_setscheduler(0, SCHED_RR, &sched_par) == -1) error_exit("Failed to set scheduler properties for this process"); syslog(LOG_INFO, "tcpconsole started"); write_pidfile("/var/run/tcpconsole.pid"); if ((pars.dmesg_buffer_size = klogctl(10, NULL, 0)) == -1) error_exit("klogctl(10) failed"); pars.dmesg_buffer = (char *)malloc(pars.dmesg_buffer_size + 1); if (!pars.dmesg_buffer) error_exit("malloc failure"); listen_on_socket(port, &pars, password); return 1;}
开发者ID:flok99,项目名称:tcpconsole,代码行数:51,
示例7: mainintmain(int argc, char **argv) { struct Config *config = NULL; const char *config_file = "/etc/sniproxy.conf"; int background_flag = 1; pid_t pid; int opt; while ((opt = getopt(argc, argv, "fc:")) != -1) { switch (opt) { case 'c': config_file = optarg; break; case 'f': /* foreground */ background_flag = 0; break; default: usage(); exit(EXIT_FAILURE); } } config = init_config(config_file); if (config == NULL) { fprintf(stderr, "Unable to load %s/n", config_file); return 1; } init_server(config); if (background_flag) { pid = daemonize(config->user ? config->user : DEFAULT_USERNAME); if (pid != 0 && config->pidfile != NULL) { /* parent */ write_pidfile(config->pidfile, pid); free_config(config); return 0; } } run_server(); free_config(config); return 0;}
开发者ID:nmav,项目名称:sniproxy,代码行数:47,
示例8: become_daemon/* Become a SysV daemon */int become_daemon(void){ int fd; long maxfd, i; switch (fork()) { case -1: return -1; /* error */ case 0: break; /* child process created */ default: exit(EXIT_FAILURE); /* parent receives child's PID */ } /* Detach from any terminal and create an independent session. */ if (setsid() == -1) return -1; /* Ensure that the daemon can never re-acquire a terminal again. */ switch (fork()) { case -1: return -1; case 0: break; default: exit(EXIT_FAILURE); } /* Reset file mode creation mask. */ umask(0); /* Change current directory to root directory (/) */ if (chdir("/") == -1) return -1; /* Find maximum open file descriptors */ maxfd = sysconf(_SC_OPEN_MAX); if (maxfd == -1) maxfd = MAX_OPEN; /* Close all open file descriptors */ for (i = 0; i < maxfd; i++) close(i); /* Connect /dev/null to stdin, stdout, stderr */ close(STDIN_FILENO); fd = open("/dev/null", O_RDWR); if (fd != STDIN_FILENO) return -1; if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO) return -1; if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO) return -1; /* Write PID file in /var/run/ */ if (write_pidfile() == -1) return -1; return 0;}
开发者ID:arpankapoor,项目名称:sield,代码行数:48,
示例9: mainintmain(int argc, char **argv){ monitor_t monitor; monitor.pidfile = NULL; monitor.mon_pidfile = NULL; monitor.on_error = NULL; monitor.logfile = "mon.log"; monitor.daemon = 0; monitor.sleepsec = 1; command_t program; program.data = &monitor; command_init(&program, "mon", VERSION); command_option(&program, "-l", "--log <path>", "specify logfile [mon.log]", on_log); command_option(&program, "-s", "--sleep <sec>", "sleep seconds before re-executing [1]", on_sleep); command_option(&program, "-S", "--status", "check status of --pidfile", on_status); command_option(&program, "-p", "--pidfile <path>", "write pid to <path>", on_pidfile); command_option(&program, "-m", "--mon-pidfile <path>", "write mon(1) pid to <path>", on_mon_pidfile); command_option(&program, "-P", "--prefix <str>", "add a log prefix", on_prefix); command_option(&program, "-d", "--daemonize", "daemonize the program", on_daemonize); command_option(&program, "-e", "--on-error <cmd>", "execute <cmd> on errors", on_error); command_parse(&program, argc, argv); // command required if (!program.argc) error("<cmd> required"); const char *cmd = program.argv[0]; // signals signal(SIGTERM, graceful_exit); signal(SIGQUIT, graceful_exit); // daemonize if (monitor.daemon) { daemonize(); redirect_stdio_to(monitor.logfile); } // write mon pidfile if (monitor.mon_pidfile) { log("write mon pid to %s", monitor.mon_pidfile); write_pidfile(monitor.mon_pidfile, getpid()); } start(cmd, &monitor); return 0;}
开发者ID:guybrush,项目名称:nexus,代码行数:47,
示例10: mainintmain(void){ const pid_t pid = getpid(); write_pidfile(pid); wait_for_peer_invocation(); static const char dir[] = "attach-p-cmd.test cmd"; int rc = chdir(dir); printf("%-5d chdir(/"%s/") = %s/n" "%-5d +++ exited with 0 +++/n", pid, dir, sprintrc(rc), pid); return 0;}
开发者ID:MIPS,项目名称:external-strace,代码行数:17,
示例11: do_work/// <summary>Our raspicomm daemon specific work gets done.</summary>void do_work(void){ /* setup the syslog for logging */ init_syslog(); /* read the settings from the settings file */ Settings settings; int ret; if ((ret = load_settings(&settings)) < 0) { //syslog(LOG_ERR, "loading settings failed (%i)", ret); exit(EXIT_FAILURE); } if (settings.log) { syslog(LOG_INFO, "starting..."); syslog(LOG_INFO, "using %s: port '%i' and pidfile '%s' and log=%i", ret == 0 ? "default configuration" : "configurationfile", settings.port, settings.pidfile, settings.log); } /* write the pidfile */ if ( write_pidfile(settings.pidfile) != 0) if (settings.log) syslog(LOG_ERR, "writing PIDFILE '%s' failed", settings.pidfile); /* use the settings to initialize the raspicomm */ if (daemon_init_raspicomm(&settings) != SUCCESS) exit(EXIT_FAILURE); /* init the pipe */ if (init_pipe() != 0) if (settings.log) syslog(LOG_ERR, "init_pipe failed"); /* block and work */ enter_main_loop(&settings); /* tear down raspicomm */ daemon_shutdown();}
开发者ID:GarethWza,项目名称:raspicomm,代码行数:46,
示例12: detach/* Detach from current terminal, write pidfile, kill parent*/bool detach(void) { setup_signals(); /* First check if we can open a fresh new pidfile */#ifndef HAVE_MINGW if(!write_pidfile()) return false; /* If we succeeded in doing that, detach */ closelogger();#endif if(do_detach) {#ifndef HAVE_MINGW if(daemon(0, 0)) { fprintf(stderr, "Couldn't detach from terminal: %s", strerror(errno)); return false; } /* Now UPDATE the pid in the pidfile, because we changed it... */ if(!write_pid(pidfilename)) { fprintf(stderr, "Could not write pid file %s: %s/n", pidfilename, strerror(errno)); return false; }#else if(!statushandle) exit(install_service());#endif } openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR)); logger(LOG_NOTICE, "tincd %s (%s %s) starting, debug level %d", VERSION, __DATE__, __TIME__, debug_level); xalloc_fail_func = memory_full; return true;}
开发者ID:codoranro,项目名称:tinc,代码行数:46,
示例13: client_backgroundstatic void client_background(void){#ifdef __uClinux__ bb_error_msg("cannot background in uclinux (yet)");/* ... mainly because udhcpc calls client_background() * in _the _middle _of _udhcpc _run_, not at the start! * If that will be properly disabled for NOMMU, client_background() * will work on NOMMU too */#else// chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh? bb_daemonize(DAEMON_CHDIR_ROOT); /* rewrite pidfile, as our pid is different now */ if (client_config.pidfile) write_pidfile(client_config.pidfile); logmode &= ~LOGMODE_STDIO;#endif client_config.foreground = 1; /* Do not fork again. */ client_config.background_if_no_lease = 0;}
开发者ID:AlickHill,项目名称:Lantern,代码行数:19,
示例14: daemonizebool daemonize(const char* pid_path){ /* Double fork. */ pid_t ret; ret = fork(); if (ret == -1) { err(EXIT_FAILURE, "fork()"); } else if (ret > 0) { waitpid(ret, NULL, 0); return false; } ret = fork(); if (ret == -1) { err(EXIT_FAILURE, "fork()"); } else if (ret > 0) { exit(EXIT_SUCCESS); } /* Write PID. */ if (!write_pidfile(pid_path)) err(EXIT_FAILURE, "%s", pid_path); /* Change directory. */ if (chdir("/") == -1) warn("%s", "/"); /* Create new session ID. */ if (setsid() == -1) warn("setsid()"); /* Close standard streams. */ if (int fd = open("/dev/null", O_RDWR) > 0) for (int i = 0; i < 3; ++i) dup2(fd, i); return true;}
开发者ID:Kaisrlik,项目名称:clang-cache,代码行数:39,
示例15: main//.........这里部分代码省略......... if (daemon_mode) {#ifndef __APPLE__ daemon (1, 0);#else /* __APPLE */ /* daemon is deprecated under APPLE * use fork() instead * */ switch (fork ()) { case -1: seaf_warning ("Failed to daemonize"); exit (-1); break; case 0: /* all good*/ break; default: /* kill origin process */ exit (0); }#endif /* __APPLE */ }#endif /* !WIN32 */ cdc_init ();#if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init();#endif#if !GLIB_CHECK_VERSION(2,32,0) g_thread_init (NULL);#endif if (!debug_str) debug_str = g_getenv("SEAFILE_DEBUG"); seafile_debug_set_flags_string (debug_str); if (seafile_dir == NULL) seafile_dir = g_build_filename (config_dir, "seafile", NULL); if (logfile == NULL) logfile = g_build_filename (seafile_dir, "seafile.log", NULL); if (seafile_log_init (logfile, ccnet_debug_level_str, seafile_debug_level_str) < 0) { seaf_warning ("Failed to init log./n"); exit (1); } client = ccnet_init (central_config_dir, config_dir); if (!client) exit (1); register_processors (client); start_rpc_service (client, cloud_mode); create_sync_rpc_clients (central_config_dir, config_dir); create_async_rpc_clients (client); seaf = seafile_session_new (central_config_dir, seafile_dir, client); if (!seaf) { seaf_warning ("Failed to create seafile session./n"); exit (1); } seaf->is_master = is_master; seaf->ccnetrpc_client = ccnetrpc_client; seaf->async_ccnetrpc_client = async_ccnetrpc_client; seaf->ccnetrpc_client_t = ccnetrpc_client_t; seaf->async_ccnetrpc_client_t = async_ccnetrpc_client_t; seaf->client_pool = ccnet_client_pool_new (central_config_dir, config_dir); seaf->cloud_mode = cloud_mode; load_history_config (); g_free (seafile_dir); g_free (logfile); set_signal_handlers (seaf); /* init seaf */ if (seafile_session_init (seaf) < 0) exit (1); if (seafile_session_start (seaf) < 0) exit (1); if (pidfile) { if (write_pidfile (pidfile) < 0) { ccnet_message ("Failed to write pidfile/n"); return -1; } } atexit (on_seaf_server_exit); /* Create a system default repo to contain the tutorial file. */ schedule_create_system_default_repo (seaf); ccnet_main (client); return 0;}
开发者ID:henryhe008,项目名称:seafile,代码行数:101,
示例16: main//.........这里部分代码省略.........#ifdef ENABLE_IPV6 } else { memset(&me6, 0, sizeof(me6)); me6.sin6_family = AF_INET6; me6.sin6_addr = in6addr_any; me6.sin6_port = htons(port); rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); }#endif /* ENABLE_IPV6 */ if(0 != rc) { error = SOCKERRNO; logmsg("Error binding socket on port %hu: (%d) %s", port, error, strerror(error)); goto server_cleanup; } logmsg("Running %s version on port %d", ipv_inuse, (int)port); /* start accepting connections */ rc = listen(sock, 5); if(0 != rc) { error = SOCKERRNO; logmsg("listen() failed with error: (%d) %s", error, strerror(error)); goto server_cleanup; } /* ** As soon as this server writes its pid file the test harness will ** attempt to connect to this server and initiate its verification. */ wrotepidfile = write_pidfile(pidname); if(!wrotepidfile) goto server_cleanup; for (;;) { msgsock = accept(sock, NULL, NULL); if(got_exit_signal) break; if (CURL_SOCKET_BAD == msgsock) { error = SOCKERRNO; logmsg("MAJOR ERROR: accept() failed with error: (%d) %s", error, strerror(error)); break; } /* ** As soon as this server acepts a connection from the test harness it ** must set the server logs advisor read lock to indicate that server ** logs should not be read until this lock is removed by this server. */ set_advisor_read_lock(SERVERLOGS_LOCK); serverlogslocked = 1; logmsg("====> Client connect");#ifdef TCP_NODELAY /* * Disable the Nagle algorithm to make it easier to send out a large * response in many small segments to torture the clients more. */ flag = 1;
开发者ID:bagobor,项目名称:vs-curl-test,代码行数:67,
示例17: start_stop_daemon_main//.........这里部分代码省略......... if (opt & OPT_s) { signal_nr = get_signum(signame); if (signal_nr < 0) bb_show_usage(); } if (!(opt & OPT_a)) startas = execname; if (!execname) /* in case -a is given and -x is not */ execname = startas; if (execname) { G.execname_sizeof = strlen(execname) + 1; G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1); }// IF_FEATURE_START_STOP_DAEMON_FANCY(// if (retry_arg)// retries = xatoi_positive(retry_arg);// ) //argc -= optind; argv += optind; if (userspec) { user_id = bb_strtou(userspec, NULL, 10); if (errno) user_id = xuname2uid(userspec); } /* Both start and stop need to know current processes */ do_procinit(); if (opt & CTX_STOP) { int i = do_stop(); return (opt & OPT_OKNODO) ? 0 : (i <= 0); } if (G.found_procs) { if (!QUIET) printf("%s is already running/n%u/n", execname, (unsigned)G.found_procs->pid); return !(opt & OPT_OKNODO); }#ifdef OLDER_VERSION_OF_X if (execname) xstat(execname, &G.execstat);#endif *--argv = startas; if (opt & OPT_BACKGROUND) {#if BB_MMU bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS + DAEMON_DOUBLE_FORK); /* DAEMON_DEVNULL_STDIO is superfluous - * it's always done by bb_daemonize() */#else /* Daemons usually call bb_daemonize_or_rexec(), but SSD can do * without: SSD is not itself a daemon, it _execs_ a daemon. * The usual NOMMU problem of "child can't run indefinitely, * it must exec" does not bite us: we exec anyway. */ pid_t pid = xvfork(); if (pid != 0) { /* parent */ /* why _exit? the child may have changed the stack, * so "return 0" may do bad things */ _exit(EXIT_SUCCESS); } /* Child */ setsid(); /* detach from controlling tty */ /* Redirect stdio to /dev/null, close extra FDs */ bb_daemon_helper(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS);#endif } if (opt & OPT_MAKEPID) { /* User wants _us_ to make the pidfile */ write_pidfile(pidfile); } if (opt & OPT_c) { struct bb_uidgid_t ugid; parse_chown_usergroup_or_die(&ugid, chuid); if (ugid.uid != (uid_t) -1L) { struct passwd *pw = xgetpwuid(ugid.uid); if (ugid.gid != (gid_t) -1L) pw->pw_gid = ugid.gid; /* initgroups, setgid, setuid: */ change_identity(pw); } else if (ugid.gid != (gid_t) -1L) { xsetgid(ugid.gid); setgroups(1, &ugid.gid); } }#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY if (opt & OPT_NICELEVEL) { /* Set process priority */ int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, INT_MIN/2, INT_MAX/2); if (setpriority(PRIO_PROCESS, 0, prio) < 0) { bb_perror_msg_and_die("setpriority(%d)", prio); } }#endif execvp(startas, argv); bb_perror_msg_and_die("can't execute '%s'", startas);}
开发者ID:nawawi,项目名称:busybox,代码行数:101,
示例18: crond_mainint crond_main(int argc UNUSED_PARAM, char **argv){ time_t t2; unsigned rescan; unsigned sleep_time; unsigned opts; INIT_G(); /* "-b after -f is ignored", and so on for every pair a-b */ opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l") /* -l and -d have numeric param */ ":l+" IF_FEATURE_CROND_D(":d+"); opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"), &G.log_level, &G.log_filename, &G.crontab_dir_name IF_FEATURE_CROND_D(,&G.log_level)); /* both -d N and -l N set the same variable: G.log_level */ if (!(opts & OPT_f)) { /* close stdin, stdout, stderr. * close unused descriptors - don't need them. */ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv); } if (!(opts & OPT_d) && G.log_filename == NULL) { /* logging to syslog */ openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON); logmode = LOGMODE_SYSLOG; } //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */ reopen_logfile_to_stderr(); xchdir(G.crontab_dir_name); log8("crond (busybox "BB_VER") started, log level %d", G.log_level); rescan_crontab_dir(); write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid"); /* Main loop */ t2 = time(NULL); rescan = 60; sleep_time = 60; for (;;) { struct stat sbuf; time_t t1; long dt; /* Synchronize to 1 minute, minimum 1 second */ t1 = t2; sleep(sleep_time - (time(NULL) % sleep_time)); t2 = time(NULL); dt = (long)t2 - (long)t1; reopen_logfile_to_stderr(); /* * The file 'cron.update' is checked to determine new cron * jobs. The directory is rescanned once an hour to deal * with any screwups. * * Check for time jump. Disparities over an hour either way * result in resynchronization. A negative disparity * less than an hour causes us to effectively sleep until we * match the original time (i.e. no re-execution of jobs that * have just been run). A positive disparity less than * an hour causes intermediate jobs to be run, but only once * in the worst case. * * When running jobs, the inequality used is greater but not * equal to t1, and less then or equal to t2. */ if (stat(G.crontab_dir_name, &sbuf) != 0) sbuf.st_mtime = 0; /* force update (once) if dir was deleted */ if (G.crontab_dir_mtime != sbuf.st_mtime) { G.crontab_dir_mtime = sbuf.st_mtime; rescan = 1; } if (--rescan == 0) { rescan = 60; rescan_crontab_dir(); } process_cron_update_file(); log5("wakeup dt=%ld", dt); if (dt < -60 * 60 || dt > 60 * 60) { bb_error_msg("time disparity of %ld minutes detected", dt / 60); /* and we do not run any jobs in this case */ } else if (dt > 0) { /* Usual case: time advances forward, as expected */ flag_starting_jobs(t1, t2); start_jobs(); sleep_time = 60; if (check_completions() > 0) { /* some jobs are still running */ sleep_time = 10; } } /* else: time jumped back, do not run any jobs */ } /* for (;;) */ return 0; /* not reached *///.........这里部分代码省略.........
开发者ID:AlexShiLucky,项目名称:busybox,代码行数:101,
示例19: mainintmain(int argc, char **argv) { const char *config_file = "/etc/sniproxy.conf"; int background_flag = 1; int max_nofiles = 65536; int opt; while ((opt = getopt(argc, argv, "fc:n:V")) != -1) { switch (opt) { case 'c': config_file = optarg; break; case 'f': /* foreground */ background_flag = 0; break; case 'n': max_nofiles = atoi(optarg); break; case 'V': printf("sniproxy %s/n", sniproxy_version);#ifdef HAVE_LIBUDNS printf("compiled with udns support/n");#endif return EXIT_SUCCESS; default: usage(); return EXIT_FAILURE; } } config = init_config(config_file, EV_DEFAULT); if (config == NULL) { fprintf(stderr, "Unable to load %s/n", config_file); usage(); return EXIT_FAILURE; } /* ignore SIGPIPE, or it will kill us */ signal(SIGPIPE, SIG_IGN); if (background_flag) { if (config->pidfile != NULL) remove(config->pidfile); daemonize(); if (config->pidfile != NULL) write_pidfile(config->pidfile, getpid()); } start_binder(); set_limits(max_nofiles); init_listeners(&config->listeners, &config->tables, EV_DEFAULT); /* Drop permissions only when we can */ drop_perms(config->user ? config->user : default_username); ev_signal_init(&sighup_watcher, signal_cb, SIGHUP); ev_signal_init(&sigusr1_watcher, signal_cb, SIGUSR1); ev_signal_init(&sigusr2_watcher, signal_cb, SIGUSR2); ev_signal_init(&sigint_watcher, signal_cb, SIGINT); ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM); ev_signal_start(EV_DEFAULT, &sighup_watcher); ev_signal_start(EV_DEFAULT, &sigusr1_watcher); ev_signal_start(EV_DEFAULT, &sigusr2_watcher); ev_signal_start(EV_DEFAULT, &sigint_watcher); ev_signal_start(EV_DEFAULT, &sigterm_watcher); resolv_init(EV_DEFAULT, config->resolver.nameservers, config->resolver.search, config->resolver.mode); init_connections(); ev_run(EV_DEFAULT, 0); free_connections(EV_DEFAULT); resolv_shutdown(EV_DEFAULT); free_config(config, EV_DEFAULT); stop_binder(); return 0;}
开发者ID:vavrecan,项目名称:sniproxy,代码行数:87,
示例20: eooqd_mainint eooqd_main(int argc, char *argv[]){ int r; char *pid_file_name, *instance_id_str; char *check; struct event *checkQueueEvent, *rePostEvent; struct timeval tv; struct rlimit limit; atlas_id= NULL; instance_id_str= NULL; pid_file_name= NULL; queue_id= ""; (void)getopt32(argv, "A:i:P:q:", &atlas_id, &instance_id_str, &pid_file_name, &queue_id); if (argc != optind+1) { bb_show_usage(); return 1; } instance_id= 0; if (instance_id_str) { instance_id= strtoul(instance_id_str, &check, 0); if (check[0] != '/0') { report("unable to parse instance id '%s'", instance_id_str); return 1; } } if(pid_file_name) { write_pidfile(pid_file_name); } state = xzalloc(sizeof(*state)); state->atlas_id= atlas_id; state->queue_file= argv[optind]; state->max_busy= 10; state->slots= xzalloc(sizeof(*state->slots) * state->max_busy); if (strlen(state->queue_file) + strlen(SUFFIX) + 1 > sizeof(state->curr_qfile)) { report("filename too long ('%s')", state->queue_file); return 1; } strlcpy(state->curr_qfile, state->queue_file, sizeof(state->curr_qfile)); strlcat(state->curr_qfile, SUFFIX, sizeof(state->curr_qfile)); signal(SIGQUIT, SIG_DFL); limit.rlim_cur= RLIM_INFINITY; limit.rlim_max= RLIM_INFINITY; setrlimit(RLIMIT_CORE, &limit); /* Create libevent event base */ EventBase= event_base_new(); if (!EventBase) { crondlog(DIE9 "event_base_new failed"); /* exits */ } DnsBase= evdns_base_new(EventBase, 1 /*initialize*/); if (!DnsBase) { event_base_free(EventBase); crondlog(DIE9 "evdns_base_new failed"); /* exits */ } checkQueueEvent= event_new(EventBase, -1, EV_TIMEOUT|EV_PERSIST, checkQueue, NULL); if (!checkQueueEvent) crondlog(DIE9 "event_new failed"); /* exits */ tv.tv_sec= 1; tv.tv_usec= 0; event_add(checkQueueEvent, &tv); rePostEvent= event_new(EventBase, -1, EV_TIMEOUT|EV_PERSIST, re_post, NULL); if (!rePostEvent) crondlog(DIE9 "event_new failed"); /* exits */ tv.tv_sec= 60; tv.tv_usec= 0; event_add(rePostEvent, &tv); r= event_base_loop(EventBase, 0); if (r != 0) crondlog(LVL9 "event_base_loop failed"); return 0;}
开发者ID:dkg,项目名称:ripe-atlas-fw,代码行数:99,
示例21: cr_serviceint cr_service(bool daemon_mode){ int server_fd = -1; int child_pid; struct sockaddr_un client_addr; socklen_t client_addr_len; { struct sockaddr_un server_addr; socklen_t server_addr_len; server_fd = socket(AF_LOCAL, SOCK_SEQPACKET, 0); if (server_fd == -1) { pr_perror("Can't initialize service socket"); goto err; } memset(&server_addr, 0, sizeof(server_addr)); memset(&client_addr, 0, sizeof(client_addr)); server_addr.sun_family = AF_LOCAL; if (opts.addr == NULL) { pr_warn("Binding to local dir address!/n"); opts.addr = CR_DEFAULT_SERVICE_ADDRESS; } strcpy(server_addr.sun_path, opts.addr); server_addr_len = strlen(server_addr.sun_path) + sizeof(server_addr.sun_family); client_addr_len = sizeof(client_addr); unlink(server_addr.sun_path); if (bind(server_fd, (struct sockaddr *) &server_addr, server_addr_len) == -1) { pr_perror("Can't bind"); goto err; } pr_info("The service socket is bound to %s/n", server_addr.sun_path); /* change service socket permissions, so anyone can connect to it */ if (chmod(server_addr.sun_path, 0666)) { pr_perror("Can't change permissions of the service socket"); goto err; } if (listen(server_fd, 16) == -1) { pr_perror("Can't listen for socket connections"); goto err; } } if (daemon_mode) { if (daemon(1, 0) == -1) { pr_perror("Can't run service server in the background"); goto err; } } if (opts.pidfile) { if (write_pidfile(getpid()) == -1) { pr_perror("Can't write pidfile"); goto err; } } if (setup_sigchld_handler()) goto err; while (1) { int sk; pr_info("Waiting for connection.../n"); sk = accept(server_fd, &client_addr, &client_addr_len); if (sk == -1) { pr_perror("Can't accept connection"); goto err; } pr_info("Connected./n"); child_pid = fork(); if (child_pid == 0) { int ret; if (restore_sigchld_handler()) exit(1); close(server_fd); init_opts(); ret = cr_service_work(sk); close(sk); exit(ret != 0); } if (child_pid < 0) pr_perror("Can't fork a child");//.........这里部分代码省略.........
开发者ID:hixichen,项目名称:criu_xichen_modify,代码行数:101,
示例22: main//.........这里部分代码省略......... case 'z': cleanup = 1; break; case 'h': default: printf(main_help); exit(0); } } argc -= optind; argv += optind; optind = 0; if (bnep_init()) return -1; /* Check non daemon modes first */ switch (mode) { case SHOW: do_show(); return 0; case KILL: do_kill(dst); return 0; case NONE: printf(main_help); return 0; } /* Initialize signals */ memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, NULL); sigaction(SIGPIPE, &sa, NULL); sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); sa.sa_handler = sig_term; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); if (detach) { if (fork()) exit(0); /* Direct stdin,stdout,stderr to '/dev/null' */ { int fd = open("/dev/null", O_RDWR); dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); close(fd); } setsid(); chdir("/"); } openlog("pand", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); syslog(LOG_INFO, "Bluetooth PAN daemon version %s", VERSION); if (src) { src_dev = hci_devid(src); if (src_dev < 0 || hci_devba(src_dev, &src_addr) < 0) { syslog(LOG_ERR, "Invalid source. %s(%d)", strerror(errno), errno); return -1; } } if (pidfile && write_pidfile()) return -1; if (dst) { /* Disable cache invalidation */ use_cache = 0; strncpy(cache.dst, dst, sizeof(cache.dst) - 1); str2ba(dst, &cache.bdaddr); cache.valid = 1; free(dst); } switch (mode) { case CONNECT: do_connect(); break; case LISTEN: do_listen(); break; } if (pidfile) unlink(pidfile); return 0;}
开发者ID:TELE-TWIN,项目名称:livebox2,代码行数:101,
示例23: main//.........这里部分代码省略......... if (0 != cf_fault_sink_activate_all_held()) { // Specifics of failure are logged in cf_fault_sink_activate_all_held(). cf_crash_nostack(AS_AS, "can't open log sink(s)"); } // Daemonize asd if specified. After daemonization, output to stderr will no // longer appear in terminal. Instead, check /tmp/aerospike-console.<pid> // for console output. if (! run_in_foreground && c->run_as_daemon) { // Don't close any open files when daemonizing. At this point only log // sink files are open - instruct cf_process_daemonize() to ignore them. int open_fds[CF_FAULT_SINKS_MAX]; int num_open_fds = cf_fault_sink_get_fd_list(open_fds); cf_process_daemonize(open_fds, num_open_fds); } // Log which build this is - should be the first line in the log file. cf_info(AS_AS, "<><><><><><><><><><> %s build %s <><><><><><><><><><>", aerospike_build_type, aerospike_build_id); // Includes echoing the configuration file to log. as_config_post_process(c, config_file); xdr_config_post_process(); // If we allocated a non-default config file name, free it. if (config_file != DEFAULT_CONFIG_FILE) { cf_free((void*)config_file); } // Write the pid file, if specified. if (! new_style_daemon) { write_pidfile(c->pidfile); } else { if (c->pidfile) { cf_warning(AS_AS, "will not write PID file in new-style daemon mode"); } } // Check that required directories are set up properly. validate_directory(c->work_directory, "work"); validate_directory(c->mod_lua.user_path, "Lua user"); validate_smd_directory(); // Initialize subsystems. At this point we're allocating local resources, // starting worker threads, etc. (But no communication with other server // nodes or clients yet.) as_json_init(); // Jansson JSON API used by System Metadata as_index_tree_gc_init(); // thread to purge dropped index trees as_sindex_thr_init(); // defrag secondary index (ok during population) as_nsup_init(); // load previous evict-void-time(s) // Initialize namespaces. Each namespace decides here whether it will do a // warm or cold start. Index arenas, partition structures and index tree // structures are initialized. Secondary index system metadata is restored. as_namespaces_init(cold_start_cmd, instance); // Initialize the storage system. For warm and cool restarts, this includes // fully resuming persisted indexes - this may take a few minutes. as_storage_init(); // Migrate memory to correct NUMA node (includes resumed index arenas). cf_topo_migrate_memory();
开发者ID:aerospike,项目名称:aerospike-server,代码行数:67,
示例24: main//.........这里部分代码省略......... _("%s. Please use --help to see a list of valid options./n"), error->message); exit (1); } /* Plugins specified with '--plugins' override those of config file */ plugins = plugins ? plugins : g_strdup (conf_plugins); g_free (conf_plugins); /* Parse the state file */ if (!parse_state_file (state_file, &error)) { fprintf (stderr, "State file %s parsing failed: (%d) %s/n", state_file, error ? error->code : -1, (error && error->message) ? error->message : "unknown"); /* Not a hard failure */ } g_clear_error (&error); /* Tricky: become_daemon is FALSE by default, so unless it's TRUE because * of a CLI option, it'll become TRUE after this */ become_daemon = !become_daemon; if (become_daemon) { if (daemon (0, 0) < 0) { int saved_errno; saved_errno = errno; fprintf (stderr, "Could not daemonize: %s [error %u]/n", g_strerror (saved_errno), saved_errno); exit (1); } if (write_pidfile (pidfile)) wrote_pidfile = TRUE; } if (g_fatal_warnings) { GLogLevelFlags fatal_mask; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); } /* * Set the umask to 0022, which results in 0666 & ~0022 = 0644. * Otherwise, if root (or an su'ing user) has a wacky umask, we could * write out an unreadable resolv.conf. */ umask (022); g_type_init (); if (!g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init ();#ifndef HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS#error HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS not defined#endif#if HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS /* Ensure that non-exported properties don't leak out, and that the * introspection 'access' permissions are respected. */ dbus_glib_global_set_disable_legacy_property_access ();
开发者ID:amedee,项目名称:barcode-utils,代码行数:67,
示例25: mainint32_t main(int argc, char *argv[]){ int32_t opt; uint32_t n; char *cfgfile = NULL; struct stat sb; struct bitcoind *b, *sigfrom; struct psj *psj; struct sigaction act; struct config *cfg; cfg = malloc(sizeof(*cfg)); if (cfg == NULL) { APPLOG(LOG_CRIT, "cfg malloc failed"); exit(255); } while ((opt = getopt(argc, argv, "hs:c:")) != -1) { switch(opt) { case 'c': cfgfile = optarg; break; case 's': cfg->force_pid = atoi(optarg); break; default: case 'h': usage(); } } APPLOG(LOG_NOTICE, "psj_sigmon v0.5 starting up"); /* config file parsing */ if (parse_cfg(cfgfile ? cfgfile : "config.cfg", cfg)) { APPLOG(LOG_CRIT, "parse_cfg error"); exit(255); } if (cfg->bitcoind_used == 0) { APPLOG(LOG_CRIT, "no bitcoind defined, exiting"); exit(EXIT_SUCCESS); } if (cfg->psj_used == 0) { APPLOG(LOG_CRIT, "no psj defined, exiting"); exit(EXIT_SUCCESS); } if (cfg->pidfile) { if (write_pidfile(cfg->pidfile) != 0) { APPLOG(LOG_CRIT, "write_pidfile failed"); exit(255); } } if (cfg->daemon) { APPLOG(LOG_NOTICE, "daemonising, you will hear no more from me"); if (daemon(false, false) == -1) { APPLOG(LOG_CRIT, "except daemonising failed.. dying"); exit(255); } cfg->daemon_done = true; } /* install signal handlers */ act.sa_flags = SA_SIGINFO; act.sa_sigaction = &sig_handler; sigaction(SIGUSR1, &act, NULL); sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); while(1) { select(0, NULL, NULL, NULL, NULL); APPLOG(LOG_INFO, "got signal %d, from pid %d", sig, pid); /* handle INT and TERM */ if (sig == SIGINT || sig == SIGTERM) /* break out of loop and exit gracefully */ break; /* ignore non-USR1 */ if (sig != SIGUSR1) continue; if (cfg->force_pid) {//.........这里部分代码省略.........
开发者ID:Shinkatechnologies,项目名称:poolserverj,代码行数:101,
示例26: main//.........这里部分代码省略......... error = SOCKERRNO; logmsg("Error creating socket: (%d) %s", error, strerror(error)); write_stdout("FAIL/n", 5); goto sockfilt_cleanup; } if(connectport) { /* Active mode, we should connect to the given port number */ mode = ACTIVE;#ifdef ENABLE_IPV6 if(!use_ipv6) {#endif memset(&me.sa4, 0, sizeof(me.sa4)); me.sa4.sin_family = AF_INET; me.sa4.sin_port = htons(connectport); me.sa4.sin_addr.s_addr = INADDR_ANY; if (!addr) addr = "127.0.0.1"; Curl_inet_pton(AF_INET, addr, &me.sa4.sin_addr); rc = connect(sock, &me.sa, sizeof(me.sa4));#ifdef ENABLE_IPV6 } else { memset(&me.sa6, 0, sizeof(me.sa6)); me.sa6.sin6_family = AF_INET6; me.sa6.sin6_port = htons(connectport); if (!addr) addr = "::1"; Curl_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr); rc = connect(sock, &me.sa, sizeof(me.sa6)); }#endif /* ENABLE_IPV6 */ if(rc) { error = SOCKERRNO; logmsg("Error connecting to port %hu: (%d) %s", connectport, error, strerror(error)); write_stdout("FAIL/n", 5); goto sockfilt_cleanup; } logmsg("====> Client connect"); msgsock = sock; /* use this as stream */ } else { /* passive daemon style */ sock = sockdaemon(sock, &port); if(CURL_SOCKET_BAD == sock) { write_stdout("FAIL/n", 5); goto sockfilt_cleanup; } msgsock = CURL_SOCKET_BAD; /* no stream socket yet */ } logmsg("Running %s version", ipv_inuse); if(connectport) logmsg("Connected to port %hu", connectport); else if(bind_only) logmsg("Bound without listening on port %hu", port); else logmsg("Listening on port %hu", port); wrotepidfile = write_pidfile(pidname); if(!wrotepidfile) { write_stdout("FAIL/n", 5); goto sockfilt_cleanup; } do { juggle_again = juggle(&msgsock, sock, &mode); } while(juggle_again);sockfilt_cleanup: if((msgsock != sock) && (msgsock != CURL_SOCKET_BAD)) sclose(msgsock); if(sock != CURL_SOCKET_BAD) sclose(sock); if(wrotepidfile) unlink(pidname); restore_signal_handlers(); if(got_exit_signal) { logmsg("============> sockfilt exits with signal (%d)", exit_signal); /* * To properly set the return status of the process we * must raise the same signal SIGINT or SIGTERM that we * caught and let the old handler take care of it. */ raise(exit_signal); } logmsg("============> sockfilt quits"); return 0;}
开发者ID:AndyUI,项目名称:curl,代码行数:101,
示例27: mainintmain(int argc, char *argv[]){ pid_t pid; int pm_fd; struct sigaction act; sigset_t sigmask; int c; char errmsg[PATH_MAX + 64]; int pid_fd; prog = argv[0]; if (geteuid() != 0) { (void) fprintf(stderr, "%s: Must be root/n", prog); exit(EXIT_FAILURE); } if ((pid_fd = open_pidfile(prog)) == -1) exit(EXIT_FAILURE); /* * Process options */ broadcast = 1; while ((c = getopt(argc, argv, "n")) != EOF) { switch (c) { case 'n': broadcast = 0; break; case '?': (void) fprintf(stderr, "Usage: %s [-n]/n", prog); exit(EXIT_FAILURE); } } pm_fd = open(PM, O_RDWR); if (pm_fd == -1) { (void) sprintf(errmsg, "%s: %s", prog, PM); perror(errmsg); exit(EXIT_FAILURE); } (void) close(pm_fd); /* * Initialize mutex lock used to insure only one command to * run at a time. */ if (mutex_init(&poweroff_mutex, USYNC_THREAD, NULL) != 0) { (void) fprintf(stderr, "%s: Unable to initialize mutex lock/n", prog); exit(EXIT_FAILURE); } if ((info = (pwr_info_t *)malloc(sizeof (pwr_info_t))) == NULL) { (void) sprintf(errmsg, "%s: malloc", prog); perror(errmsg); exit(EXIT_FAILURE); } /* * Daemon is set to go... */ if ((pid = fork()) < 0) exit(EXIT_FAILURE); else if (pid != 0) exit(EXIT_SUCCESS); pid = getpid(); openlog(prog, 0, LOG_DAEMON); if (write_pidfile(pid_fd, pid) == -1) /* logs errors on failure */ exit(EXIT_FAILURE); (void) close(pid_fd); /* * Close all the parent's file descriptors (Bug 1225843). */ closefrom(0); (void) setsid(); (void) chdir("/"); (void) umask(0);#ifdef DEBUG /* * Connect stdout to the console. */ if (dup2(open("/dev/console", O_WRONLY|O_NOCTTY), 1) == -1) { logerror("Unable to connect to the console."); }#endif info->pd_flags = PD_AC; info->pd_idle_time = -1; info->pd_start_time = 0; info->pd_finish_time = 0; /* * Allow SIGQUIT, SIGINT and SIGTERM signals to terminate us * any time */ act.sa_handler = kill_handler; (void) sigemptyset(&act.sa_mask); act.sa_flags = 0;//.........这里部分代码省略.........
开发者ID:andreiw,项目名称:polaris,代码行数:101,
示例28: zcip_main//.........这里部分代码省略......... // get the interface's ethernet address //memset(&ifr, 0, sizeof(ifr)); strncpy_IFNAMSIZ(ifr.ifr_name, argv_intf); xioctl(sock_fd, SIOCGIFHWADDR, &ifr); memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); // start with some stable ip address, either a function of // the hardware address or else the last address we used. // we are taking low-order four bytes, as top-order ones // aren't random enough. // NOTE: the sequence of addresses we try changes only // depending on when we detect conflicts. { uint32_t t; move_from_unaligned32(t, ((char *)ð_addr + 2)); srand(t); } if (ip.s_addr == 0) ip.s_addr = pick(); // FIXME cases to handle: // - zcip already running! // - link already has local address... just defend/update // daemonize now; don't delay system startup if (!FOREGROUND) {#if BB_MMU bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/);#endif if (verbose) bb_info_msg("start, interface %s", argv_intf); } write_pidfile(pidfile); bb_signals(BB_FATAL_SIGS, cleanup); // run the dynamic address negotiation protocol, // restarting after address conflicts: // - start with some address we want to try // - short random delay // - arp probes to see if another host uses it // - arp announcements that we're claiming it // - use it // - defend it, within limits // exit if: // - address is successfully obtained and -q was given: // run "<script> config", then exit with exitcode 0 // - poll error (when does this happen?) // - read error (when does this happen?) // - sendto error (in arp()) (when does this happen?) // - revents & POLLERR (link down). run "<script> deconfig" first state = PROBE; while (1) { struct pollfd fds[1]; unsigned deadline_us; struct arp_packet p; int source_ip_conflict; int target_ip_conflict; fds[0].fd = sock_fd; fds[0].events = POLLIN; fds[0].revents = 0; // poll, being ready to adjust current timeout if (!timeout_ms) { timeout_ms = random_delay_ms(PROBE_WAIT);
开发者ID:sdg7,项目名称:wl500g,代码行数:67,
示例29: ns_createvoid ns_create(int argc, char **argv){ pid_t pid; int ret, status; struct ns_exec_args args; int flags; char *pidf; args.argc = argc; args.argv = argv; ret = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, args.status_pipe); if (ret) { fprintf(stderr, "Pipe() failed %m/n"); exit(1); } flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWNET | CLONE_NEWIPC | SIGCHLD; if (getenv("ZDTM_USERNS")) flags |= CLONE_NEWUSER; pid = clone(ns_exec, args.stack_ptr, flags, &args); if (pid < 0) { fprintf(stderr, "clone() failed: %m/n"); exit(1); } close(args.status_pipe[1]); if (flags & CLONE_NEWUSER) { char pname[PATH_MAX]; int fd; snprintf(pname, sizeof(pname), "/proc/%d/uid_map", pid); fd = open(pname, O_WRONLY); if (fd < 0) { fprintf(stderr, "open(%s): %m/n", pname); exit(1); } if (write(fd, UID_MAP, sizeof(UID_MAP)) < 0) { fprintf(stderr, "write(" UID_MAP "): %m/n"); exit(1); } close(fd); snprintf(pname, sizeof(pname), "/proc/%d/gid_map", pid); fd = open(pname, O_WRONLY); if (fd < 0) { fprintf(stderr, "open(%s): %m/n", pname); exit(1); } if (write(fd, GID_MAP, sizeof(GID_MAP)) < 0) { fprintf(stderr, "write(" GID_MAP "): %m/n"); exit(1); } close(fd); } shutdown(args.status_pipe[0], SHUT_WR); pidf = pidfile; pidfile = malloc(strlen(pidfile) + 13); sprintf(pidfile, "%s%s", pidf, INPROGRESS); if (write_pidfile(pid)) { fprintf(stderr, "Preparations fail/n"); exit(1); } status = 1; ret = read(args.status_pipe[0], &status, sizeof(status)); if (ret != sizeof(status) || status) { fprintf(stderr, "The test failed (%d, %d)/n", ret, status); exit(1); } ret = read(args.status_pipe[0], &status, sizeof(status)); if (ret != 0) { fprintf(stderr, "Unexpected message from test/n"); exit(1); } unlink(pidfile); pidfile = pidf; if (write_pidfile(pid)) exit(1); exit(0);}
开发者ID:cyrillos,项目名称:criu,代码行数:89,
示例30: defined//.........这里部分代码省略......... /* Initialize the socket engine. Note that some engines can not survive a fork(), so this must be here. */ SocketEngine::Init(); ServiceManager::Init(); EventManager::Init(); new BotInfoType(); new XLineType(nullptr); new OperBlockType(); /* Read configuration file; exit if there are problems. */ try { Config = new Configuration::Conf(); } catch (const ConfigException &ex) { Log(LOG_TERMINAL) << ex.GetReason(); Log(LOG_TERMINAL) << "*** Support resources: Read through the anope.conf self-contained"; Log(LOG_TERMINAL) << "*** documentation. Read the documentation files found in the 'docs'"; Log(LOG_TERMINAL) << "*** folder. Visit our portal located at http://www.anope.org/. Join"; Log(LOG_TERMINAL) << "*** our support channel on /server irc.anope.org channel #anope."; throw CoreException("Configuration file failed to validate"); } /* Create me */ Configuration::Block *block = Config->GetBlock("serverinfo"); Me = new Server(NULL, block->Get<Anope::string>("name"), 0, block->Get<Anope::string>("description"), block->Get<Anope::string>("id")); for (std::pair<Anope::string, User *> p : UserListByNick) { User *u = p.second; if (u->type != UserType::BOT) continue; ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); bi->server = Me; ++Me->users; } /* Announce ourselves to the logfile. */ Log() << "Anope " << Anope::Version() << " starting up" << (Anope::Debug || Anope::ReadOnly ? " (options:" : "") << (Anope::Debug ? " debug" : "") << (Anope::ReadOnly ? " readonly" : "") << (Anope::Debug || Anope::ReadOnly ? ")" : ""); InitSignals(); /* Initialize multi-language support */ Language::InitLanguages(); /* Initialize random number generator */ block = Config->GetBlock("options"); srand(block->Get<unsigned>("seed") ^ time(NULL)); ModeManager::Apply(nullptr); /* load modules */ Log() << "Loading modules..."; for (int i = 0; i < Config->CountBlock("module"); ++i) ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<Anope::string>("name"), NULL);#ifndef _WIN32 /* We won't background later, so we should setuid now */ if (Anope::NoFork) setuidgid();#endif Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); if (protocol == NULL) throw CoreException("You must load a protocol module!"); /* Write our PID to the PID file. */ write_pidfile(); Log() << "Using IRCd protocol " << protocol->name; /* Auto assign sid if applicable */ if (IRCD->RequiresID) { Anope::string sid = IRCD->SID_Retrieve(); if (Me->GetSID() == Me->GetName()) Me->SetSID(sid); for (std::pair<Anope::string, User *> p : UserListByNick) { User *u = p.second; if (u->type != UserType::BOT) continue; ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); bi->GenerateUID(); } } /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);; static_cast<void>(MOD_RESULT); Log() << "Databases loaded"; for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) it->second->Sync();}
开发者ID:SaberUK,项目名称:anope,代码行数:101,
注:本文中的write_pidfile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ write_port函数代码示例 C++ write_pen_release函数代码示例 |