int server(struct conf *conf, const char *conffile, struct lock *lock, int generate_ca_only) { int ret=0; int rfd=-1; // normal client port // Only close and reopen listening sockets if the ports changed. // Otherwise you get an "unable to bind listening socket on port X" // error, and the server stops. char *oldport=NULL; char *oldstatusport=NULL; //return champ_test(conf); if(ca_server_setup(conf)) return 1; if(generate_ca_only) { logp("The '-g' command line option was given. Exiting now.\n"); return 0; } if(conf->forking && conf->daemon) { if(daemonise() || relock(lock)) return 1; } ssl_load_globals(); while(!ret && !gentleshutdown) { ret=run_server(conf, conffile, &rfd, oldport, oldstatusport); if(ret) break; if(hupreload && !gentleshutdown) { if(oldport) free(oldport); if(oldstatusport) free(oldstatusport); oldport=strdup(conf->port); oldstatusport=conf->status_port? strdup(conf->status_port):NULL; if(reload(conf, conffile, 0, // Not first time. conf->max_children, conf->max_status_children, 0)) // Not JSON output. ret=1; } hupreload=0; } close_fd(&rfd); close_fd(&sfd); if(oldport) free(oldport); if(oldstatusport) free(oldstatusport); // The signal handler stuff sets up chlds. Need to free them. chlds_free(); // FIX THIS: Have an enum for a return value, so that it is more obvious what // is happening, like client.c does. return ret; }
int server(struct conf **confs, const char *conffile, struct lock *lock, int generate_ca_only) { enum serret ret=SERVER_ERROR; int rfds[LISTEN_SOCKETS]; // Sockets for clients to connect to. int sfds[LISTEN_SOCKETS]; // Status server sockets. //return champ_test(confs); init_fds(rfds); init_fds(sfds); if(ca_server_setup(confs)) goto error; if(generate_ca_only) { logp("The '-g' command line option was given. Exiting now.\n"); goto end; } if(get_int(confs[OPT_FORK]) && get_int(confs[OPT_DAEMON])) { if(daemonise() || relock(lock)) goto error; } ssl_load_globals(); while(!gentleshutdown) { if(run_server(confs, conffile, rfds, sfds)) goto error; if(hupreload && !gentleshutdown) { if(reload(confs, conffile, 0, // Not first time. get_int(confs[OPT_MAX_CHILDREN]), get_int(confs[OPT_MAX_STATUS_CHILDREN]))) goto error; } hupreload=0; } end: ret=SERVER_OK; error: close_fds(rfds); close_fds(sfds); // FIX THIS: Have an enum for a return value, so that it is more obvious what // is happening, like client.c does. return ret; }