static void nfsd_exit(int status) { killchildren(); unregistration(); exit(status); }
pid_t au_fork() { pid_t child = fork(); if (child == -1) { killchildren(); killproc(parent,"fork failed\n"); } return child; }
static void notifyf(int sig) { int i; for(i = 0; sigmsgs[i].msg; i++) if(sigmsgs[i].sig == sig) killchildren(sigmsgs[i].msg); /* should never happen */ signal(sig, SIG_DFL); kill(getpid(), sig); }
int notifyf(void *a, char *msg) { static int nnote; USED(a); if(++nnote > 100){ /* until andrew fixes his program */ fprint(2, "mk: too many notes\n"); notify(0); abort(); } if(strcmp(msg, "interrupt")!=0 && strcmp(msg, "hangup")!=0) return 0; killchildren(msg); return -1; }
int main() { //pid_t child; int childstatus; pid_t wpid; parent = getpid(); mhd_port = get_port(4000); spdy2http_port = get_port(4100); mhd2spdy_port = get_port(4200); child_mhd = au_fork(); if (child_mhd == 0) { //run MHD pid_t devnull; char *port_s; close(1); devnull = open("/dev/null", O_WRONLY); if (-1 == devnull) abort(); if (1 != devnull) { dup2(devnull, 1); close(devnull); } asprintf(&port_s, "%i", mhd_port); execlp ("../examples/minimal_example", "minimal_example", port_s, NULL); fprintf(stderr, "executing mhd failed\nFor this test 'make' must be run before 'make check'!\n"); //killchildren(); _exit(1); } child_spdy2http = au_fork(); if (child_spdy2http == 0) { //run spdy2http pid_t devnull; char *port_s; //char *url; close(1); devnull = open("/dev/null", O_WRONLY); if (-1 == devnull) abort(); if (1 != devnull) { dup2(devnull, 1); close(devnull); } //asprintf(&url, "127.0.0.1:%i", mhd_port); asprintf(&port_s, "%i", spdy2http_port); sleep(1); execlp ("../spdy2http/microspdy2http", "microspdy2http", "-v4rtT", "10", "-p", port_s, NULL); fprintf(stderr, "executing microspdy2http failed\n"); //killchildren(); _exit(1); } child_mhd2spdy = au_fork(); if (child_mhd2spdy == 0) { //run MHD2sdpy pid_t devnull; char *port_s; char *url; close(1); devnull = open("/dev/null", O_WRONLY); if (-1 == devnull) abort(); if (1 != devnull) { dup2(devnull, 1); close(devnull); } asprintf(&url, "http://127.0.0.1:%i", spdy2http_port); asprintf(&port_s, "%i", mhd2spdy_port); sleep(2); execlp ("../examples/mhd2spdy", "mhd2spdy", "-vosb", url, "-p", port_s, NULL); fprintf(stderr, "executing mhd2spdy failed\n"); //killchildren(); _exit(1); } child_curl = au_fork(); if (child_curl == 0) { //run curl FILE *p; pid_t devnull; char *cmd; unsigned int i; int retc; char buf[strlen(EXPECTED_BODY) + 1]; close(1); devnull = open("/dev/null", O_WRONLY); if (-1 == devnull) abort (); if (1 != devnull) { dup2(devnull, 1); close(devnull); } asprintf (&cmd, "curl --proxy http://127.0.0.1:%i http://127.0.0.1:%i/", mhd2spdy_port, mhd_port); sleep(3); p = popen(cmd, "r"); if (p != NULL) { for (i = 0; i < strlen(EXPECTED_BODY) && !feof(p); i++) { retc = fgetc (p); if (EOF == retc) abort (); /* what did feof(p) do there!? */ buf[i] = (char) retc; } pclose(p); buf[i] = 0; _exit(strcmp(EXPECTED_BODY, buf)); } fprintf(stderr, "executing curl failed\n"); //killchildren(); _exit(1); } do { wpid = waitpid(child_mhd,&childstatus,WNOHANG); if(wpid == child_mhd) { fprintf(stderr, "mhd died unexpectedly\n"); killchildren(); return 1; } wpid = waitpid(child_spdy2http,&childstatus,WNOHANG); if(wpid == child_spdy2http) { fprintf(stderr, "spdy2http died unexpectedly\n"); killchildren(); return 1; } wpid = waitpid(child_mhd2spdy,&childstatus,WNOHANG); if(wpid == child_mhd2spdy) { fprintf(stderr, "mhd2spdy died unexpectedly\n"); killchildren(); return 1; } if(waitpid(child_curl,&childstatus,WNOHANG) == child_curl) { killchildren(); return WEXITSTATUS(childstatus); } sleep(1); } while(true); }
static void nfscbd_exit(int status __unused) { killchildren(); exit(status); }