void parse_config() { FILE *f = NULL; fprintf(stderr,"Reading configuration file: \"%s\" ...\n",config_path); if( (f=fopen (config_path, "r")) == NULL ) { perror("fopen"); exit(1); } LIBXML_TEST_VERSION; /* create a parser context */ ctxt = xmlNewParserCtxt(); if (ctxt == NULL) { fprintf(stderr, "Failed to allocate parser context\n"); fclose(f); return; } /* parse the file, activating the DTD validation option */ doc = xmlCtxtReadFile(ctxt, config_path, NULL, XML_PARSE_DTDVALID); /* check if parsing suceeded */ if (doc == NULL) { fprintf(stderr, "Failed to parse %s\n", config_path); } else { /* check if validation suceeded */ if (ctxt->valid == 0) fprintf(stderr, "Failed to validate %s\n", config_path); /* free up the resulting document */ else { xmlXPathInit(); xpctxt= xmlXPathNewContext(doc); } } autoconf(); get_mail(); init_syslog(); parse_routers(); parse_actions(); #ifdef _COUNTERMEASURES_ parse_countermeasures(); #endif free_xml(); fclose(f); fprintf(stderr," Done.\n"); }
int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); init_syslog(); uopt_init(); if (fuse_opt_parse(&args, NULL, unionfs_opts, unionfs_opt_proc) == -1) RETURN(1); if (uopt.debug) debug_init(); if (!uopt.doexit) { if (uopt.nbranches == 0) { printf("You need to specify at least one branch!\n"); RETURN(1); } if (uopt.stats_enabled) stats_init(&stats); } // enable fuse permission checks, we need to set this, even we we are // not root, since we don't have our own access() function int uid = getuid(); int gid = getgid(); bool default_permissions = true; if (uid != 0 && gid != 0 && uopt.relaxed_permissions) { default_permissions = false; } else if (uopt.relaxed_permissions) { // protec the user of a very critical security issue fprintf(stderr, "Relaxed permissions disallowed for root!\n"); exit(1); } if (default_permissions) { if (fuse_opt_add_arg(&args, "-odefault_permissions")) { fprintf(stderr, "Severe failure, can't enable permssion checks, aborting!\n"); exit(1); } } unionfs_post_opts(); #ifdef FUSE_CAP_BIG_WRITES /* libfuse > 0.8 supports large IO, also for reads, to increase performance * We support any IO sizes, so lets enable that option */ if (fuse_opt_add_arg(&args, "-obig_writes")) { fprintf(stderr, "Failed to enable big writes!\n"); exit(1); } #endif umask(0); int res = fuse_main(args.argc, args.argv, &unionfs_oper, NULL); RETURN(uopt.doexit ? uopt.retval : res); }
void start_builtin(plugin_conf_t *conf) { if (strcasecmp("builtin_af_unix", conf->path) == 0) { conf->type = S_AF_UNIX; init_af_unix(conf); } else if (strcasecmp("builtin_syslog", conf->path) == 0) { conf->type = S_SYSLOG; init_syslog(conf); } else syslog(LOG_ERR, "Unknown builtin %s", conf->path); }
/// <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(); }
static void write_syslog(const char *pfx, const char *msg) { int prio = LOG_WARNING; if (!syslog_started) init_syslog(); switch (pfx[0]) { case 'F': prio = LOG_CRIT; break; case 'E': prio = LOG_ERR; break; case 'W': prio = LOG_WARNING; break; case 'I': prio = LOG_INFO; break; case 'L': prio = LOG_INFO; break; case 'D': prio = LOG_DEBUG; break; case 'N': prio = LOG_DEBUG; break; } syslog(prio, "%s", msg); }
int main(){ /*********** data service module ************/ init_syslog(); //char ss[18]={51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68}; //Print_hex(ss,18); XGSetLogOutCallback(xg_printf); Info("***********************FOTILE IKCC START***************************"); Info("***********************FOTILE IKCC START***************************"); Info("***********************FOTILE IKCC START***************************"); #if 0 ds_init(); /*********** hardware service module ************/ hw_init(); /*********** message transfer ************/ msg_transfer_init(); /*********** net socket ************/ ikcc_init_net_server(8888); /*********** native socket ************/ ikcc_init_native_socket("/tmp/native_socket"); /*********** lua script ************/ #endif #ifdef LUA_SCRIPT ikcc_init_ssid_tcp_server(23576); //lua_init_lua(); //此功能会加载lua cjson库 需要安装到板子上 //cjson_test(); #endif /* LUA_SCRIPT */ ft_xlink_gateway_init(); /***********console command************/ //init_console(); //此接口会阻塞 while(1) { sleep(10); } Info("core over!"); }
int rarpd(int argc, char *argv[]) { struct rarpd rarpd; rarpd_init(&rarpd); if (parse_options(&rarpd, argc, argv) != 0) { return EXIT_FAILURE; } if (parse_args(&rarpd, argv) != 0) { return EXIT_FAILURE; } if (!(rarpd.opts & FOREGROUND) && daemonize() != 0) { return EXIT_FAILURE; } init_syslog(&rarpd); if (rarpd_init_signals(&rarpd) != 0) { return EXIT_FAILURE; } if (find_interfaces(&rarpd) != 0) { return EXIT_FAILURE; } link_array_filter(&rarpd.links, has_addr, NULL); if (rarpd.links.count == 0) { XLOG_ERR("no usable links found"); return EXIT_FAILURE; } if (!link_array_foreach(&rarpd.links, setup_link, &rarpd.dispatcher)) { cleanup_rarpd(&rarpd); return EXIT_FAILURE; } dispatcher_run(&rarpd.dispatcher); cleanup_rarpd(&rarpd); return EXIT_SUCCESS; }
int main(int argc, char **argv) { #define PORTSZ 32 char portname[PORTSZ]; max_fd = 0; /* No disk files on remote machine */ _fb_disk_enable = 0; memset((void *)clients, 0, sizeof(struct pkg_conn *) * MAX_CLIENTS); #ifdef SIGALRM (void)signal( SIGPIPE, SIG_IGN ); (void)signal( SIGALRM, sigalarm ); #endif /*alarm(1)*/ FD_ZERO(&select_list); fb_server_select_list = &select_list; fb_server_max_fd = &max_fd; #ifndef _WIN32 /* * Inetd Daemon. * Check to see if we were invoked by /etc/inetd. If so * we will have an open network socket on fd=0. Become * a Transient PKG server if this is so. */ netfd = 0; if ( is_socket(netfd) ) { init_syslog(); new_client( pkg_transerver( fb_server_pkg_switch, comm_error ) ); max_fd = 8; once_only = 1; main_loop(); return 0; } #endif /* for now, make them set a port_num, for usage message */ if ( !get_args( argc, argv ) || !port_set ) { (void)fputs(usage, stderr); return 1; } /* Single-Frame-Buffer Server */ if ( framebuffer != NULL ) { fb_server_retain_on_close = 1; /* don't ever close the frame buffer */ /* open a frame buffer */ if ( (fb_server_fbp = fb_open(framebuffer, width, height)) == FB_NULL ) bu_exit(1, NULL); max_fd = fb_set_fd(fb_server_fbp, &select_list); /* check/default port */ if ( port_set ) { if ( port < 1024 ) port += 5559; } snprintf(portname, PORTSZ, "%d", port); /* * Hang an unending listen for PKG connections */ if ( (netfd = pkg_permserver(portname, 0, 0, comm_error)) < 0 ) bu_exit(-1, NULL); FD_SET(netfd, &select_list); V_MAX(max_fd, netfd); main_loop(); return 0; } #ifndef _WIN32 /* * Stand-Alone Daemon */ /* check/default port */ if ( port_set ) { if ( port < 1024 ) port += 5559; sprintf(portname, "%d", port); } else { snprintf(portname, PORTSZ, "%s", "remotefb"); } init_syslog(); while ( (netfd = pkg_permserver(portname, 0, 0, comm_error)) < 0 ) { static int error_count=0; sleep(1); if (error_count++ < 60) { continue; } comm_error("Unable to start the stand-alone framebuffer daemon after 60 seconds, giving up."); return 1; } while (1) { int fbstat; struct pkg_conn *pcp; pcp = pkg_getclient( netfd, fb_server_pkg_switch, comm_error, 0 ); if ( pcp == PKC_ERROR ) break; /* continue is unlikely to work */ if ( fork() == 0 ) { /* 1st level child process */ (void)close(netfd); /* Child is not listener */ /* Create 2nd level child process, "double detach" */ if ( fork() == 0 ) { /* 2nd level child -- start work! */ new_client( pcp ); once_only = 1; main_loop(); return 0; } else { /* 1st level child -- vanish */ return 1; } } else { /* Parent: lingering server daemon */ pkg_close(pcp); /* Daemon is not the server */ /* Collect status from 1st level child */ (void)wait( &fbstat ); } } #endif /* _WIN32 */ return 2; }
int main(int argc, char *argv[]) { unsigned long sleep_time; double read_interval; start_time = time(0); parse_args_pre(argc, argv); configfile_read(); parse_args_post(argc, argv); conf_init(); module_init(); read_interval = cfg_read_interval; sleep_time = cfg_getint(cfg, "sleep_time"); if (((double) sleep_time / 1000000.0f) > read_interval) sleep_time = (unsigned long) (read_interval * 1000000.0f); // pipe_start(); if (cfg_getbool(cfg, "daemon")) { init_syslog(); daemonize(); write_pidfile(); } drop_privs(); do { /* * E := Elapsed time * NR := Next Read * LR := Last Read * RI := Read Interval * ST := Sleep Time * C := Correction */ timestamp_t e, ri, tmp; unsigned long st; float_to_timestamp(&ri, read_interval); /* * NR := NOW */ update_timestamp(&rtiming.rt_next_read); for (;;) { output_pre(); /* * read the chucka chucka pipe */ // pipe_handle(); /* * E := NOW */ update_timestamp(&e); /* * IF NR <= E THEN */ if (timestamp_le(&rtiming.rt_next_read, &e)) { timestamp_t c; /* * C := (NR - E) */ timestamp_sub(&c, &rtiming.rt_next_read, &e); //calc_variance(&c, &ri); /* * LR := E */ copy_timestamp(&rtiming.rt_last_read, &e); /* * NR := E + RI + C */ timestamp_add(&rtiming.rt_next_read, &e, &ri); timestamp_add(&rtiming.rt_next_read, &rtiming.rt_next_read, &c); reset_update_flags(); input_read(); free_unused_elements(); output_draw(); output_post(); } if (do_quit) exit(0); /* * ST := Configured ST */ st = sleep_time; /* * IF (NR - E) < ST THEN */ timestamp_sub(&tmp, &rtiming.rt_next_read, &e); if (tmp.tv_sec < 0) continue; if (tmp.tv_sec == 0 && tmp.tv_usec < st) { if (tmp.tv_usec < 0) continue; /* * ST := (NR - E) */ st = tmp.tv_usec; } /* * SLEEP(ST) */ usleep(st); } } while (0); return 0; /* buddha says i'll never be reached */ }