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_sms_starter_c = "$Header$";
18 #include <mit-copyright.h>
21 #include <sys/types.h>
24 #include <sys/signal.h>
25 #include <sys/ioctl.h>
27 #define SMS_LOG_FILE "/u1/sms/dcm.log"
29 #define SMS_PROG "/u1/sms/bin/dcm"
37 "illegal instruction",
44 "segmentation violation",
49 "urgent I/O condition",
54 "stopped (tty input)",
55 "stopped (tty output)",
57 "cputime limit exceeded",
58 "filesize limit exceeded",
59 "virtual timer expired",
60 "profiling timer expired",
61 "window size changed",
63 "user defined signal 1",
64 "user defined signal 2",
77 while (wait3(&stat, WNOHANG, 0) > 0) {
78 if (WIFEXITED(stat)) {
81 "exited with code %d\n",
84 if (WIFSIGNALED(stat)) {
85 sprintf(buf, "exited on %s signal%s\n",
86 sigdescr[stat.w_termsig],
87 (stat.w_coredump?"; Core dumped":0));
89 write(rdpipe[1], buf, strlen(buf));
99 int logf, inf, i, done, pid, tty;
102 extern char *sys_errlist[];
104 int nfds = getdtablesize();
107 signal(SIGCHLD, cleanup);
109 logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);
111 perror(SMS_LOG_FILE);
114 inf = open("/dev/null", O_RDONLY , 0);
131 tty = open("/dev/tty");
132 ioctl(tty, TIOCNOTTY, 0);
135 if ((pid = fork()) == 0) {
140 for (i = 3; i <nfds; i++) close(i);
141 execl(SMS_PROG, "dcm", 0);
142 perror("cannot run dcm");
150 log = fdopen(logf, "w");
151 prog = fdopen(rdpipe[0], "r");
156 extern char *ctime();
161 if (fgets(buf, BUFSIZ, prog) == NULL) {
163 strcpy(buf, "Unable to read from program: ");
164 strcat(buf, sys_errlist[errno]);
169 time_s = ctime(&foo)+4;
170 time_s[strlen(time_s)-6]='\0';
171 fprintf(log, "%s <%d> %s", time_s, pid, buf);