int main (int argc, char* argv[]) { int f[2000]; oram_args_t *args = malloc(sizeof(oram_args_t)); args_parse(args, argc, argv); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); if (args->mode == ORAM_MODE_SERVER) { if (args->daemon == ORAM_DAEMON_STOP) { if (daemon_stop(args) != 0) { errf("cannot stop"); return -1; } return 0; } else if (args->daemon == ORAM_DAEMON_RESTART) { if (daemon_stop(args) != 0) { errf("cannot stop"); return -1; } if (daemon_start(args) != 0) { errf("cannot start"); return -1; } } else if (args->daemon == ORAM_DAEMON_START) { if (daemon_start(args) != 0) { errf("cannot start"); return -1; } } server_run(args, &sv_ctx); } else { client_ctx ctx; oram_client_args ar; ar.verbose = 1; if (client_init(&ctx, &ar) < 0) return -1; // if (client_create(&ctx, 6000, 1) < 0) // return -1; if (client_load(&ctx, 1) < 0) return -1; unsigned char data[ORAM_BLOCK_SIZE]; int m; for(m = 0;m < 100;m++) { data[0] = m; oblivious_access(m, ORAM_ACCESS_WRITE, data, &ctx); } for(m = 0;m < 100;m++) { oblivious_access(m, ORAM_ACCESS_READ, data, &ctx); f[m] = data[0]; } for (m = 0;m < 100;m++) assert(f[m] == m); client_save(&ctx, 0); } return 0; }
int main(int argc, char *argv[]) { int opt; while ((opt = getopt(argc, argv, "hl:sp:")) != -1) { switch (opt) { case 's': use_syslog = true; break; case 'p': if (use_syslog) { syslog_pri = decodepri(optarg) | LOG_PID; } else { errx(EX_USAGE, "you need to specify \"-s\"."); } break; case 'l': logfilename = strdup(optarg); break; case 'h': usage(); exit(0); break; default: printf("invalid option: %c\n", opt); usage(); exit(1); } } return (daemon_start()); }
int main(int argc, char **argv) { struct cmd_args args; newt_config config; int ret; /* register signal handler */ init_signal_handler(); // parse command-line arguments parse_opt(argc, argv, &args); if(args.config_path == NULL) { perror("failed to load configuration file"); exit(1); } ret = load_config(args.config_path, &config); if(ret == RET_ERROR) { perror("failed to load configuration file"); exit(1); } if(daemon_initialize() == RET_ERROR) { exit(1); } if(daemon_start(config) == RET_ERROR) { exit(1); } return 0; }
/****************************************************************************** * * * Function: main * * * * Purpose: executes proxy processes * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ int main(int argc, char **argv) { zbx_task_t task = ZBX_TASK_START; char ch; progname = get_program_name(argv[0]); /* parse the command-line */ while ((char)EOF != (ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts, NULL))) { switch (ch) { case 'c': CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg); break; case 'R': if (0 == strcmp(zbx_optarg, ZBX_CONFIG_CACHE_RELOAD)) task = ZBX_TASK_CONFIG_CACHE_RELOAD; else { printf("invalid runtime control option: %s\n", zbx_optarg); exit(EXIT_FAILURE); } break; case 'h': help(); exit(-1); break; case 'V': version(); exit(-1); break; default: usage(); exit(-1); break; } } if (NULL == CONFIG_FILE) CONFIG_FILE = zbx_strdup(CONFIG_FILE, SYSCONFDIR "/zabbix_proxy.conf"); /* required for simple checks */ init_metrics(); zbx_load_config(); if (ZBX_TASK_CONFIG_CACHE_RELOAD == task) exit(SUCCEED == zbx_sigusr_send(ZBX_TASK_CONFIG_CACHE_RELOAD) ? EXIT_SUCCESS : EXIT_FAILURE); #ifdef HAVE_OPENIPMI init_ipmi_handler(); #endif return daemon_start(CONFIG_ALLOW_ROOT); }
/****************************************************************************** * * * Function: main * * * * Purpose: executes proxy processes * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ int main(int argc, char **argv) { ZBX_TASK_EX t = {ZBX_TASK_START}; char ch; #if defined(PS_OVERWRITE_ARGV) || defined(PS_PSTAT_ARGV) argv = setproctitle_save_env(argc, argv); #endif progname = get_program_name(argv[0]); /* parse the command-line */ while ((char)EOF != (ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts, NULL))) { switch (ch) { case 'c': CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg); break; case 'R': if (SUCCEED != parse_rtc_options(zbx_optarg, daemon_type, &t.flags)) exit(EXIT_FAILURE); t.task = ZBX_TASK_RUNTIME_CONTROL; break; case 'h': help(); exit(EXIT_SUCCESS); break; case 'V': version(); exit(EXIT_SUCCESS); break; default: usage(); exit(EXIT_FAILURE); break; } } if (NULL == CONFIG_FILE) CONFIG_FILE = zbx_strdup(CONFIG_FILE, SYSCONFDIR "/zabbix_proxy.conf"); /* required for simple checks */ init_metrics(); zbx_load_config(); if (ZBX_TASK_RUNTIME_CONTROL == t.task) exit(SUCCEED == zbx_sigusr_send(t.flags) ? EXIT_SUCCESS : EXIT_FAILURE); #ifdef HAVE_OPENIPMI init_ipmi_handler(); #endif return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER); }
void server() { // load Config File and Settings fprintf(stdout, "Starting fidistat Server...\n"); openlog("fidistat-server", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "Started Fidistat Server"); struct pidfh *pfh = daemon_start('s'); // Handle Signals signal(SIGTERM, handleSigterm_S); signal(SIGCHLD, handleChild); // Open Socket initConf(); tls_init(); struct tls* ctx = tls_server(); int sock = initTLS_S(ctx); sckt = sock; int connfd, pid; listen(sock, 10); // Destroy Config destroyConf(); while(!term) { connfd = accept(sock, (struct sockaddr*) NULL, NULL); if (term) { break; } pid = fork(); if (pid < 0) { syslog(LOG_ERR, "forking new Worker failed"); } else if (pid == 0) { close(sock); syslog(LOG_INFO, "New incoming connection"); worker(connfd, ctx); syslog(LOG_INFO, "Closing connection"); exit(0); } else { close(connfd); } } syslog(LOG_INFO, "Shutting down Server"); close(sock); tls_close(ctx); tls_free(ctx); tls_config_free(tlsServer_conf); pidfile_remove(pfh); syslog(LOG_INFO, "Stopped Fidistat Server"); closelog(); exit(0); }
bool daemon_sigchld(struct daemon_info* di, unsigned int waitbeforerestart) { int status; waitpid(di->di_pid, &status, 0); if (waitbeforerestart != 0) { (void)sleep(waitbeforerestart); } return daemon_start(di); }
int main(int argc, char *argv[]) { int c; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"config", required_argument, 0, 'c'}, {0, 0, 0, 0} }; while (1) { int option_index = 0; c = getopt_long(argc, argv, "hc:", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': usage(); exit(EXIT_SUCCESS); break; case 'c': if (!realpath(optarg, storaged_config_file)) { fprintf(stderr, "storaged failed: configuration file: %s: %s\n", optarg, strerror(errno)); exit(EXIT_FAILURE); } break; case '?': usage(); exit(EXIT_SUCCESS); break; default: usage(); exit(EXIT_FAILURE); break; } } if (storaged_initialize() != 0) { fprintf(stderr, "storaged start failed\n"); exit(EXIT_FAILURE); } openlog("storaged", LOG_PID, LOG_DAEMON); daemon_start(STORAGED_PID_FILE, on_start, on_stop, NULL); exit(0); }
int main( ) { int fd; daemon_start( 0 ); fd = open("/dev/console" , O_WRONLY ); while(1){ write( fd, "boke" , 4 ); sleep(1); } }
int main(int argc, char **argv) { int retval; signal(SIGINT, (void *)ctrlc); if (argc < 2) { usage(argv[0]); return 0; } cfg = cfg_parse(argv[1]); if (!cfg || !cfg_validate_all(cfg, ERROR_MODE)) { return 0; } if (log_open()) { lbanner(); } if (!proxy_parse()) { return 0; } retval = fork(); if (retval < 0) { perror("fork"); return 0; } else { if (!retval) { daemon_start(); fprintf(stderr, "*** An error occurred. Please check %s for more details! ***\n", (char *) hashtable_lookup(cfg, "daemon-logfile")); log_close(); _exit(1); } } return 1; }
/****************************************************************************** * * * Function: main * * * * Purpose: executes server processes * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ int main(int argc, char **argv) { struct tm *tm; struct timeval tv; int ms; char ch = '\0'; progname = get_program_name(argv[0]); /* parse the command-line */ while ((char) EOF != (ch = (char) zbx_getopt_long(argc, argv, shortopts, longopts, NULL))) { switch (ch) { case 'c': CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg); break; case 'h': help_jobarg(); exit(-1); break; case 'V': version_jobarg(); exit(-1); break; default: usage(); exit(-1); break; } } if (NULL == CONFIG_FILE) CONFIG_FILE = zbx_strdup(CONFIG_FILE, SYSCONFDIR "/jobarg_server.conf"); zbx_load_config(); gettimeofday(&tv, NULL); tm = localtime(&tv.tv_sec); ms = (int)(tv.tv_usec / 1000); zbx_snprintf(serverid, sizeof(serverid), "%04d%02d%02d%02d%02d%02d%03d", 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, ms); return daemon_start(CONFIG_ALLOW_ROOT); }
int main(int argc, char *argv[]) { if (argv[0] && argv[0][0]) program_name = argv[0]; /* figure out program name */ while (strchr(program_name, '/')) { program_name = strchr(program_name, '/') + 1; } /* extract interface name from plugin name */ if (strchr(program_name, '_')) { interface = strchr(program_name, '_') + 1; } /* * program should always run with a valid executable name */ if (strlen(interface) < 1) { errx(EX_USAGE, "Please run from symlink"); } /* resolve paths */ char *MUNIN_PLUGSTATE = getenv("MUNIN_PLUGSTATE"); /* Default is current directory */ if (!MUNIN_PLUGSTATE) MUNIN_PLUGSTATE = "."; asprintf(&pid_filename, "%s/%s.pid", MUNIN_PLUGSTATE, program_name); asprintf(&cache_filename, "%s/%s.value", MUNIN_PLUGSTATE, program_name); if (argc > 1) { char *first_arg = argv[1]; if (!strcmp(first_arg, "config")) { return config(interface); } if (!strcmp(first_arg, "acquire")) { return daemon_start(); } } return fetch(); }
int main(int argc, char *argv[]) { daemon_t *daemon; #ifdef _WIN32 #define sleep(x) Sleep((x)*1000) WORD wVersionRequested; WSADATA wsaData; int ret; wVersionRequested = MAKEWORD(2, 2); ret = WSAStartup(wVersionRequested, &wsaData); if (ret) { /* Couldn't find WinSock DLL */ return -1; } if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) { /* Version mismatch, requested version not found */ return -1; } #endif daemon = daemon_init(); daemon_start(daemon); running = 1; signal(SIGINT, handle_sigint); while (running) { sleep(1); } daemon_stop(daemon); daemon_destroy(daemon); #ifdef _WIN32 WSACleanup(); #endif return 0; }
static void check_daemon(void) { pid_t pid; newt_config config; init_newt_config(&config); if((pid = fork()) == 0) { CU_ASSERT(daemon_initialize(&config) == RET_SUCCESS); daemon_start(&config); } else { /* delay to wait for initialization of daemon to complete */ sleep(1); kill(pid, SIGINT); wait(NULL); } }
/****************************************************************************** * * * Function: main * * * * Purpose: executes server processes * * * * Parameters: * * * * Return value: * * * * Author: Eugene Grigorjev * * * * Comments: * * * ******************************************************************************/ int main(int argc, char **argv) { char ch = '\0'; progname = argv[0]; /* Parse the command-line. */ while ((ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts,NULL)) != (char)EOF) switch (ch) { case 'c': CONFIG_FILE = strdup(zbx_optarg); break; case 'h': help(); exit(-1); break; case 'V': version(); exit(-1); break; default: usage(); exit(-1); break; } if(CONFIG_FILE == NULL) { CONFIG_FILE=strdup("/etc/zabbix/zabbix_proxy.conf"); } /* Required for simple checks */ init_metrics(); init_config(); #ifdef HAVE_OPENIPMI init_ipmi_handler(); #endif return daemon_start(CONFIG_ALLOW_ROOT); }
int main(int argc, char *argv[]) { int i; signal(SIGPIPE, SIG_IGN); openlog("flexd", LOG_ERR , LOG_INFO); syslog(LOG_WARNING, "Starting flexd"); if (ax25_config_load_ports() == 0) { fprintf(stderr, "flexd error: No AX25 port data configured\n"); return 1; } process_options(argc, argv); if ((i = read_conf()) == -1) return 1; if ((is_daemon) && (!daemon_start(TRUE)) ) { fprintf(stderr, "flexd: cannot become a daemon\n"); return 1; } if ((i = update_flex()) == -1) { fprintf(stderr, "\nStopping application. Restart flexd after changing the configuration\n"); signal(SIGKILL, hup_handler); return (i); } signal(SIGHUP, hup_handler); signal(SIGALRM, alarm_handler); alarm(poll_time); for (;;) pause(); return 0; }
int main(int argc, char **argv) { std::string config_filename = sdns::conf[sdns::CONFIG_FILE], daemon_name = "sdns"; bool daemonize = false; #ifndef WINDOWS srandom((size_t)(&sdns::conf) + time(nullptr)); for(int opt; (opt = getopt(argc, argv, "c:ds:")) != -1;) { switch(opt) { case 'c': // config filename config_filename = optarg; break; case 'd': // daemonize daemonize = true; break; case 's': // syslog daemon name daemon_name = optarg; default: // '?' std::cerr << "Usage: " << argv[0] << " [-c config_filename] [-d (daemonize)] [-s syslog_daemon_name]" << std::endl; exit(EXIT_FAILURE); } } if(optind < argc) { eout() << "Unexpected argument: " << argv[optind]; exit(EXIT_FAILURE); } #endif sdns::conf.set_config_file(config_filename); try { if(daemonize) return daemon_start(&daemon_main, daemon_name.c_str()); else return daemon_main(); } catch(const e_exception &e) { eout() << "main() caught fatal or unhandled error: " << e; std::cerr << daemon_name << " main() caught fatal or unhandled error: " << e << std::endl; } return EXIT_FAILURE; }
int main(int argc, char** argv) { if (argc < 2) { std::cerr << "usage: " << argv[0] << " conf_file ..." << std::endl; return 0; } ///创建i_ini_file实例 if (create_ini_file_instance(&g_p_ini_file)) { std::cerr << "create ini_file instance failed" << std::endl; return -1; } if (g_p_ini_file->init(argv[1]) < 0) { std::cerr << "ini_file init failed, err: " << g_p_ini_file->get_last_errstr() << std::endl; g_p_ini_file->release(); g_p_ini_file = NULL; return -1; } ///开启精灵模式 if (daemon_start(argc, argv, g_p_ini_file) < 0) { return -1; } ///初始化日志系统 if (log_init(g_p_ini_file) < 0) { return -1; } ///读取dll中函数接口 char path[PATH_MAX] = {0}; if (g_p_ini_file->read_string("WorkInfo", "dll", path, sizeof(path), NULL)) { ERROR_LOG("fail to read dll_path from conf_file"); return -1; } g_dll_inst.set_dll_path(path); if (g_dll_inst.register_plugin() < 0) { ERROR_LOG("fail to register dll"); return -1; } ///读取bind_file中的内容 if (g_p_ini_file->read_string("WorkInfo", "bind_file", path, sizeof(path), NULL)) { ERROR_LOG("fail to read bind_file path from conf_file"); return -1; } std::list<bind_conf_t> bind_conf_list; bind_conf bind_conf_inst(path); if (bind_conf_inst.load_bind_conf(bind_conf_list) < 0) { ERROR_LOG("fail to read info from bind_file"); return -1; } ///初始化注册回调函数 tcp_io_event tcp_io_event_inst; udp_io_event udp_io_event_inst; if (g_dll_inst.proc_pkg_from_client) tcp_io_event_inst.set_tcp_proc_callback(g_dll_inst.proc_pkg_from_client); if (g_dll_inst.get_pkg_len) tcp_io_event_inst.set_tcp_pkg_len_callback(g_dll_inst.get_pkg_len); if (g_dll_inst.on_client_conn_closed) tcp_io_event_inst.set_tcp_close_callback(g_dll_inst.on_client_conn_closed); if (g_dll_inst.proc_udp_pkg_from_client) udp_io_event_inst.set_udp_proc_callback(g_dll_inst.proc_udp_pkg_from_client); if (g_dll_inst.on_client_conn_closed) udp_io_event_inst.set_udp_close_conn_callback(g_dll_inst.on_client_conn_closed); ///初始化网络监听 std::list<bind_conf_t>::iterator it = bind_conf_list.begin(); for (; it != bind_conf_list.end(); ++it) { inet_address serv_addr; #ifdef _IPV6 if (it->ip_addr == "0:0:0:0:0:0:0:0" || ip->ip_addr == "::" || ip->ip_addr == "::/128") { serv_addr.set_port(it->port); } else { serv_addr.set_ip_addr(it->ip_addr); serv_addr.set_port(it->port); } #else if (it->ip_addr == "0.0.0.0") { serv_addr.set_port(it->port); } else { serv_addr.set_ip_addr(it->ip_addr); serv_addr.set_port(it->port); } #endif if (it->type == TYPE_TCP) { acceptor<connection<sock_stream>, sock_acceptor>* p_acceptor = new (std::nothrow) acceptor<connection<sock_stream>, sock_acceptor>(serv_addr); if (!p_acceptor) { ERROR_LOG("tcp acceptor instantiate failed"); return -1; } p_acceptor->set_new_conn_callback( boost::bind(&tcp_io_event::tcp_on_new_conn, &tcp_io_event_inst, _1)); p_acceptor->set_on_message_callback( boost::bind(&tcp_io_event::tcp_on_message, &tcp_io_event_inst, _1, _2, _3)); //p_acceptor->set_on_write_comple_callback( // boost::bind(&tcp_io_event::tcp_on_write_complete, &tcp_io_event_inst, _1)); p_acceptor->set_on_close_callback( boost::bind(&tcp_io_event::tcp_on_close_conn, &tcp_io_event_inst, _1)); if (p_acceptor->start() < 0) { return -1; } g_tcp_acceptor_list.push_back(p_acceptor); } else { acceptor<connection<sock_dgram>, sock_dgram>* p_acceptor = new (std::nothrow) acceptor<connection<sock_dgram>, sock_dgram>(serv_addr); if (!p_acceptor) { ERROR_LOG("udp acceptor instantiate failed"); return -1; } p_acceptor->set_new_conn_callback( boost::bind(&udp_io_event::udp_on_new_conn, &udp_io_event_inst, _1)); p_acceptor->set_on_message_callback( boost::bind(&udp_io_event::udp_on_message, &udp_io_event_inst, _1, _2, _3)); //p_acceptor->set_on_write_comple_callback( // boost::bind(&udp_io_event::udp_on_write_comple, &udp_io_event_inst, _1)); p_acceptor->set_on_close_callback( boost::bind(&udp_io_event::udp_on_close_conn, &udp_io_event_inst, _1)); if (p_acceptor->start() < 0) { return -1; } g_udp_acceptor_list.push_back(p_acceptor); } } ///创建socketpair g_work_num = g_p_ini_file->read_int("WorkInfo", "worker_num", 1); for (int i = 0; i < g_work_num; i++) { connections_pool<connection<vpipe_sockpair> >* p_pool = connections_pool<connection<vpipe_sockpair> >::instance(); assert(p_pool); connection<vpipe_sockpair>* p_conn = p_pool->get_new_connection(); assert(p_conn); if ((p_conn->get_ipc_conn())->open() < 0) { return -1; } worker_proc_t tmp; tmp.id = i; tmp.worker_pid = 0; tmp.p_sockpair = p_conn; g_worker_proc_vec.push_back(tmp); } if (g_dll_inst.init_service && g_dll_inst.init_service(g_saved_argc, g_saved_argv, PROC_MAIN) != 0) { ERROR_LOG("main proc init_service failed"); return -1; } daemon_set_title("%s-[%s]", g_prog_name, "master"); ///fork工作进程 for (int i = 0; i < g_work_num; i++) { pid_t pid = fork(); switch (pid) { case -1: ERROR_LOG("fork failed, err: %s", strerror(errno)); return -1; case 0: ///子进程 worker_proc_loop(i); default: ///master进程 g_worker_proc_vec[i].worker_pid = pid; break; } } ///设置work进程cpu亲和性 for (int i = 0; i < g_work_num; i++) { if (set_cpu_affinity(g_work_num, g_worker_proc_vec[i].worker_pid, g_worker_proc_vec[i].id) < 0) { DEBUG_LOG("set_cpu_affinity failed, err: %s", strerror(errno)); } } master_proc_loop(); daemon_stop(); if (g_p_ini_file) { g_p_ini_file->uninit(); g_p_ini_file->release(); g_p_ini_file = NULL; } return 0; }
int main(int argc, char **argv) { if(parse_args(argc, argv)) return 0; int err = 0; printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime()); if(myconfig_init(argc, argv) < 0) { printf("myconfig_init fail %m\n"); goto error; } daemon_start(argc, argv); umask(0); ICALL(init_log); ICALL(init_glog); ICALL(init_fdinfo); ICALL(delay_task_init); ICALL(init_thread); ICALL(init_global); ICALL(vfs_init); ICALL(init_task_info); ICALL(init_file_filter); ICALL(init_tc); if (get_self_info(&self_ipinfo)) { LOG(glogfd, LOG_NORMAL, "get_self_role ERR!\n"); self_ipinfo.role = ROLE_FCS; } if (self_ipinfo.role <= UNKOWN || self_ipinfo.role >= SELF_IP) { LOG(glogfd, LOG_ERROR, "get_self_role ERR!\n"); fprintf(stderr, "get_self_role ERR!\n"); goto error; } if (self_ipinfo.role != ROLE_VOSS_MASTER) ICALL(init_vfs_agent); char *srole = iprole[self_ipinfo.role]; LOG(glogfd, LOG_NORMAL, "MY ROLE is %s\n", srole); t_thread_arg arg; memset(&arg, 0, sizeof(arg)); snprintf(arg.name, sizeof(arg.name), "./%s_client.so", srole); LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name); if (ROLE_FCS != self_ipinfo.role) { arg.port = g_config.sig_port; arg.flag = 1; } arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096); if (init_vfs_thread(&arg)) goto error; t_thread_arg arg1; memset(&arg1, 0, sizeof(arg1)); snprintf(arg1.name, sizeof(arg1.name), "./%s_http.so", srole); LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name); arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096); if (init_vfs_thread(&arg1)) goto error; thread_jumbo_title(); struct threadstat *thst = get_threadstat(); if(start_threads() < 0) goto out; thread_reached(thst); gen_pidfile(); printf("Server Started\n"); vfs_start_time = time(NULL); main_loop(thst); out: printf("Stopping Server %s (%s)...\n", version_string, compiling_date); thread_reached(thst); stop_threads(); myconfig_cleanup(); fini_fdinfo(); printf("Server Stopped.\n"); return restart; error: if(err == -ENOMEM) printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n"); printf("\033[31m\033[1mStart Fail.\033[0m\n"); return -1; }
int main(int argc, char *argv[]) { int opt = 0; int opt_index = 0; int daemonize = 1; int newid = 0; char *pidfile = COMMOTION_PIDFILE; char *statedir = COMMOTION_STATEDIR; char *socket_uri = COMMOTION_MANAGESOCK; //char *plugindir = COMMOTION_PLUGINDIR; char *profiledir = COMMOTION_PROFILEDIR; static const char *opt_string = "b:d:f:i:np:s:h"; static struct option long_opts[] = { {"bind", required_argument, NULL, 'b'}, {"plugins", required_argument, NULL, 'd'}, {"profiles", required_argument, NULL, 'f'}, {"nodeid", required_argument, NULL, 'i'}, {"nodaemon", no_argument, NULL, 'n'}, {"pid", required_argument, NULL, 'p'}, {"statedir", required_argument, NULL, 's'}, {"help", no_argument, NULL, 'h'} }; opt = getopt_long(argc, argv, opt_string, long_opts, &opt_index); while(opt != -1) { switch(opt) { case 'b': socket_uri = optarg; break; case 'd': //plugindir = optarg; break; case 'f': profiledir = optarg; break; case 'i': newid = atoi(optarg); break; case 'n': daemonize = 0; break; case 'p': pidfile = optarg; break; case 's': statedir = optarg; break; case 'h': default: print_usage(); return 0; break; } opt = getopt_long(argc, argv, opt_string, long_opts, &opt_index); } if(daemonize) daemon_start((char *)statedir, (char *)pidfile); co_id_set_from_int(newid); nodeid_t id = co_id_get(); DEBUG("Node ID: %d", (int) id.id); co_loop_create(); co_ifaces_create(); co_profiles_create(); co_profile_import_files(profiledir); co_cmd_add("help", cmd_help, "help <none>\n", "Print list of commands and usage information.\n", 0); co_cmd_add("list_profiles", cmd_list_profiles, "list_profiles <none>\n", "Print list of available profiles.\n", 0); co_cmd_add("up", cmd_up, "up <interface> <profile>\n", "Apply profile to interface.\n", 0); co_cmd_add("down", cmd_down, "down <interface>\n", "Bring specified interface down.\n", 0); co_cmd_add("status", cmd_status, "status <interface>\n", "Report profile of connected interface.\n", 0); co_cmd_add("state", cmd_state, "state <interface> <property>\n", "Report properties of connected interface.\n", 0); co_cmd_add("nodeid", cmd_nodeid, "nodeid <none>\n", "Print unique ID for this node\n", 0); co_cmd_add("nodeidset", cmd_set_nodeid_from_mac, "nodeid <mac>\n", "Use mac address to generate identifier for this node.\n", 0); //plugins_create(); //plugins_load_all(plugindir); co_socket_t *socket = NEW(co_socket, unix_socket); socket->poll_cb = dispatcher_cb; socket->register_cb = co_loop_add_socket; socket->bind(socket, socket_uri); co_loop_start(); co_loop_destroy(); return 0; }
int main(int argc, char **argv) { int exit_code = EXIT_FAILURE; int i; bool help = false; bool version = false; bool check_config = false; bool daemon = false; const char *debug_filter = NULL; bool libusb_debug = false; int pid_fd = -1; for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0) { help = true; } else if (strcmp(argv[i], "--version") == 0) { version = true; } else if (strcmp(argv[i], "--check-config") == 0) { check_config = true; } else if (strcmp(argv[i], "--daemon") == 0) { daemon = true; } else if (strcmp(argv[i], "--debug") == 0) { if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) { debug_filter = argv[++i]; } else { debug_filter = ""; } } else if (strcmp(argv[i], "--libusb-debug") == 0) { libusb_debug = true; } else { fprintf(stderr, "Unknown option '%s'\n\n", argv[i]); print_usage(); return EXIT_FAILURE; } } if (help) { print_usage(); return EXIT_SUCCESS; } if (version) { printf("%s\n", VERSION_STRING); return EXIT_SUCCESS; } if (check_config) { return config_check(CONFIG_FILENAME) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } config_init(CONFIG_FILENAME); if (config_has_error()) { fprintf(stderr, "Error(s) occurred while reading config file '%s'\n", CONFIG_FILENAME); goto error_config; } log_init(); if (daemon) { pid_fd = daemon_start(LOG_FILENAME, PID_FILENAME, false); } else { pid_fd = pid_file_acquire(PID_FILENAME, getpid()); if (pid_fd == PID_FILE_ALREADY_ACQUIRED) { fprintf(stderr, "Already running according to '%s'\n", PID_FILENAME); } } if (pid_fd < 0) { goto error_pid_file; } log_info("Brick Daemon %s started (pid: %u, daemonized: %d)", VERSION_STRING, getpid(), daemon ? 1 : 0); if (debug_filter != NULL) { log_enable_debug_override(debug_filter); } if (config_has_warning()) { log_warn("Warning(s) in config file '%s', run with --check-config option for details", CONFIG_FILENAME); } if (event_init() < 0) { goto error_event; } if (signal_init(NULL, handle_sigusr1) < 0) { goto error_signal; } if (hardware_init() < 0) { goto error_hardware; } if (usb_init(libusb_debug) < 0) { goto error_usb; } if (iokit_init() < 0) { goto error_iokit; } if (network_init() < 0) { goto error_network; } if (event_run(network_cleanup_clients_and_zombies) < 0) { goto error_run; } exit_code = EXIT_SUCCESS; error_run: network_exit(); error_network: iokit_exit(); error_iokit: usb_exit(); error_usb: hardware_exit(); error_hardware: signal_exit(); error_signal: event_exit(); error_event: log_info("Brick Daemon %s stopped", VERSION_STRING); error_pid_file: if (pid_fd >= 0) { pid_file_release(PID_FILENAME, pid_fd); } log_exit(); error_config: config_exit(); return exit_code; }
int main (int argc, char *argv[]) { int ch; JCR *jcr; cat_op mode; bool no_signals = false; bool test_config = false; char *uid = NULL; char *gid = NULL; start_heap = sbrk(0); setlocale(LC_ALL, ""); bindtextdomain("bareos", LOCALEDIR); textdomain("bareos"); init_stack_dump(); my_name_is(argc, argv, "bareos-dir"); init_msg(NULL, NULL); /* initialize message handler */ init_reload(); daemon_start_time = time(NULL); console_command = run_console_command; while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:v?")) != -1) { switch (ch) { case 'c': /* specify config file */ if (configfile != NULL) { free(configfile); } configfile = bstrdup(optarg); break; case 'd': /* set debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } Dmsg1(10, "Debug level = %d\n", debug_level); break; case 'f': /* run in foreground */ background = false; break; case 'g': /* set group id */ gid = optarg; break; case 'm': /* print kaboom output */ prt_kaboom = true; break; case 'r': /* run job */ if (runjob != NULL) { free(runjob); } if (optarg) { runjob = bstrdup(optarg); } break; case 's': /* turn off signals */ no_signals = true; break; case 't': /* test config */ test_config = true; break; case 'u': /* set uid */ uid = optarg; break; case 'v': /* verbose */ verbose++; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (!no_signals) { init_signals(terminate_dird); } if (argc) { if (configfile != NULL) { free(configfile); } configfile = bstrdup(*argv); argc--; argv++; } if (argc) { usage(); } if (configfile == NULL) { configfile = bstrdup(CONFIG_FILE); } /* * See if we want to drop privs. */ if (geteuid() == 0) { drop(uid, gid, false); /* reduce privileges if requested */ } my_config = new_config_parser(); parse_dir_config(my_config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); goto bail_out; } if (!check_resources()) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); goto bail_out; } if (!test_config) { /* we don't need to do this block in test mode */ if (background) { daemon_start(); init_stack_dump(); /* grab new pid */ } /* Create pid must come after we are a daemon -- so we have our final pid */ create_pid_file(me->pid_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs)); read_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs)); } set_jcr_in_tsd(INVALID_JCR); set_thread_concurrency(me->MaxConcurrentJobs * 2 + 4 /* UA */ + 5 /* sched+watchdog+jobsvr+misc */); lmgr_init_thread(); /* initialize the lockmanager stack */ load_dir_plugins(me->plugin_directory, me->plugin_names); /* * If we are in testing mode, we don't try to fix the catalog */ mode = (test_config) ? CHECK_CONNECTION : UPDATE_AND_FIX; if (!check_catalog(mode)) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); goto bail_out; } if (test_config) { terminate_dird(0); } if (!initialize_sql_pooling()) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); goto bail_out; } my_name_is(0, NULL, me->name()); /* set user defined name */ cleanup_old_files(); p_db_log_insert = (db_log_insert_func)dir_db_log_insert; #if !defined(HAVE_WIN32) signal(SIGHUP, reload_config); #endif init_console_msg(working_directory); Dmsg0(200, "Start UA server\n"); start_UA_server(me->DIRaddrs); start_watchdog(); /* start network watchdog thread */ if (me->jcr_watchdog_time) { init_jcr_subsystem(me->jcr_watchdog_time); /* start JCR watchdogs etc. */ } init_job_server(me->MaxConcurrentJobs); dbg_jcr_add_hook(db_debug_print); /* used to debug B_DB connexion after fatal signal */ // init_device_resources(); Dmsg0(200, "wait for next job\n"); /* Main loop -- call scheduler to get next job to run */ while ( (jcr = wait_for_next_job(runjob)) ) { run_job(jcr); /* run job */ free_jcr(jcr); /* release jcr */ set_jcr_in_tsd(INVALID_JCR); if (runjob) { /* command line, run a single job? */ break; /* yes, terminate */ } } terminate_dird(0); bail_out: return 0; }
int main(int argc, char **argv) { int s, i; struct sockaddr_in loc_addr; struct timeval timeout; time_t timenow, timelast = 0; int interval = 3600; fd_set fdset; if (!load_dests()) { fprintf(stderr, "rip98d: no destination routers defined\n"); return 1; } while ((i = getopt(argc, argv, "dlrt:v")) != -1) { switch (i) { case 'd': debug = TRUE; break; case 'l': logging = TRUE; break; case 'r': route_restrict = TRUE; break; case 't': interval = atoi(optarg) * 60; if (interval < 60 || interval > 7200) { fprintf(stderr, "rip98d: invalid time interval\n"); return 1; } break; case 'v': printf("rip98d: %s\n", VERSION); return 0; case ':': fprintf(stderr, "rip98d: invalid time interval\n"); return 1; case '?': fprintf(stderr, "usage: rip98d [-d] [-l] [-r] [-t interval] [-v]\n"); return 1; } } signal(SIGTERM, terminate); if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("rip98d: socket"); return 1; } memset((char *)&loc_addr, 0, sizeof(loc_addr)); loc_addr.sin_family = AF_INET; loc_addr.sin_addr.s_addr = htonl(INADDR_ANY); loc_addr.sin_port = htons(RIP_PORT); if (bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)) < 0) { perror("rip98d: bind"); close(s); return 1; } if (!daemon_start(FALSE)) { fprintf(stderr, "rip98d: cannot become a daemon\n"); close(s); return 1; } if (logging) { openlog("rip98d", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "starting"); } for (;;) { FD_ZERO(&fdset); FD_SET(s, &fdset); timeout.tv_sec = 60; timeout.tv_usec = 0; select(s + 1, &fdset, NULL, NULL, &timeout); if (!read_routes()) { if (logging) closelog(); return 1; } if (FD_ISSET(s, &fdset)) receive_routes(s); time(&timenow); if ((timenow - timelast) > interval) { timelast = timenow; if (first_route != NULL) transmit_routes(s); } } }
int main(int argc, char **argv) { int exit_code = EXIT_FAILURE; int i; bool help = false; bool version = false; bool check_config = false; bool daemon = false; const char *debug_filter = NULL; int pid_fd = -1; #ifdef BRICKD_WITH_LIBUDEV bool initialized_udev = false; #endif for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0) { help = true; } else if (strcmp(argv[i], "--version") == 0) { version = true; } else if (strcmp(argv[i], "--check-config") == 0) { check_config = true; } else if (strcmp(argv[i], "--daemon") == 0) { daemon = true; } else if (strcmp(argv[i], "--debug") == 0) { if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) { debug_filter = argv[++i]; } else { debug_filter = ""; } } else { fprintf(stderr, "Unknown option '%s'\n\n", argv[i]); print_usage(); return EXIT_FAILURE; } } if (help) { print_usage(); return EXIT_SUCCESS; } if (version) { printf("%s\n", VERSION_STRING); return EXIT_SUCCESS; } if (prepare_paths() < 0) { return EXIT_FAILURE; } if (check_config) { return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } config_init(_config_filename); if (config_has_error()) { fprintf(stderr, "Error(s) occurred while reading config file '%s'\n", _config_filename); goto error_config; } log_init(); if (daemon) { pid_fd = daemon_start(_log_filename, &_log_file, _pid_filename, true); } else { pid_fd = pid_file_acquire(_pid_filename, getpid()); if (pid_fd == PID_FILE_ALREADY_ACQUIRED) { fprintf(stderr, "Already running according to '%s'\n", _pid_filename); } } if (pid_fd < 0) { goto error_pid_file; } log_info("Brick Daemon %s started (pid: %u, daemonized: %d)", VERSION_STRING, getpid(), daemon ? 1 : 0); if (debug_filter != NULL) { log_enable_debug_override(debug_filter); } if (config_has_warning()) { log_warn("Warning(s) in config file '%s', run with --check-config option for details", _config_filename); } if (event_init() < 0) { goto error_event; } if (signal_init(handle_sighup, handle_sigusr1) < 0) { goto error_signal; } if (hardware_init() < 0) { goto error_hardware; } if (usb_init() < 0) { goto error_usb; } #ifdef BRICKD_WITH_LIBUDEV if (!usb_has_hotplug()) { if (udev_init() < 0) { goto error_udev; } initialized_udev = true; } #endif if (network_init() < 0) { goto error_network; } if (mesh_init() < 0) { goto error_mesh; } #ifdef BRICKD_WITH_RED_BRICK if (gpio_init() < 0) { goto error_gpio; } if (redapid_init() < 0) { goto error_redapid; } if (red_stack_init() < 0) { goto error_red_stack; } if (red_extension_init() < 0) { goto error_red_extension; } if (red_usb_gadget_init() < 0) { goto error_red_usb_gadget; } red_led_set_trigger(RED_LED_GREEN, config_get_option_value("led_trigger.green")->symbol); red_led_set_trigger(RED_LED_RED, config_get_option_value("led_trigger.red")->symbol); #endif if (event_run(network_cleanup_clients_and_zombies) < 0) { goto error_run; } #ifdef BRICKD_WITH_RED_BRICK hardware_announce_disconnect(); network_announce_red_brick_disconnect(); red_usb_gadget_announce_red_brick_disconnect(); #endif exit_code = EXIT_SUCCESS; error_run: #ifdef BRICKD_WITH_RED_BRICK red_usb_gadget_exit(); error_red_usb_gadget: red_extension_exit(); error_red_extension: red_stack_exit(); error_red_stack: redapid_exit(); error_redapid: //gpio_exit(); error_gpio: #endif network_exit(); error_mesh: mesh_exit(); error_network: #ifdef BRICKD_WITH_LIBUDEV if (initialized_udev) { udev_exit(); } error_udev: #endif usb_exit(); error_usb: hardware_exit(); error_hardware: signal_exit(); error_signal: event_exit(); error_event: log_info("Brick Daemon %s stopped", VERSION_STRING); error_pid_file: if (pid_fd >= 0) { pid_file_release(_pid_filename, pid_fd); } log_exit(); error_config: config_exit(); return exit_code; }
int main(int argc, char** argv) { // start the daemon daemon_start(); struct sockaddr_in server_address; int server_socket; bzero(&server_address, sizeof(server_address)); //create unammed socket and name it server_socket = socket(AF_INET, SOCK_STREAM, 0); // create addr struct server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = inet_addr(SERVER_ADDR); server_address.sin_port = htons(PORT); //create, initialize, and set the thread attribute pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_t threads[100]; //binding unnamed socket if (bind(server_socket, (struct sockaddr * )&server_address, sizeof(server_address)) ==-1){ syslog(LOG_NOTICE, "server with PID %d: error binding socket\n", getpid() ); exit(EXIT_FAILURE); } // wait for client connections and put pending connections in queue if(listen(server_socket, NUM_CONNECTION) !=0){ syslog(LOG_NOTICE,"server with PID %d: error listing on socket\n", getpid()); exit(EXIT_FAILURE); } while(1){ int client_socket = accept(server_socket, NULL, NULL); syslog(LOG_NOTICE,"server with PID %d: accepted client\n", getpid()); //create the thread to handel pthread_t threads [1]; // Launch threads for(int i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) { if(pthread_create(&threads[i], NULL,handel_client,(void*)&client_socket)!= 0) { syslog(LOG_NOTICE,"server with PID %d: error creating the thread\n", getpid()); exit(EXIT_FAILURE); } } // Wait for threads to finish for(int i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) { if(pthread_join(threads[i],NULL) != 0) { perror("Thread join failed"); exit(EXIT_FAILURE); } } // Release the mutex if(pthread_mutex_destroy(&mutex) != 0) { perror("Destroy mutex"); exit(EXIT_FAILURE); } } }
int main(int argc, char **argv) { int exit_code = EXIT_FAILURE; int i; bool help = false; bool version = false; bool check_config = false; bool daemon = false; bool debug = false; bool libusb_debug = false; int pid_fd = -1; #ifdef BRICKD_WITH_LIBUDEV bool initialized_udev = false; #endif for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0) { help = true; } else if (strcmp(argv[i], "--version") == 0) { version = true; } else if (strcmp(argv[i], "--check-config") == 0) { check_config = true; } else if (strcmp(argv[i], "--daemon") == 0) { daemon = true; } else if (strcmp(argv[i], "--debug") == 0) { debug = true; } else if (strcmp(argv[i], "--libusb-debug") == 0) { libusb_debug = true; } else { fprintf(stderr, "Unknown option '%s'\n\n", argv[i]); print_usage(); return EXIT_FAILURE; } } if (help) { print_usage(); return EXIT_SUCCESS; } if (version) { printf("%s\n", VERSION_STRING); return EXIT_SUCCESS; } if (prepare_paths() < 0) { return EXIT_FAILURE; } if (check_config) { return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } config_init(_config_filename); log_init(); if (daemon) { pid_fd = daemon_start(_log_filename, _pid_filename, true); } else { pid_fd = pid_file_acquire(_pid_filename, getpid()); if (pid_fd == PID_FILE_ALREADY_ACQUIRED) { fprintf(stderr, "Already running according to '%s'\n", _pid_filename); } } if (pid_fd < 0) { goto error_log; } log_set_debug_override(debug); log_set_level(LOG_CATEGORY_EVENT, config_get_option("log_level.event")->value.log_level); log_set_level(LOG_CATEGORY_USB, config_get_option("log_level.usb")->value.log_level); log_set_level(LOG_CATEGORY_NETWORK, config_get_option("log_level.network")->value.log_level); log_set_level(LOG_CATEGORY_HOTPLUG, config_get_option("log_level.hotplug")->value.log_level); log_set_level(LOG_CATEGORY_HARDWARE, config_get_option("log_level.hardware")->value.log_level); log_set_level(LOG_CATEGORY_WEBSOCKET, config_get_option("log_level.websocket")->value.log_level); #ifdef BRICKD_WITH_RED_BRICK log_set_level(LOG_CATEGORY_RED_BRICK, config_get_option("log_level.red_brick")->value.log_level); log_set_level(LOG_CATEGORY_SPI, config_get_option("log_level.spi")->value.log_level); log_set_level(LOG_CATEGORY_RS485, config_get_option("log_level.rs485")->value.log_level); #endif log_set_level(LOG_CATEGORY_OTHER, config_get_option("log_level.other")->value.log_level); if (config_has_error()) { log_error("Error(s) in config file '%s', run with --check-config option for details", _config_filename); goto error_config; } if (daemon) { log_info("Brick Daemon %s started (daemonized)", VERSION_STRING); } else { log_info("Brick Daemon %s started", VERSION_STRING); } if (config_has_warning()) { log_error("Warning(s) in config file '%s', run with --check-config option for details", _config_filename); } if (event_init() < 0) { goto error_event; } if (signal_init(handle_sigusr1) < 0) { goto error_signal; } if (hardware_init() < 0) { goto error_hardware; } if (usb_init(libusb_debug) < 0) { goto error_usb; } #ifdef BRICKD_WITH_LIBUDEV if (!usb_has_hotplug()) { if (udev_init() < 0) { goto error_udev; } initialized_udev = true; } #endif if (network_init() < 0) { goto error_network; } #ifdef BRICKD_WITH_RED_BRICK if (gpio_init() < 0) { goto error_gpio; } if (red_usb_gadget_init() < 0) { goto error_red_usb_gadget; } if (redapid_init() < 0) { goto error_redapid; } if (red_stack_init() < 0) { goto error_red_stack; } if (rs485_extension_init() < 0) { goto error_rs485_extension; } #endif if (event_run(network_cleanup_clients_and_zombies) < 0) { goto error_run; } exit_code = EXIT_SUCCESS; error_run: #ifdef BRICKD_WITH_RED_BRICK rs485_extension_exit(); error_rs485_extension: red_stack_exit(); error_red_stack: redapid_exit(); error_redapid: red_usb_gadget_exit(); error_red_usb_gadget: //gpio_exit(); error_gpio: #endif network_exit(); error_network: #ifdef BRICKD_WITH_LIBUDEV if (initialized_udev) { udev_exit(); } error_udev: #endif usb_exit(); error_usb: hardware_exit(); error_hardware: signal_exit(); error_signal: event_exit(); error_event: log_info("Brick Daemon %s stopped", VERSION_STRING); error_config: error_log: log_exit(); if (pid_fd >= 0) { pid_file_release(_pid_filename, pid_fd); } config_exit(); return exit_code; }
int main(int argc, char* argv[]) { pid_t pid; parse_args(argc, argv); if (config_init(argv[1]) == -1) { BOOT_LOG(-1, "Failed to Parse File '%s'", argv[1]); } if (config_init("common.conf") == -1) { BOOT_LOG(-1, "Failed to Parse File '%s'", argv[1]); } daemon_start(argc, argv); load_bind_file(); log_init_ex( config_get_strval("log_dir"), config_get_intval("log_level", log_lvl_trace), config_get_intval("log_size", 1<<30), config_get_intval("max_log_files", 0), config_get_strval("log_prefix") , config_get_intval("log_save_next_file_interval_min", 0) ); //Èç¹ûʹÓÃÔà´Ê¼ì²âÂß¼£¬Ôò¿ªÆô¸¸½ø³ÌµÄÔà´Ê¸üÐÂÂß¼. if (config_get_intval("tm_dirty_use_dirty_logical", 1) == 1) { if (tm_dirty_daemon( config_get_strval("tm_dirty_local_dirty_file_path"), config_get_strval("tm_dirty_server_addr"), config_get_intval("tm_dirty_update_cycle", 600), NULL) == -1) { BOOT_LOG(-1, "FAILED TO RUN TM_DIRTY_DAEMON"); } } net_init(MAXFDS, MAXFDS); bind_config_t* bc = get_bind_conf(); //-------------------------------- net_start(config_get_strval("online_ip"), config_get_intval("online_port", 443), bc->configs); //-------------------------------- // bind_config_elem_t* bc_elem; int i = 0; for ( ; i != bc->bind_num; ++i ) { bind_config_elem_t* bc_elem = &(bc->configs[i]); shmq_create(bc_elem); if ( (pid = fork ()) < 0 ) { BOOT_LOG(-1, "fork child process"); } else if (pid > 0) { //parent process close_shmq_pipe(bc, i, 0); do_add_conn(bc_elem->sendq.pipe_handles[0], PIPE_TYPE_FD, 0, bc_elem); //net_start(bc_elem->bind_ip, bc_elem->bind_port, bc_elem); } else { //child process run_worker_process(bc, i, i + 1); } } while (!stop) { net_loop(-1, PAGESIZE, 1); } net_exit(); shmq_destroy(0, bc->bind_num); daemon_stop(); return 0; }
int main(int argc, char **argv) { int exit_code = EXIT_FAILURE; int i; bool help = false; bool version = false; bool check_config = false; bool daemon = false; const char *debug_filter = NULL; int pid_fd = -1; for (i = 1; i < argc; ++i) { if (strcmp(argv[i], "--help") == 0) { help = true; } else if (strcmp(argv[i], "--version") == 0) { version = true; } else if (strcmp(argv[i], "--check-config") == 0) { check_config = true; } else if (strcmp(argv[i], "--daemon") == 0) { daemon = true; } else if (strcmp(argv[i], "--debug") == 0) { if (i + 1 < argc && strncmp(argv[i + 1], "--", 2) != 0) { debug_filter = argv[++i]; } else { debug_filter = ""; } } else { fprintf(stderr, "Unknown option '%s'\n\n", argv[i]); print_usage(); return EXIT_FAILURE; } } if (help) { print_usage(); return EXIT_SUCCESS; } if (version) { printf("%s\n", VERSION_STRING); return EXIT_SUCCESS; } read_image_version(); _x11_enabled = access("/etc/tf_x11_enabled", F_OK) == 0; if (prepare_paths() < 0) { return EXIT_FAILURE; } if (check_config) { return config_check(_config_filename) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } config_init(_config_filename); if (config_has_error()) { fprintf(stderr, "Error(s) occurred while reading config file '%s'", _config_filename); goto error_config; } log_init(); if (daemon) { pid_fd = daemon_start(_log_filename, _pid_filename, 1); } else { pid_fd = pid_file_acquire(_pid_filename, getpid()); if (pid_fd == PID_FILE_ALREADY_ACQUIRED) { fprintf(stderr, "Already running according to '%s'\n", _pid_filename); } } if (pid_fd < 0) { goto error_pid_file; } if (daemon && _x11_enabled) { log_info("RED Brick API Daemon %s started (daemonized, X11 enabled) on %s image", VERSION_STRING, _image_version); } else if (daemon) { log_info("RED Brick API Daemon %s started (daemonized) on %s image", VERSION_STRING, _image_version); } else if (_x11_enabled) { log_info("RED Brick API Daemon %s started (X11 enabled) on %s image", VERSION_STRING, _image_version); } else { log_info("RED Brick API Daemon %s started on %s image", VERSION_STRING, _image_version); } if (debug_filter != NULL) { log_enable_debug_override(debug_filter); } if (config_has_warning()) { log_warn("Warning(s) in config file '%s', run with --check-config option for details", _config_filename); } if (event_init() < 0) { goto error_event; } if (signal_init(handle_sighup, NULL) < 0) { goto error_signal; } if (process_monitor_init() < 0) { goto error_process_monitor; } if (cron_init() < 0) { goto error_cron; } if (inventory_init() < 0) { goto error_inventory; } if (api_init() < 0) { goto error_api; } if (network_init(_brickd_socket_filename, _cron_socket_filename) < 0) { goto error_network; } if (inventory_load_programs() < 0) { goto error_load_programs; } if (event_run(network_cleanup_brickd_and_socats) < 0) { goto error_run; } exit_code = EXIT_SUCCESS; error_run: inventory_unload_programs(); error_load_programs: network_exit(); error_network: api_exit(); error_api: inventory_exit(); error_inventory: cron_exit(); error_cron: process_monitor_exit(); error_process_monitor: signal_exit(); error_signal: event_exit(); error_event: log_info("RED Brick API Daemon %s stopped", VERSION_STRING); error_pid_file: if (pid_fd >= 0) { pid_file_release(_pid_filename, pid_fd); } log_exit(); error_config: config_exit(); return exit_code; }
int main (int argc, char *argv[]) { int ch; bool no_signals = false; bool test_config = false; pthread_t thid; char *uid = NULL; char *gid = NULL; start_heap = sbrk(0); setlocale(LC_ALL, ""); bindtextdomain("bareos", LOCALEDIR); textdomain("bareos"); init_stack_dump(); my_name_is(argc, argv, "bareos-sd"); init_msg(NULL, NULL); daemon_start_time = time(NULL); /* Sanity checks */ if (TAPE_BSIZE % B_DEV_BSIZE != 0 || TAPE_BSIZE / B_DEV_BSIZE == 0) { Emsg2(M_ABORT, 0, _("Tape block size (%d) not multiple of system size (%d)\n"), TAPE_BSIZE, B_DEV_BSIZE); } if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) { Emsg1(M_ABORT, 0, _("Tape block size (%d) is not a power of 2\n"), TAPE_BSIZE); } while ((ch = getopt(argc, argv, "c:d:fg:mpstu:v?")) != -1) { switch (ch) { case 'c': /* configuration file */ if (configfile != NULL) { free(configfile); } configfile = bstrdup(optarg); break; case 'd': /* debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'f': /* run in foreground */ foreground = true; break; case 'g': /* set group id */ gid = optarg; break; case 'm': /* print kaboom output */ prt_kaboom = true; break; case 'p': /* proceed in spite of I/O errors */ forge_on = true; break; case 's': /* no signals */ no_signals = true; break; case 't': test_config = true; break; case 'u': /* set uid */ uid = optarg; break; case 'v': /* verbose */ verbose++; break; case '?': default: usage(); break; } } argc -= optind; argv += optind; if (argc) { if (configfile != NULL) { free(configfile); } configfile = bstrdup(*argv); argc--; argv++; } if (argc) usage(); /* * See if we want to drop privs. */ if (geteuid() == 0) { drop(uid, gid, false); } if (!no_signals) { init_signals(terminate_stored); } if (configfile == NULL) { configfile = bstrdup(CONFIG_FILE); } my_config = new_config_parser(); parse_sd_config(my_config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); } if (!check_resources()) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); } init_reservations_lock(); if (test_config) { terminate_stored(0); } my_name_is(0, (char **)NULL, me->hdr.name); /* Set our real name */ if (!foreground) { daemon_start(); /* become daemon */ init_stack_dump(); /* pick up new pid */ } create_pid_file(me->pid_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); read_state_file(me->working_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); read_crypto_cache(me->working_directory, "bareos-sd", get_first_port_host_order(me->SDaddrs)); set_jcr_in_tsd(INVALID_JCR); /* * Make sure on Solaris we can run concurrent, watch dog + servers + misc */ set_thread_concurrency(me->max_concurrent_jobs * 2 + 4); lmgr_init_thread(); /* initialize the lockmanager stack */ load_sd_plugins(me->plugin_directory, me->plugin_names); cleanup_old_files(); /* Ensure that Volume Session Time and Id are both * set and are both non-zero. */ VolSessionTime = (uint32_t)daemon_start_time; if (VolSessionTime == 0) { /* paranoid */ Jmsg0(NULL, M_ABORT, 0, _("Volume Session Time is ZERO!\n")); } /* * Start the device allocation thread */ create_volume_lists(); /* do before device_init */ if (pthread_create(&thid, NULL, device_initialization, NULL) != 0) { berrno be; Emsg1(M_ABORT, 0, _("Unable to create thread. ERR=%s\n"), be.bstrerror()); } start_watchdog(); /* start watchdog thread */ if (me->jcr_watchdog_time) { init_jcr_subsystem(me->jcr_watchdog_time); /* start JCR watchdogs etc. */ } #if HAVE_NDMP /* Seperate thread that handles NDMP connections */ if (me->ndmp_enable) { start_ndmp_thread_server(me->NDMPaddrs, me->max_concurrent_jobs * 2 + 1, &ndmp_workq); } #endif /* Single server used for Director/Storage and File daemon */ sock_fds = New(alist(10, not_owned_by_alist)); bnet_thread_server_tcp(me->SDaddrs, me->max_concurrent_jobs * 2 + 1, sock_fds, &dird_workq, me->nokeepalive, handle_connection_request); exit(1); /* to keep compiler quiet */ }
int main(int argc, char **argv) { if(parse_args(argc, argv)) return 0; int err = 0; printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime()); if(myconfig_init(argc, argv) < 0) { printf("myconfig_init fail %m\n"); goto error; } daemon_start(argc, argv); umask(0); ICALL(start_watchdog); ICALL(init_log); ICALL(init_glog); ICALL(init_fdinfo); ICALL(delay_task_init); ICALL(init_thread); ICALL(init_global); ICALL(vfs_init); ICALL(init_task_info); if (g_config.voss_flag == 0) { t_thread_arg arg; memset(&arg, 0, sizeof(arg)); snprintf(arg.name, sizeof(arg.name), "./ott_server.so"); LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name); arg.port = 80; arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096); if (init_vfs_thread(&arg)) goto error; t_thread_arg arg1; memset(&arg1, 0, sizeof(arg1)); snprintf(arg1.name, sizeof(arg1.name), "./ott_client.so"); LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name); arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096); if (init_vfs_thread(&arg1)) goto error; ICALL(init_vfs_agent); } else { t_thread_arg arg; memset(&arg, 0, sizeof(arg)); snprintf(arg.name, sizeof(arg.name), "./ott_voss.so"); LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name); arg.port = g_config.sig_port; arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096); if (init_vfs_thread(&arg)) goto error; } thread_jumbo_title(); struct threadstat *thst = get_threadstat(); if(start_threads() < 0) goto out; thread_reached(thst); gen_pidfile(); printf("Server Started\n"); vfs_start_time = time(NULL); main_loop(thst); out: printf("Stopping Server %s (%s)...\n", version_string, compiling_date); thread_reached(thst); stop_threads(); myconfig_cleanup(); fini_fdinfo(); printf("Server Stopped.\n"); return restart; error: if(err == -ENOMEM) printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n"); printf("\033[31m\033[1mStart Fail.\033[0m\n"); return -1; }