int main(void) { int i; build_needs_escape(); for(i = 0; i <= NEEDS_ESCAPE_BITS; ++i) { if (needs_escape(i)) { fprintf(stdout, "%3d needs escape.\n", i); } } return(0); }
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 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(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; }