6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
8 * This program starts the DCM in a "clean" environment.
9 * and then waits for it to exit.
13 static char *rcsid_sms_starter_c = "$Header$";
18 #include <sys/types.h>
21 #include <sys/signal.h>
22 #include <sys/ioctl.h>
24 #define SMS_LOG_FILE "/u1/sms/dcm.log"
26 #define SMS_PROG "/u1/sms/bin/dcm"
34 "illegal instruction",
41 "segmentation violation",
46 "urgent I/O condition",
51 "stopped (tty input)",
52 "stopped (tty output)",
54 "cputime limit exceeded",
55 "filesize limit exceeded",
56 "virtual timer expired",
57 "profiling timer expired",
58 "window size changed",
60 "user defined signal 1",
61 "user defined signal 2",
74 while (wait3(&stat, WNOHANG, 0) > 0) {
75 if (WIFEXITED(stat)) {
78 "exited with code %d\n",
81 if (WIFSIGNALED(stat)) {
82 sprintf(buf, "exited on %s signal%s\n",
83 sigdescr[stat.w_termsig],
84 (stat.w_coredump?"; Core dumped":0));
86 write(rdpipe[1], buf, strlen(buf));
96 int logf, inf, i, done, pid, tty;
99 extern char *sys_errlist[];
101 int nfds = getdtablesize();
104 signal(SIGCHLD, cleanup);
106 logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);
108 perror(SMS_LOG_FILE);
111 inf = open("/dev/null", O_RDONLY , 0);
128 tty = open("/dev/tty");
129 ioctl(tty, TIOCNOTTY, 0);
132 if ((pid = fork()) == 0) {
137 for (i = 3; i <nfds; i++) close(i);
138 execl(SMS_PROG, "dcm", 0);
139 perror("cannot run dcm");
147 log = fdopen(logf, "w");
148 prog = fdopen(rdpipe[0], "r");
153 extern char *ctime();
158 if (fgets(buf, BUFSIZ, prog) == NULL) {
160 strcpy(buf, "Unable to read from program: ");
161 strcat(buf, sys_errlist[errno]);
166 time_s = ctime(&foo)+4;
167 time_s[strlen(time_s)-6]='\0';
168 fprintf(log, "%s <%d> %s", time_s, pid, buf);