X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/316aa5b295611264b30d26de5499253a9ea4c9b2..34b6375ca4de11ca05f8c6907638a80411a8bfa9:/server/startmoira.c diff --git a/server/startmoira.c b/server/startmoira.c index b17b8230..a85bc680 100644 --- a/server/startmoira.c +++ b/server/startmoira.c @@ -1,154 +1,156 @@ -/* - * $Source$ - * $Author$ - * $Header$ +/* $Id$ * - * Copyright (C) 1987 by the Massachusetts Institute of Technology - * For copying and distribution information, please see the file - * . + * This program starts the moira server in a "clean" environment. + * and then waits for it to exit. * - * This program starts the moira server in a "clean" environment. - * and then waits for it to exit. - * + * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology + * For copying and distribution information, please see the file + * . */ -#ifndef lint -static char *rcsid_mr_starter_c = "$Header$"; -#endif lint - #include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include + +#include +#include +#include +#include +#include +#include + +RCSID("$Header$"); + #define PROG "moirad" -char *whoami; int rdpipe[2]; -extern char *sys_siglist[]; +char *whoami; +void cleanup(void); -cleanup() +void cleanup(void) { - union wait stat; - char buf[BUFSIZ]; - extern int errno; - int serrno = errno; - - buf[0]='\0'; - - while (wait3(&stat, WNOHANG, 0) > 0) { - if (WIFEXITED(stat)) { - if (stat.w_retcode) { - sprintf(buf, - "moirad exited with code %d\n", - stat.w_retcode); - send_zgram("startmoira", buf); - } - if (WIFSIGNALED(stat)) { - sprintf(buf, "moirad exited on %s signal%s\n", - sys_siglist[stat.w_termsig], - (stat.w_coredump?"; Core dumped":0)); - if(stat.w_coredump) send_zgram("startmoira", buf); - } - write(rdpipe[1], buf, strlen(buf)); - close(rdpipe[1]); + int stat, serrno = errno; + char buf[BUFSIZ]; + + buf[0] = '\0'; + + while (waitpid(-1, &stat, WNOHANG) > 0) + { + if (WIFEXITED(stat)) + { + if (WEXITSTATUS(stat)) + { + sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat)); + critical_alert("startmoira", "%s", buf); + } + } + if (WIFSIGNALED(stat)) + { + sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat), + (WCOREDUMP(stat) ? "; Core dumped" : "")); + if (WCOREDUMP(stat)) + critical_alert("startmoira", "%s", buf); } - errno = serrno; + write(rdpipe[1], buf, strlen(buf)); + close(rdpipe[1]); + } + errno = serrno; } -main(argc, argv) - int argc; - char **argv; +int main(int argc, char *argv[]) { - char buf[BUFSIZ]; - FILE *log, *prog; - int logf, inf, i, done, pid, tty; - - extern int errno; - extern char *sys_errlist[]; - - int nfds = getdtablesize(); - - whoami = argv[0]; - - setreuid(0); - signal(SIGCHLD, cleanup); - - sprintf(buf, "%s/moira.log", SMS_DIR); - logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); - if (logf<0) { - perror(buf); - exit(1); - } - inf = open("/dev/null", O_RDONLY , 0); - if (inf < 0) { - perror("/dev/null"); - exit(1); - } - pipe(rdpipe); - if (fork()) { - exit(0); - } - chdir("/"); - close(0); - close(1); - close(2); - dup2(inf, 0); - dup2(inf, 1); - dup2(inf, 2); - - tty = open("/dev/tty"); - ioctl(tty, TIOCNOTTY, 0); - close(tty); - sprintf(buf, "%s/%s", BIN_DIR, PROG); - - if ((pid = fork()) == 0) { - - dup2(inf, 0); - dup2(rdpipe[1], 1); - dup2(1,2); - for (i = 3; i