]> andersk Git - moira.git/blob - update/exec_002.c
86dc35c9a66c4a221e0185b11b933fc1357ed053
[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         execlp(str, str, (char *)NULL);
48         n = errno;
49         sigsetmask(mask);
50         log_priority = log_ERROR;
51         com_err(whoami, n, ": %s", str);
52         (void) send_object(conn, (char *)&n, INTEGER_T);
53         exit(1);
54     default:
55         do {
56             n = wait(&waitb);
57         } while (n != -1 && n != pid);
58         sigsetmask(mask);
59         if (waitb.w_status) {
60             n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
61             log_priority = log_ERROR;
62             com_err(whoami, n, " child exited with status %d", waitb.w_retcode);
63             code = send_object(conn, (char *)&n, INTEGER_T);
64             if (code) {
65                 exit(1);
66             }
67         } else {
68             code = send_ok();
69             if (code)
70               exit(1);
71         }
72     }
73 }
This page took 0.031912 seconds and 3 git commands to generate.