static int champ_chooser_fork(struct sdirs *sdirs, struct conf *conf) { pid_t childpid=-1; if(!conf->forking) { logp("Not forking a champ chooser process.\n"); // They need to manually run a separate process. return 0; } switch((childpid=fork())) { case -1: logp("fork failed in %s: %s\n", __func__, strerror(errno)); return -1; case 0: // Child. int cret; set_logfp(NULL, conf); switch(champ_chooser_server(sdirs, conf)) { case 0: cret=0; default: cret=1; } exit(cret); default: // Parent. logp("forked champ chooser pid %d\n", childpid); return 0; } return -1; // Not reached. }
// The return code of this is the return code of the standalone process. int champ_chooser_server_standalone(struct conf **globalcs) { int ret=1; struct sdirs *sdirs=NULL; struct conf **cconfs=NULL; const char *orig_client=get_string(globalcs[OPT_ORIG_CLIENT]); if(!(cconfs=confs_alloc())) goto end; confs_init(cconfs); // We need to be given a client name and load the relevant server side // clientconfdir file, because various settings may be overridden // there. if(set_string(cconfs[OPT_CNAME], orig_client) || conf_load_clientconfdir(globalcs, cconfs) || !(sdirs=sdirs_alloc()) || sdirs_init_from_confs(sdirs, cconfs) || champ_chooser_server(sdirs, cconfs, 0 /* resume */)) goto end; ret=0; end: confs_free(&cconfs); sdirs_free(&sdirs); return ret; }
static int champ_chooser_fork(struct sdirs *sdirs, struct conf **confs, int resume) { pid_t childpid=-1; int cret; if(!get_int(confs[OPT_FORK])) { logp("Not forking a champ chooser process.\n"); // They need to manually run a separate process. return 0; } switch((childpid=fork())) { case -1: logp("fork failed in %s: %s\n", __func__, strerror(errno)); return -1; case 0: // Child. log_fzp_set(NULL, confs); switch(champ_chooser_server(sdirs, confs, resume)) { case 0: cret=0; break; default: cret=1; break; } exit(cret); default: // Parent. logp("forked champ chooser pid %d\n", childpid); return 0; } return -1; // Not reached. }