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>
27 #include <moira_site.h>
33 extern char *sys_siglist[];
44 while (wait3(&stat, WNOHANG, 0) > 0) {
45 if (WIFEXITED(stat)) {
48 "moirad exited with code %d\n",
50 send_zgram("startmoira", buf);
53 if (WIFSIGNALED(stat)) {
54 sprintf(buf, "moirad exited on %s signal%s\n",
55 sys_siglist[stat.w_termsig],
56 (stat.w_coredump?"; Core dumped":0));
57 if(stat.w_coredump) send_zgram("startmoira", buf);
59 write(rdpipe[1], buf, strlen(buf));
71 int logf, inf, i, done, pid, tty;
74 extern char *sys_errlist[];
76 int nfds = getdtablesize();
81 signal(SIGCHLD, cleanup);
83 sprintf(buf, "%s/moira.log", SMS_DIR);
84 logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
89 inf = open("/dev/null", O_RDONLY , 0);
106 tty = open("/dev/tty");
107 ioctl(tty, TIOCNOTTY, 0);
109 sprintf(buf, "%s/%s", BIN_DIR, PROG);
111 if ((pid = fork()) == 0) {
116 for (i = 3; i <nfds; i++) close(i);
118 perror("cannot run moirad");
122 perror("moira_starter");
126 log = fdopen(logf, "w");
127 prog = fdopen(rdpipe[0], "r");
132 extern char *ctime();
137 if (fgets(buf, BUFSIZ, prog) == NULL) {
139 strcpy(buf, "Unable to read from program: ");
140 strcat(buf, sys_errlist[errno]);
145 time_s = ctime(&foo)+4;
146 time_s[strlen(time_s)-6]='\0';
147 fprintf(log, "%s %s", time_s, buf);