6 * Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * This program starts the DCM in a "clean" environment.
11 * 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>
28 #include <sys/resource.h>
29 #include <moira_site.h>
39 int stat, serrno = errno;
44 while (waitpid(-1, &stat, WNOHANG) > 0)
48 if (WEXITSTATUS(stat))
49 sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat));
51 if (WIFSIGNALED(stat))
53 sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat),
54 (WCOREDUMP(stat) ? "; Core dumped" : ""));
56 write(rdpipe[1], buf, strlen(buf));
62 int main(int argc, char *argv)
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", MOIRA_DIR, PROG);
84 logf = open(buf, O_CREAT | O_WRONLY | O_APPEND, 0640);
90 inf = open("/dev/null", O_RDONLY , 0);
108 sprintf(buf, "%s/%s", BIN_DIR, PROG);
110 if ((pid = fork()) == 0)
115 for (i = 3; i < nfds; i++)
118 perror("cannot run dcm");
127 log = fdopen(logf, "w");
128 prog = fdopen(rdpipe[0], "r");
137 if (!fgets(buf, BUFSIZ, prog))
139 if (errno && errno != EINTR)
141 strcpy(buf, "Unable to read from program: ");
142 strcat(buf, sys_errlist[errno]);
149 time_s = ctime(&foo) + 4;
150 time_s[strlen(time_s) - 6] = '\0';
151 fprintf(log, "%s <%d> %s", time_s, pid, buf);