]> andersk Git - moira.git/blob - update/exec_002.c
lint
[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 POSIX
37     int waitb;
38     sigset_t mask,oldmask;
39 #else
40     union wait waitb;
41     int mask;
42 #endif
43     int n, pid;
44
45     if (config_lookup("noexec")) {
46         code = EPERM;
47         code = send_object(conn, (char *)&code, INTEGER_T);
48         com_err(whoami, code, "Not allowed to execute");
49         return(0);
50     }
51     str += 8;
52     while (*str == ' ')
53         str++;
54 #ifdef POSIX
55     sigemptyset(&mask);
56     sigaddset(&mask,SIGCHLD);
57     sigprocmask(SIG_BLOCK,&mask,&oldmask);
58 #else
59     mask = sigblock(sigmask(SIGCHLD));
60 #endif
61     pid = fork();
62     switch (pid) {
63     case -1:
64         n = errno;
65 #ifdef POSIX
66         sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
67 #else
68         sigsetmask(mask);
69 #endif
70         log_priority = log_ERROR;
71         com_err(whoami, errno, ": can't fork to run install script");
72         code = send_object(conn, (char *)&n, INTEGER_T);
73         if (code)
74             exit(1);
75         return(0);
76     case 0:
77         if (setuid(uid) < 0) {
78             com_err(whoami, errno, "Unable to setuid to %d\n", uid);
79             exit(1);
80         }
81 #ifdef POSIX
82         sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
83 #else
84         sigsetmask(mask);
85 #endif
86         execlp(str, str, (char *)NULL);
87         n = errno;
88 #ifdef POSIX
89         sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
90 #else
91         sigsetmask(mask);
92 #endif
93         log_priority = log_ERROR;
94         com_err(whoami, n, ": %s", str);
95         (void) send_object(conn, (char *)&n, INTEGER_T);
96         exit(1);
97     default:
98         do {
99             n = wait(&waitb);
100         } while (n != -1 && n != pid);
101 #ifdef POSIX
102         sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
103 #else
104         sigsetmask(mask);
105 #endif
106 #ifdef POSIX
107         if (WIFEXITED(waitb)) {
108             n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
109             log_priority = log_ERROR;
110             com_err(whoami, n, " child exited with status %d",
111                     WEXITSTATUS(waitb));
112 #else
113         if (waitb.w_status) {
114             n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
115             log_priority = log_ERROR;
116             com_err(whoami, n, " child exited with status %d",
117                     waitb.w_retcode);
118 #endif
119             code = send_object(conn, (char *)&n, INTEGER_T);
120             if (code) {
121                 exit(1);
122             }
123         } else {
124             code = send_ok();
125             if (code)
126               exit(1);
127         }
128     }
129 }
This page took 0.14132 seconds and 5 git commands to generate.