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>
22 #include <sys/types.h>
25 #include <sys/signal.h>
26 #include <sys/ioctl.h>
29 #include <sys/resource.h>
30 #include <moira_site.h>
32 #define PROG "reg_svr"
39 int stat, serrno = errno;
44 while (waitpid(-1, &stat, WNOHANG) > 0) {
45 if (WIFEXITED(stat)) {
46 if (WEXITSTATUS(stat))
48 "exited with code %d\n",
51 if (WIFSIGNALED(stat)) {
52 sprintf(buf, "exited on signal %d%s\n",
54 (WCOREDUMP(stat)?"; Core dumped":0));
56 write(rdpipe[1], buf, strlen(buf));
66 int logf, inf, i, done, pid, tty;
70 extern char *sys_errlist[];
72 struct sigaction action;
75 getrlimit(RLIMIT_NOFILE, &rl);
78 action.sa_handler = cleanup;
80 sigemptyset(&action.sa_mask);
81 sigaction(SIGCHLD, &action, NULL);
83 sprintf(buf, "%s/%s.log", SMS_DIR, PROG);
84 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
89 inf = open("/dev/null", O_RDONLY , 0);
107 sprintf(buf, "%s/%s", BIN_DIR, PROG);
109 if ((pid = fork()) == 0) {
114 for (i = 3; i <nfds; i++) close(i);
116 perror("cannot run reg_svr");
124 log = fdopen(logf, "w");
125 prog = fdopen(rdpipe[0], "r");
134 if (fgets(buf, BUFSIZ, prog) == NULL) {
135 if (errno && errno!=EINTR) {
136 strcpy(buf, "Unable to read from program: ");
137 strcat(buf, sys_errlist[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);