]> andersk Git - moira.git/blob - update/exec_002.c
Solaris changes
[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 <errno.h>
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 #include <signal.h>
19 #include <gdb.h>
20 #include <moira.h>
21 #include "update.h"
22
23 extern CONNECTION conn;
24 extern int code, errno, uid;
25 extern char *whoami;
26
27 #if defined(vax) || defined(ibm032)
28 #define WEXITSTATUS(waitb) ((waitb).w_retcode)
29 #endif
30
31
32 int
33 exec_002(str)
34     char *str;
35 {
36 #ifdef _AIX
37     int waitb;
38 #else
39     union wait waitb;
40 #endif
41     int n, pid, mask;
42
43     if (config_lookup("noexec")) {
44         code = EPERM;
45         code = send_object(conn, (char *)&code, INTEGER_T);
46         com_err(whoami, code, "Not allowed to execute");
47         return(0);
48     }
49     str += 8;
50     while (*str == ' ')
51         str++;
52     mask = sigblock(sigmask(SIGCHLD));
53     pid = fork();
54     switch (pid) {
55     case -1:
56         n = errno;
57         sigsetmask(mask);
58         log_priority = log_ERROR;
59         com_err(whoami, errno, ": can't fork to run install script");
60         code = send_object(conn, (char *)&n, INTEGER_T);
61         if (code)
62             exit(1);
63         return(0);
64     case 0:
65         if (setuid(uid) < 0) {
66             com_err(whoami, errno, "Unable to setuid to %d\n", uid);
67             exit(1);
68         }
69         sigsetmask(mask);
70         execlp(str, str, (char *)NULL);
71         n = errno;
72         sigsetmask(mask);
73         log_priority = log_ERROR;
74         com_err(whoami, n, ": %s", str);
75         (void) send_object(conn, (char *)&n, INTEGER_T);
76         exit(1);
77     default:
78         do {
79             n = wait(&waitb);
80         } while (n != -1 && n != pid);
81         sigsetmask(mask);
82         if (WEXITSTATUS(waitb)) {
83             n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
84             log_priority = log_ERROR;
85             com_err(whoami, n, " child exited with status %d",
86                     WEXITSTATUS(waitb));
87             code = send_object(conn, (char *)&n, INTEGER_T);
88             if (code) {
89                 exit(1);
90             }
91         } else {
92             code = send_ok();
93             if (code)
94               exit(1);
95         }
96     }
97 }
This page took 0.043416 seconds and 5 git commands to generate.