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 sms server in a "clean" environment.
11 * and then waits for it to exit.
16 static char *rcsid_sms_starter_c = "$Header$";
19 #include <mit-copyright.h>
22 #include <sys/types.h>
25 #include <sys/signal.h>
26 #include <sys/ioctl.h>
28 #define SMS_LOG_FILE "/u1/sms/sms.log"
30 #define SMS_PROG "/u1/sms/bin/smsd"
38 "illegal instruction",
45 "segmentation violation",
50 "urgent I/O condition",
55 "stopped (tty input)",
56 "stopped (tty output)",
58 "cputime limit exceeded",
59 "filesize limit exceeded",
60 "virtual timer expired",
61 "profiling timer expired",
62 "window size changed",
64 "user defined signal 1",
65 "user defined signal 2",
78 while (wait3(&stat, WNOHANG, 0) > 0) {
79 if (WIFEXITED(stat)) {
82 "exited with code %d\n",
85 if (WIFSIGNALED(stat)) {
86 sprintf(buf, "exited on %s signal%s\n",
87 sigdescr[stat.w_termsig],
88 (stat.w_coredump?"; Core dumped":0));
90 write(rdpipe[1], buf, strlen(buf));
100 int logf, inf, i, done, pid, tty;
103 extern char *sys_errlist[];
105 int nfds = getdtablesize();
108 signal(SIGCHLD, cleanup);
110 logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);
112 perror(SMS_LOG_FILE);
115 inf = open("/dev/null", O_RDONLY , 0);
132 tty = open("/dev/tty");
133 ioctl(tty, TIOCNOTTY, 0);
136 if ((pid = fork()) == 0) {
141 for (i = 3; i <nfds; i++) close(i);
142 execl(SMS_PROG, "smsd", 0);
143 perror("cannot run smsd");
147 perror("sms_starter");
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);