void sig_all_default(void) { int i; for (i = 1; i < SIGMAX; i++) if (i != SIGPROF || i != SIGSEGV) sig_default(i); }
static void child_exec(int which) { pid_t pid = 0; tain_t now; tain_t when_ok; char **argv = deux[which].argv; tain_now(&now); tain_load(&when_ok, 1, 0); tain_plus(&when_ok, &deux[which].when, &when_ok); if(tain_less(&now, &when_ok)){ warn("pausing for respawn of ", argv[0], " ..."); sleep(1); } /* if option -x: ** not supervising, don't fork here, just exec into deux[1] */ if(opt_super ? 1 : (which == 0)){ while((pid = fork()) == -1){ warn("failure on fork() while starting ", argv[0]); sleep(2); } } /* child (or, if not opt_super, execing into deux[1]): */ if(pid == 0){ /* setup logpipe: */ fd_dupe(which, my_logpipe[which]); close(my_logpipe[0]); close(my_logpipe[1]); #if 0 if(which == 1){ /* redirect stderr to stdout for program: */ fd_dupe(2, 1); } #endif /* reset default signal handlers, unblock: */ sig_default(SIGTERM); sig_default(SIGCHLD); sig_default(SIGALRM); sig_default(SIGCONT); sig_default(SIGHUP); sig_default(SIGINT); sig_default(SIGQUIT); sig_default(SIGTSTP); sig_default(SIGUSR1); sig_default(SIGUSR2); sig_default(SIGPIPE); sigset_unblock(&my_sigset); /* do it: */ execvx(argv[0], argv, environ, NULL); /* uh oh: */ fatal_syserr("failure on exec of ", argv[0]); } /* parent: */ deux[which].pid = pid; tain_now(&deux[which].when); return; }
static void child_exec(int which) { pid_t pid = 0; tain_t now; tain_t when_ok; char **argv = deux[which].argv; tain_now(&now); tain_load(&when_ok, 1, 0); tain_plus(&when_ok, &deux[which].when, &when_ok); if(tain_less(&now, &when_ok)){ warn("pausing for restart of ", argv[0], " ..."); sleep(1); } /* if option -x: ** not supervising, don't fork here, just exec into deux[1] */ if(opt_super ? 1 : (which == 0)){ while((pid = fork()) == -1){ warn("failure on fork() while starting ", argv[0]); sleep(2); } } /* child (or, if not opt_super, execing into deux[1]): */ if(pid == 0){ int fd, fd_max; struct rlimit rlim; int i; /* setup PERP_BASE in environment: */ if(newenv_set("PERP_BASE", perp_base) == -1){ fatal_syserr("failure setting environment in child for ", argv[0]); } /* prepare for closing unused file descriptors: */ if(getrlimit(RLIMIT_NOFILE, &rlim) == -1){ fatal_syserr("failure getting file rlimit in child for ", argv[0]); } fd_max = (rlim.rlim_max == RLIM_INFINITY) ? 1024 : rlim.rlim_max; /* start fd 0,1,2 on /dev/null: */ if((fd = open("/dev/null", O_RDWR)) == -1){ fatal_syserr("failure opening /dev/null in child for ", argv[0]); } fd_dupe(0, fd); fd_dupe(1, fd); fd_dupe(2, fd); close(fd); /* setup logpipe: */ fd_dupe(which, my_logpipe[which]); if(which == 1){ /* perpd gets stderr redirected to stdout for logger: */ fd_dupe(2, 1); } /* close all other descriptors: */ for(i = 3; i < fd_max; ++i) close(i); /* set default umask: */ umask(0); /* reset default signal handlers, unblock: */ sig_default(SIGTERM); sig_default(SIGCHLD); sig_default(SIGALRM); sig_default(SIGCONT); sig_default(SIGHUP); sig_default(SIGINT); sig_default(SIGQUIT); sig_default(SIGTSTP); sig_default(SIGUSR1); sig_default(SIGUSR2); sig_default(SIGPIPE); sigset_unblock(&my_sigset); /* do it: */ newenv_run(argv, environ); /* uh oh: */ fatal_syserr("failure on exec of ", argv[0]); } /* parent: */ deux[which].pid = pid; tain_now(&deux[which].when); return; }