ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_pidfile(const char *bname) { /* * If the OS has a pidfile(), call that, but still call * pid_file_write(). Even if both want to write the same file, * writing it twice will still work. */ #ifdef HAVE_PIDFILE pidfile(bname); #endif if (pidfile_path != NULL) return; if (bname == NULL) bname = getprogname(); pidfile_path = pid_file_write(bname); pidfile_pid = getpid(); #if defined(HAVE_ATEXIT) if (pidfile_path != NULL) atexit(pidfile_cleanup); #elif defined(HAVE_ON_EXIT) if (pidfile_path != NULL) on_exit(pidfile_cleanup); #endif }
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile(const char *basename) { if(pidfile_path != NULL) return; if(basename == NULL) basename = getprogname(); pidfile_path = pid_file_write(basename); #if defined(HAVE_ATEXIT) atexit(pidfile_cleanup); #elif defined(HAVE_ON_EXIT) on_exit(pidfile_cleanup); #endif }
static void zipper_run(zipper_t *zipper, bool run_foreground) { char ip_store_file_path[PATH_MAX]; if (0 != conf_get_path(zipper->config_, "ip_store_file_path", ip_store_file_path)) { ASSERT(0, "log file path isn't configured\n", ip_store_file_path); return; } if (0 != ipstore_load(zipper->ip_store_, ip_store_file_path)) { ASSERT(0, "load ip store file [%s] faild\n", ip_store_file_path); } if (!run_foreground) { int ret = fork(); ASSERT (ret >= 0, "fork failed"); if (ret > 0) { pid_file_write(zipper->pid_file_, ret); exit(0); } ret = setsid(); ASSERT( ret != -1, "setsid failed"); int fd = open("/dev/null", O_RDWR, 0); ASSERT(fd != -1, "open null dev failed"); (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); if (fd > 2) (void)close(fd); } dns_server_start(zipper->dns_server_, handle_dns_query, zipper); command_server_start(zipper->command_server_); event_base_dispatch(zipper->base_event_); }