int main(int argc, char * argv[]) { util::daemon::Daemon my_daemon("ppbox_transfer.conf"); char const * default_argv[] = { "++Logger.stream_count=1", "++Logger.ResolverService=1", "++LogStream0.file=$LOG/ppbox_transfer.log", "++LogStream0.append=true", "++LogStream0.level=5", }; my_daemon.parse_cmdline(sizeof(default_argv) / sizeof(default_argv[0]), default_argv); my_daemon.parse_cmdline(argc, (char const **)argv); framework::process::SignalHandler sig_handler( framework::process::Signal::sig_int, boost::bind(&util::daemon::Daemon::post_stop, &my_daemon), true); framework::logger::global_logger().load_config(my_daemon.config()); util::daemon::use_module<ppbox::demux::DemuxerModule>(my_daemon); util::daemon::use_module<ppbox::mux::MuxerModule>(my_daemon); tools::transfer::TransferModule & module = util::daemon::use_module<tools::transfer::TransferModule>(my_daemon); my_daemon.start(framework::this_process::notify_wait); return module.error().value(); }
int main() { Conf::init_instance( CONF_FILE ); my_daemon(); Logger::init_instance(); Split::init_instance(); PageDB::init_instance(); InvertIdx::init_instance(); int start = clock(); initiation(); printf("%.3lf second\nInitialization completed\n", double( clock()-start)/ CLOCKS_PER_SEC); Conf cf = Conf::get_instance(); size_t queuesize = strtoul( cf["queuesize"].c_str() ,NULL, 0); size_t threadsnum = strtoul( cf["threadsnum"].c_str(), NULL, 0 ); ThreadPool threadpool( queuesize, threadsnum ); threadpool.start(); unsigned short port = atoi( cf["port"].c_str() ); EpollPoller epoller( cf["ip"], port, threadpool ); epoller.loop(); epoller.unloop(); threadpool.stop(); InvertIdx::shut_down(); PageDB::shut_down(); Split::shut_down(); Logger::shut_down(); return 0; }
int main(int argc, char **argv) { /* command line options */ int c; /* function-local options */ int foreground = FALSE; char *pid_file = NULL; /* config file */ char *configFile = NULL; /* config file parsing temp strings */ char tmp[MAX_CONFIG_STRING_SIZE], *tmpstr; /* open a connection to the syslog daemon */ openlog("pptpd", LOG_PID, PPTP_FACILITY); syslog(LOG_ERR, "MGR: Config file not found!"); /* process command line options */ while (1) { int option_index = 0; #ifdef BCRELAY char *optstring = "b:c:de:fhil:o:p:s:t:T:vwC:Dk"; #else char *optstring = "c:de:fhil:o:p:s:t:T:vwC:Dk"; #endif static struct option long_options[] = { #ifdef BCRELAY {"bcrelay", 1, 0, 0}, #endif {"conf", 1, 0, 'c'}, {"debug", 0, 0, 'd'}, {"ppp", 1, 0, 'e'}, {"fg", 0, 0, 'f'}, {"help", 0, 0, 'h'}, {"noipparam", 0, 0, 'i'}, {"listen", 1, 0, 'l'}, {"option", 1, 0, 'o'}, {"pidfile", 1, 0, 'p'}, {"speed", 1, 0, 's'}, {"stimeout", 1, 0, 't'}, {"ptimeout", 1, 0, 'T'}, {"version", 0, 0, 'v'}, {"logwtmp", 0, 0, 'w'}, {"connections", 1, 0, 'C'}, {"delegate", 0, 0, 'D'}, {"keep", 0, 0, 'k'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, optstring, long_options, &option_index); if (c == -1) break; /* convert long options to short form */ if (c == 0) #ifdef BCRELAY c = "bcdefhilopstvwCDk"[option_index]; #else c = "cdefhilopstvwCDk"[option_index]; #endif switch (c) { #ifdef BCRELAY case 'b': /* --bcrelay */ if (bcrelay) free(bcrelay); bcrelay = strdup(optarg); break; #endif case 'l': /* --listen */ tmpstr = lookup(optarg); if (!tmpstr) { syslog(LOG_ERR, "MGR: Invalid listening address: %s!", optarg); return 1; } if (bindaddr) free(bindaddr); bindaddr = strdup(tmpstr); break; case 'h': /* --help */ showusage(argv[0]); return 0; case 'i': /* --noipparam */ pptp_noipparam = TRUE; break; case 'e': /* --ppp */ if (ppp_binary) free(ppp_binary); ppp_binary = strdup(optarg); break; case 'd': /* --debug */ pptp_debug = TRUE; break; case 'f': /* --fg */ foreground = TRUE; break; case 'v': /* --version */ showversion(); return 0; case 'w': /* --logwtmp */ pptp_logwtmp = TRUE; break; case 'C': /* --connections */ pptp_connections = atoi(optarg); break; case 'D': /* --delegate */ pptp_delegate = TRUE; break; case 'o': /* --option */ if (pppdoptstr) free(pppdoptstr); pppdoptstr = strdup(optarg); break; case 'p': /* --pidfile */ if (pid_file) free(pid_file); pid_file = strdup(optarg); break; case 's': /* --speed */ if (speedstr) free(speedstr); speedstr = strdup(optarg); break; case 't': /* --stimeout */ pptp_stimeout = atoi(optarg); break; case 'T': /* --stimeout */ pptp_ptimeout = atoi(optarg); break; case 'k': /* --keep */ keep_connections = 1; break; case 'c': /* --conf */ { FILE *f; if (!(f = fopen(optarg, "r"))) { syslog(LOG_ERR, "MGR: Config file not found!"); return 1; } fclose(f); if(configFile) free(configFile); configFile = strdup(optarg); break; } default: showusage(argv[0]); return 1; } } /* Now that we have all the command line args.. lets open the * conf file and add anything else (remembering not to override * anything since the command line has more privilages :-) */ if (!configFile) configFile = strdup(PPTPD_CONFIG_FILE_DEFAULT); if (read_config_file(configFile, CONNECTIONS_KEYWORD, tmp) > 0) { pptp_connections = atoi(tmp); if (pptp_connections <= 0) pptp_connections = CONNECTIONS_DEFAULT; } slot_init(pptp_connections); if (!pptp_debug && read_config_file(configFile, DEBUG_KEYWORD, tmp) > 0) pptp_debug = TRUE; #ifdef BCRELAY if (!bcrelay && read_config_file(configFile, BCRELAY_KEYWORD, tmp) > 0) bcrelay = strdup(tmp); #endif if (!pptp_stimeout && read_config_file(configFile, STIMEOUT_KEYWORD, tmp) > 0) { pptp_stimeout = atoi(tmp); if (pptp_stimeout <= 0) pptp_stimeout = STIMEOUT_DEFAULT; } if (!pptp_ptimeout && read_config_file(configFile, PTIMEOUT_KEYWORD, tmp) > 0) { pptp_ptimeout = atoi(tmp); if (pptp_ptimeout <= 0) pptp_ptimeout = PTIMEOUT_DEFAULT; } if (!pptp_noipparam && read_config_file(configFile, NOIPPARAM_KEYWORD, tmp) > 0) { pptp_noipparam = TRUE; } if (!bindaddr && read_config_file(configFile, LISTEN_KEYWORD, tmp) > 0) { tmpstr = lookup(tmp); if(!tmpstr) { syslog(LOG_ERR, "MGR: Invalid listening address: %s!", tmp); return 1; } bindaddr = strdup(tmpstr); } if (!speedstr && read_config_file(configFile, SPEED_KEYWORD, tmp) > 0) speedstr = strdup(tmp); if (!pppdoptstr && read_config_file(configFile, PPPD_OPTION_KEYWORD, tmp) > 0) { pppdoptstr = strdup(tmp); } if (!ppp_binary && read_config_file(configFile, PPP_BINARY_KEYWORD, tmp) > 0) { ppp_binary = strdup(tmp); } if (!pptp_logwtmp && read_config_file(configFile, LOGWTMP_KEYWORD, tmp) > 0) { pptp_logwtmp = TRUE; } if (!pptp_delegate && read_config_file(configFile, DELEGATE_KEYWORD, tmp) > 0) { pptp_delegate = TRUE; } if (read_config_file(configFile, KEEP_KEYWORD, tmp) > 0) { keep_connections = TRUE; } if (!pid_file) pid_file = strdup((read_config_file(configFile, PIDFILE_KEYWORD, tmp) > 0) ? tmp : PIDFILE_DEFAULT); if (!pptp_delegate) { /* NOTE: remote then local, reason can be seen at the end of processIPStr */ /* grab the remoteip string from the config file */ if (read_config_file(configFile, REMOTEIP_KEYWORD, tmp) <= 0) { /* use "smart" defaults */ strlcpy(tmp, DEFAULT_REMOTE_IP_LIST, sizeof(tmp)); } processIPStr(REMOTE, tmp); /* grab the localip string from the config file */ if (read_config_file(configFile, LOCALIP_KEYWORD, tmp) <= 0) { /* use "smart" defaults */ strlcpy(tmp, DEFAULT_LOCAL_IP_LIST, sizeof(tmp)); } processIPStr(LOCAL, tmp); } free(configFile); /* if not yet set, adopt default PPP binary path */ if (!ppp_binary) ppp_binary = strdup(PPP_BINARY); /* check that the PPP binary is executable */ if (access(ppp_binary, X_OK) < 0) { syslog(LOG_ERR, "MGR: PPP binary %s not executable", ppp_binary); return 1; } /* check that the PPP options file is readable */ if (pppdoptstr && access(pppdoptstr, R_OK) < 0) { syslog(LOG_ERR, "MGR: PPP options file %s not readable", pppdoptstr); return 1; } #ifdef BCRELAY /* check that the bcrelay binary is executable */ if (bcrelay && access(BCRELAY_BIN, X_OK) < 0) { syslog(LOG_ERR, "MGR: bcrelay binary %s not executable", BCRELAY_BIN); return 1; } #endif syslog(LOG_INFO, "accel-pptpd-%s compiled for pppd-%s\n",VERSION, "2.4.2"); if (!foreground) { #if HAVE_DAEMON closelog(); freopen("/dev/null", "r", stdin); daemon(0, 0); /* returns to child only */ /* pid will have changed */ openlog("pptpd", LOG_PID, PPTP_FACILITY); #else /* !HAVE_DAEMON */ my_daemon(argc, argv); /* returns to child if !HAVE_FORK * never returns if HAVE_FORK (re-execs with -f) */ #endif } #ifdef BCRELAY if (bcrelay) { syslog(LOG_DEBUG, "CTRL: BCrelay incoming interface is %s", bcrelay); /* Launch BCrelay */ #ifndef HAVE_FORK switch(bcrelayfork = vfork()){ #else switch(bcrelayfork = fork()){ #endif case -1: /* fork() error */ syslog(LOG_ERR, "CTRL: Error forking to exec bcrelay"); _exit(1); case 0: /* child */ syslog(LOG_DEBUG, "CTRL (BCrelay Launcher): Launching BCrelay with pid %i", bcrelayfork); launch_bcrelay(); syslog(LOG_ERR, "CTRL (BCrelay Launcher): Failed to launch BCrelay."); _exit(1); } } /* End bcrelay */ #endif #ifdef CONFIG_NETtel /* turn the NETtel VPN LED on */ ledman_cmd(LEDMAN_CMD_ON, LEDMAN_VPN); #endif /* after we have our final pid... */ log_pid(pid_file); /* manage connections until SIGTERM */ pptp_manager(argc, argv); #ifdef BCRELAY if (bcrelayfork > 0) { syslog(LOG_DEBUG, "CTRL: Closing child BCrelay with pid %i", bcrelayfork); kill(bcrelayfork, SIGTERM); } #endif slot_free(); return 0; } static void log_pid(char *pid_file) { FILE *f; pid_t pid; pid = getpid(); if ((f = fopen(pid_file, "w")) == NULL) { syslog(LOG_ERR, "PPTPD: failed to open(%s), errno=%d\n", pid_file, errno); return; } fprintf(f, "%d\n", pid); fclose(f); }
int main(int argc, char **argv) { regex_t preg; /* command line options */ int c; char *ifout = ""; char *ifin = ""; #ifndef BCRELAY fprintf(stderr, "bcrelay: pptpd was compiled without support for bcrelay, exiting.\n" " run configure --with-bcrelay, make, and install.\n"); exit(1); #endif /* open a connection to the syslog daemon */ openlog("bcrelay", LOG_PID, PPTP_FACILITY); while (1) { int option_index = 0; static struct option long_options[] = { {"nolog", 0, 0, 0}, {"daemon", 0, 0, 0}, {"help", 0, 0, 0}, {"incoming", 1, 0, 0}, {"outgoing", 1, 0, 0}, {"ipsec", 1, 0, 0}, {"version", 0, 0, 0}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "ndhi:o:s:v", long_options, &option_index); if (c == -1) break; /* convert long options to short form */ if (c == 0) c = "ndhiosv"[option_index]; switch (c) { case 'n': vnologging = 1; break; case 'd': vdaemon = 1; break; case 'h': showusage(argv[0]); return 0; case 'i': ifin = strdup(optarg); break; case 'o': ifout = strdup(optarg); break; case 's': ipsec = strdup(optarg); // Validate the ipsec parameters regcomp(&preg, "ipsec[0-9]+:[0-9]+.[0-9]+.[0-9]+.255", REG_EXTENDED); if (regexec(&preg, ipsec, 0, NULL, 0)) { syslog(LOG_INFO,"Bad syntax: %s", ipsec); fprintf(stderr, "\nBad syntax: %s\n", ipsec); showusage(argv[0]); return 0; } else { regfree(&preg); break; } case 'v': showversion(); return 0; default: showusage(argv[0]); return 1; } } if (ifin == "") { syslog(LOG_INFO,"Incoming interface required!"); showusage(argv[0]); _exit(1); } if (ifout == "" && ipsec == "") { syslog(LOG_INFO,"Listen-mode or outgoing or IPsec interface required!"); showusage(argv[0]); _exit(1); } else { sprintf(interfaces,"%s|%s", ifin, ifout); } // If specified, become Daemon. if (vdaemon) { #if HAVE_DAEMON closelog(); freopen("/dev/null", "r", stdin); /* set noclose, we want stdout/stderr still attached if we can */ daemon(0, 1); /* returns to child only */ /* pid will have changed */ openlog("bcrelay", LOG_PID, PPTP_FACILITY); #else /* !HAVE_DAEMON */ my_daemon(argc, argv); /* returns to child if !HAVE_FORK * never returns if HAVE_FORK (re-execs without -d) */ #endif } else { syslog(LOG_INFO, "Running as child\n"); } mainloop(argc,argv); _exit(0); }
int main(int argc, char *argv[]) { int chnr = 0; struct channel_item_st *link = NULL; pthread_t pthd; openlog("netradio", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "daemon start."); sep_arg(&args); my_daemon(); if (install_signal() != 0) { syslog(LOG_ERR, "install signal failed, exit."); closelog(); exit(1); } if (save_pid(LOCK_FILE) == -1) { closelog(); exit(1); } if ((sd = create_socket(args.multicast_group)) == -1) { syslog(LOG_ERR, "create socket failed, exit."); closelog(); exit(1); } if (medialib_get_channellist(&chnr, &link) != 0) { syslog(LOG_ERR, "init channellist failed, exit."); closelog(); close(sd); exit(1); } if (pthread_create(&pthd, NULL, channel_0_pth, link) != 0) { syslog(LOG_ERR, "init channel 0 failed, exit."); medialib_free_channellist(link); closelog(); close(sd); exit(1); } //失败时会释放link 和已经打开的线程 if (create_channel_pthread(link) == -1) { syslog(LOG_ERR, "init channel pthread failed, exit."); closelog(); close(sd); exit(1); } wait_until_exit(link, chnr); pthread_cancel(pthd); /*cancel pth 0*/ pthread_join(pthd, NULL); syslog(LOG_INFO, "netradio daemon exit."); closelog(); close(sd); return 0; }