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 moira server in a "clean" environment.
11 * and then waits for it to exit.
16 static char *rcsid_mr_starter_c = "$Header$";
19 #include <mit-copyright.h>
23 #include <sys/types.h>
26 #include <sys/signal.h>
27 #include <sys/ioctl.h>
30 #include <sys/resource.h>
31 #include <moira_site.h>
42 int stat, serrno = errno;
47 while (waitpid(-1, &stat, WNOHANG) > 0)
51 if (WEXITSTATUS(stat))
53 sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat));
54 critical_alert("startmoira", "%s", buf);
57 if (WIFSIGNALED(stat))
59 sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat),
60 (WCOREDUMP(stat) ? "; Core dumped" : ""));
62 critical_alert("startmoira", "%s", buf);
64 write(rdpipe[1], buf, strlen(buf));
70 int main(int argc, char *argv[])
74 int logf, inf, i, done, pid, tty;
78 extern char *sys_errlist[];
80 struct sigaction action;
85 getrlimit(RLIMIT_NOFILE, &rl);
88 action.sa_handler = cleanup;
90 sigemptyset(&action.sa_mask);
91 sigaction(SIGCHLD, &action, NULL);
93 sprintf(buf, "%s/moira.log", MOIRA_DIR);
94 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
100 inf = open("/dev/null", O_RDONLY , 0);
118 sprintf(buf, "%s/%s", BIN_DIR, PROG);
120 if ((pid = fork()) == 0)
125 for (i = 3; i < nfds; i++)
128 perror("cannot run moirad");
133 perror("moira_starter");
137 log = fdopen(logf, "w");
138 prog = fdopen(rdpipe[0], "r");
147 if (!fgets(buf, BUFSIZ, prog))
149 if (errno && errno != EINTR)
151 strcpy(buf, "Unable to read from program: ");
152 strcat(buf, sys_errlist[errno]);
159 time_s = ctime(&foo) + 4;
160 time_s[strlen(time_s) - 6] = '\0';
161 fprintf(log, "%s %s", time_s, buf);