X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/c801de4c5e65ae5a33776cf4acfa6a89122af4de..refs/heads/LOCKING:/server/startmoira.c diff --git a/server/startmoira.c b/server/startmoira.c index 513674ff..4bb8925c 100644 --- a/server/startmoira.c +++ b/server/startmoira.c @@ -7,13 +7,13 @@ * For copying and distribution information, please see the file * . * - * This program starts the sms server in a "clean" environment. + * This program starts the moira server in a "clean" environment. * and then waits for it to exit. * */ #ifndef lint -static char *rcsid_sms_starter_c = "$Header$"; +static char *rcsid_mr_starter_c = "$Header$"; #endif lint #include @@ -24,47 +24,13 @@ static char *rcsid_sms_starter_c = "$Header$"; #include #include #include +#include -#define SMS_LOG_FILE "/u1/sms/sms.log" - -#define SMS_PROG "/u1/sms/bin/smsd" +#define PROG "moirad" +char *whoami int rdpipe[2]; -char *sigdescr[] = { - 0, - "hangup", - "interrupt", - "quit", - "illegal instruction", - "trace/BPT trap", - "IOT trap", - "EMT trap", - "floating exception", - "kill", - "bus error", - "segmentation violation", - "bad system call", - "broken pipe", - "alarm clock", - "termination", - "urgent I/O condition", - "stopped", - "stopped", - "continued", - "child exited", - "stopped (tty input)", - "stopped (tty output)", - "I/O possible", - "cputime limit exceeded", - "filesize limit exceeded", - "virtual timer expired", - "profiling timer expired", - "window size changed", - "signal 29", - "user defined signal 1", - "user defined signal 2", - "signal 32" -}; +extern char *sys_siglist[]; cleanup() { @@ -77,15 +43,17 @@ cleanup() while (wait3(&stat, WNOHANG, 0) > 0) { if (WIFEXITED(stat)) { - if (stat.w_retcode) + if (stat.w_retcode) { sprintf(buf, - "exited with code %d\n", + "moirad exited with code %d\n", stat.w_retcode); + send_zgram("startmoira", buf); } if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on %s signal%s\n", - sigdescr[stat.w_termsig], + 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]); @@ -94,6 +62,8 @@ cleanup() } main(argc, argv) + int argc; + char **argv; { char buf[BUFSIZ]; FILE *log, *prog; @@ -104,12 +74,15 @@ main(argc, argv) int nfds = getdtablesize(); + whoami = argv[0]; + setreuid(0); signal(SIGCHLD, cleanup); - logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640); + sprintf(buf, "%s/moira.log", SMS_DIR); + logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); if (logf<0) { - perror(SMS_LOG_FILE); + perror(buf); exit(1); } inf = open("/dev/null", O_RDONLY , 0); @@ -119,7 +92,7 @@ main(argc, argv) } pipe(rdpipe); if (fork()) { - exit(); + exit(0); } chdir("/"); close(0); @@ -132,6 +105,7 @@ main(argc, argv) tty = open("/dev/tty"); ioctl(tty, TIOCNOTTY, 0); close(tty); + sprintf(buf, "%s/%s", BIN_DIR, PROG); if ((pid = fork()) == 0) { @@ -139,12 +113,12 @@ main(argc, argv) dup2(rdpipe[1], 1); dup2(1,2); for (i = 3; i %s", time_s, pid, buf); + fprintf(log, "%s %s", time_s, buf); fflush(log); } while (!done); exit(0);