3 * This program starts the moira server in a "clean" environment.
4 * and then waits for it to exit.
6 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
15 #include <sys/resource.h>
35 int stat, serrno = errno;
40 while (waitpid(-1, &stat, WNOHANG) > 0)
44 if (WEXITSTATUS(stat))
46 sprintf(buf, "exited with code %d\n", WEXITSTATUS(stat));
47 critical_alert("startmoira", "%s", buf);
50 if (WIFSIGNALED(stat))
52 sprintf(buf, "exited on signal %d%s\n", WTERMSIG(stat),
53 (WCOREDUMP(stat) ? "; Core dumped" : ""));
55 critical_alert("startmoira", "%s", buf);
57 write(rdpipe[1], buf, strlen(buf));
63 int main(int argc, char *argv[])
67 int logf, inf, i, done, pid;
70 struct sigaction action;
75 getrlimit(RLIMIT_NOFILE, &rl);
78 action.sa_handler = cleanup;
80 sigemptyset(&action.sa_mask);
81 sigaction(SIGCHLD, &action, NULL);
83 sprintf(buf, "%s/moira.log", MOIRA_DIR);
84 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
90 inf = open("/dev/null", O_RDONLY , 0);
108 sprintf(buf, "%s/%s", BIN_DIR, PROG);
110 if ((pid = fork()) == 0)
115 for (i = 3; i < nfds; i++)
118 perror("cannot run moirad");
123 perror("moira_starter");
127 log = fdopen(logf, "w");
128 prog = fdopen(rdpipe[0], "r");
137 if (!fgets(buf, BUFSIZ, prog))
139 if (errno && errno != EINTR)
141 strcpy(buf, "Unable to read from program: ");
142 strcat(buf, strerror(errno));
149 time_s = ctime(&foo) + 4;
150 time_s[strlen(time_s) - 6] = '\0';
151 fprintf(log, "%s %s", time_s, buf);