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.3 1987-08-22 17:30:58 wesommer
13 * Changed path used to start server.
15 * Revision 1.2 87/06/02 20:08:16 wesommer
16 * Changed logging, location of daemon to run.
18 * Revision 1.1 87/06/01 03:35:33 wesommer
24 static char *rcsid_sms_starter_c = "$Header$";
29 #include <sys/types.h>
32 #include <sys/signal.h>
33 #include <sys/ioctl.h>
35 #define SMS_LOG_FILE "/u1/sms/sms.log"
37 #define SMS_PROG "/u1/sms/bin/smsd"
45 "illegal instruction",
52 "segmentation violation",
57 "urgent I/O condition",
62 "stopped (tty input)",
63 "stopped (tty output)",
65 "cputime limit exceeded",
66 "filesize limit exceeded",
67 "virtual timer expired",
68 "profiling timer expired",
69 "window size changed",
71 "user defined signal 1",
72 "user defined signal 2",
85 while (wait3(&stat, WNOHANG, 0) > 0) {
86 if (WIFEXITED(stat)) {
89 "exited with code %d\n",
92 if (WIFSIGNALED(stat)) {
93 sprintf(buf, "exited on %s signal%s\n",
94 sigdescr[stat.w_termsig],
95 (stat.w_coredump?"; Core dumped":0));
97 write(rdpipe[1], buf, strlen(buf));
107 int logf, inf, i, done, pid, tty;
110 extern char *sys_errlist[];
112 int nfds = getdtablesize();
115 signal(SIGCHLD, cleanup);
117 logf = open(SMS_LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);
119 perror(SMS_LOG_FILE);
122 inf = open("/dev/null", O_RDONLY , 0);
139 tty = open("/dev/tty");
140 ioctl(tty, TIOCNOTTY, 0);
143 if ((pid = fork()) == 0) {
148 for (i = 3; i <nfds; i++) close(i);
149 execl(SMS_PROG, "smsd", 0);
150 perror("cannot run smsd");
154 perror("sms_starter");
158 log = fdopen(logf, "w");
159 prog = fdopen(rdpipe[0], "r");
164 extern char *ctime();
169 if (fgets(buf, BUFSIZ, prog) == NULL) {
171 strcpy(buf, "Unable to read from program: ");
172 strcat(buf, sys_errlist[errno]);
177 time_s = ctime(&foo)+4;
178 time_s[strlen(time_s)-6]='\0';
179 fprintf(log, "%s <%d> %s", time_s, pid, buf);