void sighup_run(void) { sighup_flag = 0; time(¤t_time); log_error_time(); fputs("caught SIGHUP, restarting\n", stderr); /* Philosophy change for 0.92: don't close and attempt reopen of logfiles, * since usual permission structure prevents such reopening. */ /* why ? */ /* FD_ZERO(&block_read_fdset); FD_ZERO(&block_write_fdset); */ /* clear_common_env(); NEVER DO THIS */ dump_mime(); dump_passwd(); dump_alias(); free_requests(); range_pool_empty(); log_error_time(); fputs("re-reading configuration files\n", stderr); read_config_files(); log_error_time(); fputs("successful restart\n", stderr); }
RuntimeConfigImpl() : m_profile_name { "default" } { // read pre-init config set to get config file name from env var ConfigSetImpl pre_init_config; pre_init_config.init("config", s_configdata, map<string, string>()); // read config files read_config_files(pre_init_config.get("file").to_string()); }
void read_premib_configs (void) { DEBUGMSGTL(("read_config","reading premib configuration tokens\n")); if (!ds_get_boolean(DS_LIBRARY_ID, DS_LIB_DONT_READ_CONFIGS)) read_config_files(PREMIB_CONFIG); snmp_call_callbacks(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_POST_PREMIB_READ_CONFIG, NULL); }
int main(int argc, char **argv) { char *paths[] = { NULL, NULL }; int i; pthread_t u_tid; cmdname = argv[0]; for (i = 1; i < argc && *argv[i] == '-'; i++) { if (streq(argv[i], "-h")) { usage(); } } paths[0] = (argc > i) ? argv[i] : "."; paths[1] = (argc > (i + 1)) ? argv[i + 1] : paths[0]; atexit(atexit_handler); if (!setlocale(LC_CTYPE, "")) die("couldn't set locale\n"); config_init(); program_init(); read_config_files(); /* setup windows */ for (i = 0; i < 2; i++) { data.win[i] = dwindow_create(); dwindow_set_sort(data.win[i], config()->sort); dwindow_read(data.win[i], paths[i]); } data.wsel = data.win[0]; /* setup ui */ ui_init(); theme_init(); /* set default state */ states_push(list_state()); /* start update thread */ pthread_mutex_init(&data.mutex, NULL); if (pthread_create(&u_tid, NULL, update_loop, &data) != 0) die("pthread_create: %s\n", strerror(errno)); main_loop(); ui_close(); return 0; }
void read_configs (void) { char *optional_config = ds_get_string(DS_LIBRARY_ID, DS_LIB_OPTIONALCONFIG); char *type = ds_get_string(DS_LIBRARY_ID, DS_LIB_APPTYPE); DEBUGMSGTL(("read_config","reading normal configuration tokens\n")); if (!ds_get_boolean(DS_LIBRARY_ID, DS_LIB_DONT_READ_CONFIGS)) read_config_files(NORMAL_CONFIG); /* do this even when the normal above wasn't done */ if (optional_config && type) read_config_with_type(optional_config, type); snmp_call_callbacks(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_POST_READ_CONFIG, NULL); }
void merge_argv_with_cfgfile(int *argc, char ***argv, struct ga_option *options, int nopts) { struct cfg_option *cfg_file_options; if ((cfg_file_options = read_config_files()) != NULL) { /* * There are config files that need to be integrated into * the command line */ char **tmpargv; int tmpargc = *argc; tmpargv = make_new_argv(*argv, &tmpargc, cfg_file_options, options, nopts); if (tmpargv != NULL) { *argv = tmpargv; *argc = tmpargc; } } }
int main(int argc, char **argv) { int c; int server_s; c = umask(~0600); if (c == -1) { perror("umask"); exit(1); } devnullfd = open("/dev/null", 0); if (devnullfd == -1) { DIE("can't open /dev/null"); } if (dup2(devnullfd, STDIN_FILENO) == -1) { DIE("can't dup2 /dev/null to STDIN_FILENO"); } if (dup2(devnullfd, STDOUT_FILENO) == -1) { DIE("can't dup2 /dev/null to STDOUT_FILENO"); } (void) time(¤t_time); while ((c = getopt(argc, argv, "c:r:d")) != -1) { switch (c) { case 'c': if (server_root) free(server_root); server_root = strdup(optarg); if (!server_root) { perror("strdup (for server_root)"); exit(1); } break; case 'r': if (chdir(optarg) == -1) { log_error_time(); perror("chdir (to chroot)"); exit(1); } if (chroot(optarg) == -1) { log_error_time(); perror("chroot"); exit(1); } if (chdir("/") == -1) { log_error_time(); perror("chdir (after chroot)"); exit(1); } break; case 'd': do_fork = 0; break; default: fprintf(stderr, "Usage: %s [-c serverroot] [-r chroot] [-d]\n", argv[0]); exit(1); } } fixup_server_root(); read_config_files(); open_logs(); server_s = create_server_socket(); boa_event_base = create_event_base(server_s); init_signals(); drop_privs(); create_common_env(); build_needs_escape(); if (max_connections < 1) { struct rlimit rl; c = getrlimit(RLIMIT_NOFILE, &rl); if (c < 0) { perror("getrlimit"); exit(1); } max_connections = rl.rlim_cur; } if (do_fork) { switch(fork()) { case -1: perror("fork"); exit(1); break; case 0: break; default: exit(0); break; } } timestamp(); status.requests = 0; status.errors = 0; start_time = current_time; select_loop(server_s); return 0; }
int main(int argc, char **argv) { int c; /* command line arg */ int server_s; /* boa socket */ /* set umask to u+rw, u-x, go-rwx */ c = umask(~0600); if (c == -1) { perror("umask"); exit(1); } devnullfd = open("/dev/null", 0); /* make STDIN and STDOUT point to /dev/null */ if (devnullfd == -1) { DIE("can't open /dev/null"); } #if 0 if (dup2(devnullfd, STDIN_FILENO) == -1) { DIE("can't dup2 /dev/null to STDIN_FILENO"); } if (dup2(devnullfd, STDOUT_FILENO) == -1) { DIE("can't dup2 /dev/null to STDOUT_FILENO"); } #endif /* but first, update timestamp, because log_error_time uses it */ (void) time(¤t_time); while ((c = getopt(argc, argv, "c:r:d")) != -1) { switch (c) { case 'c': if (server_root) free(server_root); server_root = strdup(optarg); if (!server_root) { perror("strdup (for server_root)"); exit(1); } break; case 'r': if (chdir(optarg) == -1) { log_error_time(); perror("chdir (to chroot)"); exit(1); } if (chroot(optarg) == -1) { log_error_time(); perror("chroot"); exit(1); } if (chdir("/") == -1) { log_error_time(); perror("chdir (after chroot)"); exit(1); } break; case 'd': do_fork = 1; break; default: fprintf(stderr, "Usage: %s [-c serverroot] [-r chroot] [-d] [-b] [-q bitrate]\n", argv[0]); exit(1); } } #ifdef DAVINCI_IPCAM if(ApproDrvInit(BOA_MSG_TYPE) < 0){ exit(1); } //printf("func_get_mem Begin\n"); if (func_get_mem(NULL)) { ApproDrvExit(); exit(1); } //printf("SysDrvInit Begin\n"); if(SysDrvInit(SYS_BOA_MSG) < 0){ ApproDrvExit(); exit(1); } //printf("InitFileMsgDrv Begin\n"); if (InitFileMsgDrv(FILE_MSG_KEY, FILE_BOA_MSG) < 0) { ApproDrvExit(); SysDrvExit(); exit(1); } //printf("hash_table_init Begin\n"); if (hash_table_init() < 0) { exit(1); } //printf("arg_hash_table_init Begin\n"); if(arg_hash_table_init() < 0) { exit(1); } //printf("uri_hash_table_init Begin\n"); if(uri_hash_table_init() < 0) { exit(1); } #endif #ifdef PSIA_MEDIA //printf("psia_uri_hash_table_init Begin\n"); if(psia_uri_hash_table_init() < 0) { exit(1); } #endif //printf("fixup_server_root Begin\n"); fixup_server_root(); printf("read_config_files Begin\n"); read_config_files(); #ifdef DAVINCI_IPCAM { //printf("ControlSystemData Begin\n"); unsigned short value; #if 1 if (ControlSystemData(SFIELD_GET_HTTPPORT, (void *)&value, sizeof(value)) >= 0) server_port = value; #endif dbg("server_port=%d\n", server_port); } #endif open_logs(); server_s = create_server_socket(); init_signals(); drop_privs(); create_common_env(); build_needs_escape(); if (max_connections < 1) { struct rlimit rl; /* has not been set explicitly */ c = getrlimit(RLIMIT_NOFILE, &rl); if (c < 0) { perror("getrlimit"); exit(1); } max_connections = rl.rlim_cur; } /* background ourself */ if (do_fork) { switch(fork()) { case -1: /* error */ perror("fork"); exit(1); break; case 0: /* child, success */ break; default: /* parent, success */ exit(0); break; } } /* Ask system server to start upnp */ //system("/opt/dvr/boot_proc 2\n");//add by sxh upnp /* main loop */ timestamp(); status.requests = 0; status.errors = 0; start_time = current_time; select_loop(server_s); return 0; }
int main(int argc, char **argv) { int c; /* command line arg */ int server_s; /* boa socket */ /* set umask to u+rw, u-x, go-rwx */ c = umask(~0600); if (c == -1) { perror("umask"); exit(1); } devnullfd = open("/dev/null", 0); /* make STDIN and STDOUT point to /dev/null */ if (devnullfd == -1) { DIE("can't open /dev/null"); } if (dup2(devnullfd, STDIN_FILENO) == -1) { DIE("can't dup2 /dev/null to STDIN_FILENO"); } if (dup2(devnullfd, STDOUT_FILENO) == -1) { DIE("can't dup2 /dev/null to STDOUT_FILENO"); } /* but first, update timestamp, because log_error_time uses it */ (void) time(¤t_time); while ((c = getopt(argc, argv, "c:r:d")) != -1) { switch (c) { case 'c': if (server_root) free(server_root); server_root = strdup(optarg); if (!server_root) { perror("strdup (for server_root)"); exit(1); } break; case 'r': if (chdir(optarg) == -1) { log_error_time(); perror("chdir (to chroot)"); exit(1); } if (chroot(optarg) == -1) { log_error_time(); perror("chroot"); exit(1); } if (chdir("/") == -1) { log_error_time(); perror("chdir (after chroot)"); exit(1); } break; case 'd': do_fork = 0; break; default: fprintf(stderr, "Usage: %s [-c serverroot] [-r chroot] [-d]\n", argv[0]); exit(1); } } fixup_server_root(); read_config_files(); open_logs(); server_s = create_server_socket(); init_signals(); drop_privs(); create_common_env(); build_needs_escape(); if (max_connections < 1) { struct rlimit rl; /* has not been set explicitly */ c = getrlimit(RLIMIT_NOFILE, &rl); if (c < 0) { perror("getrlimit"); exit(1); } max_connections = rl.rlim_cur; } /* background ourself */ if (do_fork) { switch(fork()) { case -1: /* error */ perror("fork"); exit(1); break; case 0: /* child, success */ break; default: /* parent, success */ exit(0); break; } } /* main loop */ timestamp(); status.requests = 0; status.errors = 0; start_time = current_time; select_loop(server_s); return 0; }
int main() { int node_id ; binary_header_class bhc; binary_time_record_class btrc; if(read_config_files(&cf)==-1) { printf("\nCannot load config_xml.xml"); exit(0); } FILE *f; char *filename = cf.scenario_file_bin; f = fopen(filename,"rb"); if(f == NULL) return 0; io_read_binary_header_from_file(&bhc,f); io_binary_print_header(&bhc); node_id = get_node_id(); char **record_table; record_table=(char**)malloc(sizeof(char*)*bhc.time_record_number); if (record_table == NULL) { printf("\nCannot alloc for record table"); exit(0); } int i; for(i =0; i<bhc.time_record_number; i++) { record_table[i] = (char*)malloc(sizeof(char)*bhc.node_number+1); memset(record_table[i],0,bhc.node_number+1); } int count =0; int j; int k; for(i =0; i<bhc.time_record_number; i++) { io_read_binary_time_record_from_file(&btrc,f); //printf("\ni:%d with record number %d and time:%f\n",i,btrc.record_number,btrc.time); binary_record_class * binary_records; binary_records = (binary_record_class *)malloc(sizeof(binary_record_class)* btrc.record_number); if(binary_records == NULL) { printf("\nNot enough memory"); exit(0); } io_read_binary_records_from_file(binary_records,btrc.record_number,f); if(btrc.record_number <=0 ) continue; //io_binary_print_record(binary_records); for(k=0; k<btrc.record_number; k++) { if( binary_records[k].from_node == node_id) { //printf("\nbinary_records[k].loss_rate:%f",binary_records[k].loss_rate); if(binary_records[k].loss_rate < 0.8) record_table[i][binary_records[k].to_node] = 1; else record_table[i][binary_records[k].to_node] = -1; continue; } if( binary_records[k].to_node == node_id) { //printf("\nbinary_records[k].loss_rate:%f",binary_records[k].loss_rate); if(binary_records[k].loss_rate < 0.8) record_table[i][binary_records[k].from_node] = 1; else record_table[i][binary_records[k].from_node] = -1; } } free(binary_records); } //refine_neighbors_record1(records,bhc.time_record_number); //printf("\nrefine neighbor table"); for(i =1; i<bhc.time_record_number; i++) for(j=0; j<bhc.node_number; j++) { if(record_table[i][j] == 0) { record_table[i][j] = record_table[i-1][j]; } } //sum all neighbors in a point of time int temp =0; for(i =1; i<bhc.time_record_number; i++) { for(j=0; j<bhc.node_number; j++) { if(record_table[i][j] == 1) temp++; } record_table[i][j] = temp; temp =0; } //printf("\n refine finish"); char *file_bin = cf.neighbor_table_bin; write_neighbor_time_table_to_file(file_bin,record_table,bhc.time_record_number,bhc.node_number + 1,node_id); close(f); printf("\n write successfully"); int number_of_time_record; int number_of_node; //char** tables= load_neighbor_record_table_file(cf.neighbor_table_bin,&number_of_time_record,&number_of_node,node_id); //if(tables == NULL) //{ //printf("\nCannot load neighbor table file"); //return 0; //} /*for(i =0;i<number_of_time_record;i++) { for(j=0;j<number_of_node;j++) { printf("%d ",tables[i][j]); } printf("\n"); }*/ return 0; }
int main(int argc, char **argv) { int c; /* command line arg */ int server_s; /* boa socket */ /* set umask to u+rw, u-x, go-rwx */ c = umask(~0600); if (c == -1) { perror("umask"); exit(1); } devnullfd = open("/dev/null", 0); /* make STDIN and STDOUT point to /dev/null */ if (devnullfd == -1) { DIE("can't open /dev/null"); } if (dup2(devnullfd, STDIN_FILENO) == -1) { DIE("can't dup2 /dev/null to STDIN_FILENO"); } if (dup2(devnullfd, STDOUT_FILENO) == -1) { DIE("can't dup2 /dev/null to STDOUT_FILENO"); } /* but first, update timestamp, because log_error_time uses it */ (void) time(¤t_time); while ((c = getopt(argc, argv, "c:r:d")) != -1) { switch (c) { case 'c': if (server_root) free(server_root); server_root = strdup(optarg); if (!server_root) { perror("strdup (for server_root)"); exit(1); } break; case 'r': if (chdir(optarg) == -1) { log_error_time(); perror("chdir (to chroot)"); exit(1); } if (chroot(optarg) == -1) { log_error_time(); perror("chroot"); exit(1); } if (chdir("/") == -1) { log_error_time(); perror("chdir (after chroot)"); exit(1); } break; case 'd': do_fork = 0; break; default: fprintf(stderr, "Usage: %s [-c serverroot] [-r chroot] [-d]\n", argv[0]); exit(1); } } /* fix it first, see this file */ fixup_server_root(); /* parse configuration files, see config.c */ read_config_files(); /* log function, see log.c */ open_logs(); /* create http server socket, see this file */ server_s = create_server_socket(); /* init signal for later use, see signals.c */ init_signals(); /* give privs if we can, see this file */ drop_privs(); /* setup envrionment varables, see cgi.c */ create_common_env(); /* escape handle, see escape.c */ build_needs_escape(); /* max connections parse from config files,see config.c & y.tab.c for more detail */ if (max_connections < 1) { struct rlimit rl; /* has not been set explicitly */ /* getrlimit is system call, see man getrlimit for more detail */ c = getrlimit(RLIMIT_NOFILE, &rl); if (c < 0) { perror("getrlimit"); exit(1); } /* set to max allowed by HOST os. */ max_connections = rl.rlim_cur; } /* background ourself */ if (do_fork) { switch(fork()) { case -1: /* error */ perror("fork"); exit(1); break; case 0: /* child, success */ /* so,we run in child */ break; default: /* parent, success */ /* exit in parent */ exit(0); break; } } /* main loop */ timestamp(); status.requests = 0; status.errors = 0; start_time = current_time; /*start socket and process request, see select.c*/ select_loop(server_s); return 0; }
int main() { if(read_config_files(&cf)== -1) { printf("\nError in reading config files"); exit(0); } //---declare variable of program----// int listen_sd, accept_sd; struct sockaddr_in addr; int i; //--------------load action record from file-----------------------// int numberofac; char *filename = cf.action_record; ActionRecord *ac; ac = ReadOutputFile(filename,&numberofac); if(ac == NULL) { printf("\nCannot read action record file"); return 0; } //sort the array with the action's starting time SortActionArray(ac,numberofac); printf("\nnumber of action record:%d",numberofac); //-------------load action mapping file------------------------// char *action_mapping_file = cf.action_mapping; action_mapping *ap ; int numberofap =0; ap = read_action_mapping_file(action_mapping_file,&numberofap); if(ap == NULL) { printf("\nCannot read action mapping file"); return 0; } action_mapping *temp; temp = ap; while(temp!=NULL) { print_action_mapping(temp); temp=temp->next; } //-------------------------------load setting file ---------------// char *setting_file = cf.setting_file; id_ip *ID_IP; int numberofnode; ID_IP = read_setting_file(setting_file,&numberofnode); if(ID_IP == NULL) { printf("\nCannot read setting file"); return 0; } printf("\nnumber of node in setting file:%d\n",numberofnode); //------------INIT main process to control child processes----------------// main_process_init(); //--------------INIT server for listening the time value from QOMET-------// /* If an argument was specified, use it to */ /* control the number of incoming connections */ listen_sd = InitTCPServer(SERVER_PORT); if(listen_sd < 1) { fprintf(stderr,"Server cannot init"); return 0; } //--------------------------main loop----------------------// do_actions(listen_sd,ac,numberofac,ap,ID_IP); //------------------------close program--------------------// /* Close the listen socket */ close(listen_sd); //kill all child processes// kill_all_processes(main_p->pgid); //wait for close main process// wait_to_close(); return 0; //--------------close program in bad cases-----------------------// bad_main: printf("\nclose do action program\n"); close(listen_sd); close(accept_sd); kill_all_processes(main_p->pgid); exit(-1); }
int main(int argc, char *argv[]) { int server_s; /* aspis socket */ pid_t pid; /* set umask to u+rw, u-x, go-rwx */ /* according to the man page, umask always succeeds */ umask(077); /* but first, update timestamp, because log_error_time uses it */ (void) time(¤t_time); /* set timezone right away */ tzset(); { int devnullfd = -1; devnullfd = open("/dev/null", 0); /* make STDIN point to /dev/null */ if (devnullfd == -1) { DIE("can't open /dev/null"); } if (dup2(devnullfd, STDIN_FILENO) == -1) { DIE("can't dup2 /dev/null to STDIN_FILENO"); } (void) close(devnullfd); } parse_commandline(argc, argv); fixup_server_root(); read_config_files(); drop_privs1(); set_root(); create_common_env(); open_logs(); server_s = create_server_socket(); init_signals(); build_needs_escape(); /* background ourself */ if (do_fork) { pid = fork(); } else { pid = getpid(); } switch (pid) { case -1: /* error */ perror("fork/getpid"); exit(EXIT_FAILURE); case 0: /* child, success */ break; default: /* parent, success */ if (pid_file != NULL) { FILE *PID_FILE = fopen(pid_file, "w"); if (PID_FILE != NULL) { fprintf(PID_FILE, "%d", pid); fclose(PID_FILE); } else { perror("fopen pid file"); } } if (do_fork) exit(EXIT_SUCCESS); break; } drop_privs2(); /* main loop */ timestamp(); status.requests = 0; status.errors = 0; start_time = current_time; loop(server_s); close_logs(); return 0; }