6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * This program starts the user registration server
11 * in a "clean" environment, and then waits for it to exit.
15 static char *rcsid_mr_starter_c = "$Header$";
18 #include <mit-copyright.h>
21 #include <sys/types.h>
24 #include <sys/signal.h>
25 #include <sys/ioctl.h>
26 #include <moira_site.h>
28 #define PROG "reg_svr"
31 extern char *sys_siglist[];
42 while (wait3(&stat, WNOHANG, 0) > 0) {
43 if (WIFEXITED(stat)) {
46 "exited with code %d\n",
49 if (WIFSIGNALED(stat)) {
50 sprintf(buf, "exited on %s signal%s\n",
51 sys_siglist[stat.w_termsig],
52 (stat.w_coredump?"; Core dumped":0));
54 write(rdpipe[1], buf, strlen(buf));
64 int logf, inf, i, done, pid, tty;
67 extern char *sys_errlist[];
69 int nfds = getdtablesize();
72 signal(SIGCHLD, cleanup);
74 sprintf(buf, "%s/%s.log", SMS_DIR, PROG);
75 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
80 inf = open("/dev/null", O_RDONLY , 0);
97 tty = open("/dev/tty");
98 ioctl(tty, TIOCNOTTY, 0);
100 sprintf(buf, "%s/%s", BIN_DIR, PROG);
102 if ((pid = fork()) == 0) {
107 for (i = 3; i <nfds; i++) close(i);
109 perror("cannot run reg_svr");
117 log = fdopen(logf, "w");
118 prog = fdopen(rdpipe[0], "r");
123 extern char *ctime();
128 if (fgets(buf, BUFSIZ, prog) == NULL) {
130 strcpy(buf, "Unable to read from program: ");
131 strcat(buf, sys_errlist[errno]);
136 time_s = ctime(&foo)+4;
137 time_s[strlen(time_s)-6]='\0';
138 fprintf(log, "%s <%d> %s", time_s, pid, buf);