6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
8 * This program starts the sms server in a "clean" environment.
9 * and then waits for it to exit.
12 * Revision 1.2 1987-06-02 20:08:16 wesommer
13 * Changed logging, location of daemon to run.
15 * Revision 1.1 87/06/01 03:35:33 wesommer
21 static char *rcsid_sms_starter_c = "$Header$";
26 #include <sys/types.h>
29 #include <sys/signal.h>
30 #include <sys/ioctl.h>
32 #define SMS_LOG_FILE "/u1/sms/sms.log"
34 #define SMS_PROG "/u1/sms/server/smsd"
42 "illegal instruction",
49 "segmentation violation",
54 "urgent I/O condition",
59 "stopped (tty input)",
60 "stopped (tty output)",
62 "cputime limit exceeded",
63 "filesize limit exceeded",
64 "virtual timer expired",
65 "profiling timer expired",
66 "window size changed",
68 "user defined signal 1",
69 "user defined signal 2",
82 while (wait3(&stat, WNOHANG, 0) > 0) {
83 if (WIFEXITED(stat)) {
86 "exited with code %d\n",
89 if (WIFSIGNALED(stat)) {
90 sprintf(buf, "exited on %s signal%s\n",
91 sigdescr[stat.w_termsig],
92 (stat.w_coredump?"; Core dumped":0));
94 write(rdpipe[1], buf, strlen(buf));
104 int logf, inf, i, done, pid, tty;
107 extern char *sys_errlist[];
109 int nfds = getdtablesize();
112 signal(SIGCHLD, cleanup);
114 logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);
116 perror(SMS_LOG_FILE);
119 inf = open("/dev/null", O_RDONLY , 0);
136 tty = open("/dev/tty");
137 ioctl(tty, TIOCNOTTY, 0);
140 if ((pid = fork()) == 0) {
145 for (i = 3; i <nfds; i++) close(i);
146 execl(SMS_PROG, "smsd", 0);
147 perror("cannot run smsd");
151 perror("sms_starter");
155 log = fdopen(logf, "w");
156 prog = fdopen(rdpipe[0], "r");
161 extern char *ctime();
166 if (fgets(buf, BUFSIZ, prog) == NULL) {
168 strcpy(buf, "Unable to read from program: ");
169 strcat(buf, sys_errlist[errno]);
174 time_s = ctime(&foo)+4;
175 time_s[strlen(time_s)-6]='\0';
176 fprintf(log, "%s <%d> %s", time_s, pid, buf);