]> andersk Git - moira.git/blobdiff - server/startmoira.c
Remove `delete_user_by_uid' since it's never been used in any logs we have,
[moira.git] / server / startmoira.c
index f3d85db36ef9f40fa02e38909249b323ba92effd..74cd79ba50b34e6b4d6c368e1f5421065b1e9762 100644 (file)
@@ -17,74 +17,47 @@ static char *rcsid_mr_starter_c = "$Header$";
 #endif lint
 
 #include <mit-copyright.h>
+#include <errno.h>
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/wait.h>
 #include <sys/signal.h>
 #include <sys/ioctl.h>
+#include <time.h>
+#include <fcntl.h>
+#include <sys/resource.h>
 #include <moira_site.h>
 
+
 #define PROG   "moirad"
 
 int rdpipe[2];
-char *sigdescr[] = {
-       0,
-       "hangup",
-       "interrupt",    
-       "quit",
-       "illegal instruction",
-       "trace/BPT trap",
-       "IOT trap",
-       "EMT trap",
-       "floating exception",
-       "kill",
-       "bus error",
-       "segmentation violation",
-       "bad system call",
-       "broken pipe",
-       "alarm clock",
-       "termination",
-       "urgent I/O condition",
-       "stopped",
-       "stopped",
-       "continued",
-       "child exited",
-       "stopped (tty input)",
-       "stopped (tty output)",
-       "I/O possible",
-       "cputime limit exceeded",
-       "filesize limit exceeded",
-       "virtual timer expired",
-       "profiling timer expired",
-       "window size changed",
-       "signal 29",
-       "user defined signal 1",
-       "user defined signal 2",
-       "signal 32"
-};
+extern int errno;
+char *whoami;
 
-cleanup()
+void cleanup()
 {
-       union wait stat;
+       int stat, serrno = errno;
        char buf[BUFSIZ];
-       extern int errno;
-       int serrno = errno;
 
        buf[0]='\0';
        
-       while (wait3(&stat, WNOHANG, 0) > 0) {
+       while (waitpid(-1, &stat, WNOHANG) > 0) {
                if (WIFEXITED(stat)) {
-                       if (stat.w_retcode)
+                       if (WEXITSTATUS(stat)) {
                                sprintf(buf,
                                        "exited with code %d\n",
-                                       stat.w_retcode);
+                                       WEXITSTATUS(stat));
+                               send_zgram("startmoira", buf);
+                       }
                }
                if (WIFSIGNALED(stat)) {
-                       sprintf(buf, "exited on %s signal%s\n",
-                               sigdescr[stat.w_termsig],
-                               (stat.w_coredump?"; Core dumped":0));
+                       sprintf(buf, "exited on signal %d%s\n",
+                               WTERMSIG(stat),
+                               (WCOREDUMP(stat)?"; Core dumped":0));
+                       if(WCOREDUMP(stat)) send_zgram("startmoira", buf);
                }
                write(rdpipe[1], buf, strlen(buf));
                close(rdpipe[1]);
@@ -93,18 +66,29 @@ cleanup()
 }
 
 main(argc, argv)
+     int argc;
+     char *argv[];
 {
        char buf[BUFSIZ];
        FILE *log, *prog;
        int logf, inf, i, done, pid, tty;
+       struct rlimit rl;
        
        extern int errno;
        extern char *sys_errlist[];
        
-       int nfds = getdtablesize();
+       struct sigaction action;
+       int nfds;
        
-       setreuid(0);
-       signal(SIGCHLD, cleanup);
+       whoami = argv[0];
+       
+       getrlimit(RLIMIT_NOFILE, &rl);
+       nfds = rl.rlim_cur;
+
+       action.sa_handler = cleanup;
+       action.sa_flags = 0;
+       sigemptyset(&action.sa_mask);
+       sigaction(SIGCHLD, &action, NULL);
        
        sprintf(buf, "%s/moira.log", SMS_DIR);
        logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
@@ -119,7 +103,7 @@ main(argc, argv)
        }
        pipe(rdpipe);
        if (fork()) {
-               exit();
+               exit(0);
        }
        chdir("/");     
        close(0);
@@ -129,9 +113,7 @@ main(argc, argv)
        dup2(inf, 1);
        dup2(inf, 2);
        
-       tty = open("/dev/tty");
-       ioctl(tty, TIOCNOTTY, 0);
-       close(tty);
+       setpgrp();
        sprintf(buf, "%s/%s", BIN_DIR, PROG);
        
        if ((pid = fork()) == 0) {
@@ -155,13 +137,12 @@ main(argc, argv)
        
        do {
                char *time_s;
-               extern char *ctime();
                long foo;
                
                done = 0;
                errno = 0;
                if (fgets(buf, BUFSIZ, prog) == NULL) {
-                       if (errno) {
+                       if (errno && errno!=EINTR) {
                                strcpy(buf, "Unable to read from program: ");
                                strcat(buf, sys_errlist[errno]);
                                strcat(buf, "\n");
@@ -170,12 +151,8 @@ main(argc, argv)
                time(&foo);
                time_s = ctime(&foo)+4;
                time_s[strlen(time_s)-6]='\0';
-               fprintf(log, "%s <%d> %s", time_s, pid, buf);
+               fprintf(log, "%s %s", time_s, buf);
                fflush(log);
        } while (!done);
        exit(0);
 }
-
-
-
-         
This page took 0.042763 seconds and 4 git commands to generate.