]> andersk Git - moira.git/blob - update/exec_002.c
make it work on sun
[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
28 int
29 exec_002(str)
30     char *str;
31 {
32     union wait waitb;
33     int n, pid, mask;
34
35     if (config_lookup("noexec")) {
36         code = EPERM;
37         code = send_object(conn, (char *)&code, INTEGER_T);
38         com_err(whoami, code, "Not allowed to execute");
39         return;
40     }
41     str += 8;
42     while (*str == ' ')
43         str++;
44     mask = sigblock(sigmask(SIGCHLD));
45     pid = fork();
46     switch (pid) {
47     case -1:
48         n = errno;
49         sigsetmask(mask);
50         log_priority = log_ERROR;
51         com_err(whoami, errno, ": can't fork to run install script");
52         code = send_object(conn, (char *)&n, INTEGER_T);
53         if (code)
54             exit(1);
55         return;
56     case 0:
57         if (setuid(uid) < 0) {
58             com_err(whoami, errno, "Unable to setuid to %d\n", uid);
59             exit(1);
60         }
61         sigsetmask(mask);
62         execlp(str, str, (char *)NULL);
63         n = errno;
64         sigsetmask(mask);
65         log_priority = log_ERROR;
66         com_err(whoami, n, ": %s", str);
67         (void) send_object(conn, (char *)&n, INTEGER_T);
68         exit(1);
69     default:
70         do {
71             n = wait(&waitb);
72         } while (n != -1 && n != pid);
73         sigsetmask(mask);
74         if (waitb.w_status) {
75             n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
76             log_priority = log_ERROR;
77             com_err(whoami, n, " child exited with status %d", waitb.w_retcode);
78             code = send_object(conn, (char *)&n, INTEGER_T);
79             if (code) {
80                 exit(1);
81             }
82         } else {
83             code = send_ok();
84             if (code)
85               exit(1);
86         }
87     }
88 }
This page took 0.042288 seconds and 5 git commands to generate.