3 * This program starts the user registration server
4 * in a "clean" environment, and then waits for it to exit.
6 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
15 #include <sys/resource.h>
27 #define PROG "reg_svr"
35 int stat, serrno = errno;
40 while (waitpid(-1, &stat, WNOHANG) > 0)
44 if (WEXITSTATUS(stat))
45 sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat));
47 if (WIFSIGNALED(stat))
49 sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat),
50 (WCOREDUMP(stat) ? "; Core dumped" : ""));
52 write(rdpipe[1], buf, strlen(buf));
58 int main(int argc, char **argv)
62 int logf, inf, i, done, pid;
65 struct sigaction action;
68 getrlimit(RLIMIT_NOFILE, &rl);
71 action.sa_handler = cleanup;
73 sigemptyset(&action.sa_mask);
74 sigaction(SIGCHLD, &action, NULL);
76 sprintf(buf, "%s/%s.log", MOIRA_DIR, PROG);
77 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
83 inf = open("/dev/null", O_RDONLY , 0);
101 sprintf(buf, "%s/%s", BIN_DIR, PROG);
103 if ((pid = fork()) == 0)
108 for (i = 3; i < nfds; i++)
111 perror("cannot run reg_svr");
120 log = fdopen(logf, "w");
121 prog = fdopen(rdpipe[0], "r");
130 if (!fgets(buf, BUFSIZ, prog))
132 if (errno && errno != EINTR)
134 strcpy(buf, "Unable to read from program: ");
135 strcat(buf, strerror(errno));
142 time_s = ctime(&foo) + 4;
143 time_s[strlen(time_s) - 6] = '\0';
144 fprintf(log, "%s <%d> %s", time_s, pid, buf);