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>
21 #include <sys/types.h>
24 #include <sys/signal.h>
25 #include <sys/ioctl.h>
26 #include <moira_site.h>
36 "illegal instruction",
43 "segmentation violation",
48 "urgent I/O condition",
53 "stopped (tty input)",
54 "stopped (tty output)",
56 "cputime limit exceeded",
57 "filesize limit exceeded",
58 "virtual timer expired",
59 "profiling timer expired",
60 "window size changed",
62 "user defined signal 1",
63 "user defined signal 2",
76 while (wait3(&stat, WNOHANG, 0) > 0) {
77 if (WIFEXITED(stat)) {
80 "exited with code %d\n",
83 if (WIFSIGNALED(stat)) {
84 sprintf(buf, "exited on %s signal%s\n",
85 sigdescr[stat.w_termsig],
86 (stat.w_coredump?"; Core dumped":0));
88 write(rdpipe[1], buf, strlen(buf));
98 int logf, inf, i, done, pid, tty;
101 extern char *sys_errlist[];
103 int nfds = getdtablesize();
106 signal(SIGCHLD, cleanup);
108 sprintf(buf, "%s/%s.log", SMS_DIR, PROG);
109 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
114 inf = open("/dev/null", O_RDONLY , 0);
131 tty = open("/dev/tty");
132 ioctl(tty, TIOCNOTTY, 0);
134 sprintf(buf, "%s/%s", BIN_DIR, PROG);
136 if ((pid = fork()) == 0) {
141 for (i = 3; i <nfds; i++) close(i);
143 perror("cannot run dcm");
151 log = fdopen(logf, "w");
152 prog = fdopen(rdpipe[0], "r");
157 extern char *ctime();
162 if (fgets(buf, BUFSIZ, prog) == NULL) {
164 strcpy(buf, "Unable to read from program: ");
165 strcat(buf, sys_errlist[errno]);
170 time_s = ctime(&foo)+4;
171 time_s[strlen(time_s)-6]='\0';
172 fprintf(log, "%s <%d> %s", time_s, pid, buf);