]> andersk Git - moira.git/blob - update/exec_002.c
make sure exec program runs with sigchild enabled
[moira.git] / update / exec_002.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /*  For copying and distribution information, please see the file */
7 /*  <mit-copyright.h>. */
8
9 #ifndef lint
10 static char *rcsid_exec_002_c = "$Header$";
11 #endif  lint
12
13 #include <mit-copyright.h>
14 #include <stdio.h>
15 #include <sys/wait.h>
16 #include <signal.h>
17 #include <gdb.h>
18 #include <moira.h>
19 #include "update.h"
20
21 extern CONNECTION conn;
22 extern int code, errno;
23
24 int
25 exec_002(str)
26     char *str;
27 {
28     union wait waitb;
29     int n, pid, mask;
30
31     str += 8;
32     while (*str == ' ')
33         str++;
34     mask = sigblock(sigmask(SIGCHLD));
35     pid = fork();
36     switch (pid) {
37     case -1:
38         n = errno;
39         sigsetmask(mask);
40         log_priority = log_ERROR;
41         com_err(whoami, errno, ": can't fork to run install script");
42         code = send_object(conn, (char *)&n, INTEGER_T);
43         if (code)
44             exit(1);
45         return;
46     case 0:
47         sigsetmask(mask);
48         execlp(str, str, (char *)NULL);
49         n = errno;
50         sigsetmask(mask);
51         log_priority = log_ERROR;
52         com_err(whoami, n, ": %s", str);
53         (void) send_object(conn, (char *)&n, INTEGER_T);
54         exit(1);
55     default:
56         do {
57             n = wait(&waitb);
58         } while (n != -1 && n != pid);
59         sigsetmask(mask);
60         if (waitb.w_status) {
61             n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
62             log_priority = log_ERROR;
63             com_err(whoami, n, " child exited with status %d", waitb.w_retcode);
64             code = send_object(conn, (char *)&n, INTEGER_T);
65             if (code) {
66                 exit(1);
67             }
68         } else {
69             code = send_ok();
70             if (code)
71               exit(1);
72         }
73     }
74 }
This page took 0.382394 seconds and 5 git commands to generate.