]> andersk Git - moira.git/blobdiff - update/exec_002.c
Don't coredump on bad input streams (sanity check lengths of received
[moira.git] / update / exec_002.c
index 4f4d06c4438f54aa716300fffb69d0a8b4157674..f0fbbf4636854db5415efda5595f21818ee468b4 100644 (file)
@@ -2,18 +2,22 @@
  *     $Source$
  *     $Header$
  */
+/*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
+/*  For copying and distribution information, please see the file */
+/*  <mit-copyright.h>. */
 
 #ifndef lint
 static char *rcsid_exec_002_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/wait.h>
-#include "gdb.h"
+#include <signal.h>
+#include <gdb.h>
+#include <sms.h>
 #include "update.h"
-#include "sms_update_int.h"
 #include "kludge.h"
-#include "smsu_int.h"
 
 extern CONNECTION conn;
 extern int code, errno;
@@ -23,15 +27,17 @@ exec_002(str)
     char *str;
 {
     union wait waitb;
-    int n, pid;
+    int n, pid, mask;
 
     str += 8;
     while (*str == ' ')
        str++;
+    mask = sigblock(sigmask(SIGCHLD));
     pid = fork();
     switch (pid) {
     case -1:
        n = errno;
+       sigsetmask(mask);
        log_priority = log_ERROR;
        com_err(whoami, errno, ": can't fork to run install script");
        code = send_object(conn, (char *)&n, INTEGER_T);
@@ -41,6 +47,7 @@ exec_002(str)
     case 0:
        execlp(str, str, (char *)NULL);
        n = errno;
+       sigsetmask(mask);
        log_priority = log_ERROR;
        com_err(whoami, n, ": %s", str);
        (void) send_object(conn, (char *)&n, INTEGER_T);
@@ -49,17 +56,19 @@ exec_002(str)
        do {
            n = wait(&waitb);
        } while (n != -1 && n != pid);
+       sigsetmask(mask);
        if (waitb.w_status) {
+           n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
            log_priority = log_ERROR;
-           com_err(whoami, 0, "child exited with status %d", waitb.w_status);
+           com_err(whoami, n, " child exited with status %d", waitb.w_retcode);
            code = send_object(conn, (char *)&n, INTEGER_T);
-           if (code)
+           if (code) {
                exit(1);
-       }
-       else {
+           }
+       else {
            code = send_ok();
            if (code)
-               exit(1);
+             exit(1);
        }
     }
 }
This page took 0.334173 seconds and 4 git commands to generate.