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>
22 #include <sys/types.h>
25 #include <sys/signal.h>
26 #include <sys/ioctl.h>
28 #include <sys/resource.h>
29 #include <moira_site.h>
40 int stat, serrno = errno;
45 while (waitpid(-1, &stat, WNOHANG) > 0) {
46 if (WIFEXITED(stat)) {
47 if (WEXITSTATUS(stat)) {
49 "exited with code %d\n",
51 send_zgram("startmoira", buf);
54 if (WIFSIGNALED(stat)) {
55 sprintf(buf, "exited on signal %d%s\n",
57 (WCOREDUMP(stat)?"; Core dumped":0));
58 if(WCOREDUMP(stat)) send_zgram("startmoira", buf);
60 write(rdpipe[1], buf, strlen(buf));
72 int logf, inf, i, done, pid, tty;
76 extern char *sys_errlist[];
78 struct sigaction action;
83 getrlimit(RLIMIT_NOFILE, &rl);
86 action.sa_handler = cleanup;
88 sigemptyset(&action.sa_mask);
89 sigaction(SIGCHLD, &action, NULL);
91 sprintf(buf, "%s/moira.log", SMS_DIR);
92 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
97 inf = open("/dev/null", O_RDONLY , 0);
115 sprintf(buf, "%s/%s", BIN_DIR, PROG);
117 if ((pid = fork()) == 0) {
122 for (i = 3; i <nfds; i++) close(i);
124 perror("cannot run moirad");
128 perror("moira_starter");
132 log = fdopen(logf, "w");
133 prog = fdopen(rdpipe[0], "r");
138 extern char *ctime();
143 if (fgets(buf, BUFSIZ, prog) == NULL) {
144 if (errno && errno!=EINTR) {
145 strcpy(buf, "Unable to read from program: ");
146 strcat(buf, sys_errlist[errno]);
151 time_s = ctime(&foo)+4;
152 time_s[strlen(time_s)-6]='\0';
153 fprintf(log, "%s %s", time_s, buf);