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_mr_starter_c = "$Header$";
18 #include <mit-copyright.h>
21 #include <sys/types.h>
24 #include <sys/signal.h>
25 #include <sys/ioctl.h>
27 #include <sys/resource.h>
28 #include <moira_site.h>
37 int stat, serrno = errno;
42 while (waitpid(-1, &stat, WNOHANG) > 0) {
43 if (WIFEXITED(stat)) {
44 if (WEXITSTATUS(stat))
46 "exited with code %d\n",
49 if (WIFSIGNALED(stat)) {
50 sprintf(buf, "exited with signal %d%s\n",
52 (WCOREDUMP(stat)?"; Core dumped":0));
54 write(rdpipe[1], buf, strlen(buf));
64 int logf, inf, i, done, pid, tty;
68 extern char *sys_errlist[];
70 struct sigaction action;
73 getrlimit(RLIMIT_NOFILE, &rl);
76 action.sa_handler = cleanup;
78 sigemptyset(&action.sa_mask);
79 sigaction(SIGCHLD, &action, NULL);
81 sprintf(buf, "%s/%s.log", SMS_DIR, PROG);
82 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
87 inf = open("/dev/null", O_RDONLY , 0);
105 sprintf(buf, "%s/%s", BIN_DIR, PROG);
107 if ((pid = fork()) == 0) {
112 for (i = 3; i <nfds; i++) close(i);
114 perror("cannot run dcm");
122 log = fdopen(logf, "w");
123 prog = fdopen(rdpipe[0], "r");
128 extern char *ctime();
133 if (fgets(buf, BUFSIZ, prog) == NULL) {
135 strcpy(buf, "Unable to read from program: ");
136 strcat(buf, sys_errlist[errno]);
141 time_s = ctime(&foo)+4;
142 time_s[strlen(time_s)-6]='\0';
143 fprintf(log, "%s <%d> %s", time_s, pid, buf);