]> andersk Git - moira.git/blame - update/exec_002.c
posixify source
[moira.git] / update / exec_002.c
CommitLineData
de56407f 1/*
2 * $Source$
3 * $Header$
4 */
546bc43b 5/* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6/* For copying and distribution information, please see the file */
7/* <mit-copyright.h>. */
de56407f 8
9#ifndef lint
10static char *rcsid_exec_002_c = "$Header$";
11#endif lint
12
546bc43b 13#include <mit-copyright.h>
de56407f 14#include <stdio.h>
8b3ba58e 15#include <errno.h>
c57b6bd3 16#include <sys/types.h>
c91c8276 17#ifdef _AIX
18#undef _BSD
19#endif
de56407f 20#include <sys/wait.h>
c91c8276 21#ifdef _AIX
22#define _BSD 44
23#endif
6143ee87 24#include <signal.h>
c8dc853f 25#include <gdb.h>
2ad0a777 26#include <moira.h>
de56407f 27#include "update.h"
de56407f 28
29extern CONNECTION conn;
8b3ba58e 30extern int code, errno, uid;
31extern char *whoami;
32
984bd8ef 33#if defined(vax) || defined(ibm032)
34#define WEXITSTATUS(waitb) ((waitb).w_retcode)
35#endif
36
de56407f 37
38int
39exec_002(str)
40 char *str;
41{
8a7d0639 42#ifdef POSIX
984bd8ef 43 int waitb;
8a7d0639 44 sigset_t mask,oldmask;
984bd8ef 45#else
de56407f 46 union wait waitb;
8a7d0639 47 int mask;
984bd8ef 48#endif
8a7d0639 49 int n, pid;
de56407f 50
8b3ba58e 51 if (config_lookup("noexec")) {
52 code = EPERM;
53 code = send_object(conn, (char *)&code, INTEGER_T);
54 com_err(whoami, code, "Not allowed to execute");
984bd8ef 55 return(0);
8b3ba58e 56 }
de56407f 57 str += 8;
58 while (*str == ' ')
59 str++;
8a7d0639 60#ifdef POSIX
61 sigemptyset(&mask);
62 sigaddset(&mask,SIGCHLD);
63 sigprocmask(SIG_BLOCK,&mask,&oldmask);
64#else
6143ee87 65 mask = sigblock(sigmask(SIGCHLD));
8a7d0639 66#endif
de56407f 67 pid = fork();
68 switch (pid) {
69 case -1:
70 n = errno;
8a7d0639 71#ifdef POSIX
72 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
73#else
6143ee87 74 sigsetmask(mask);
8a7d0639 75#endif
de56407f 76 log_priority = log_ERROR;
77 com_err(whoami, errno, ": can't fork to run install script");
78 code = send_object(conn, (char *)&n, INTEGER_T);
79 if (code)
80 exit(1);
984bd8ef 81 return(0);
de56407f 82 case 0:
8b3ba58e 83 if (setuid(uid) < 0) {
84 com_err(whoami, errno, "Unable to setuid to %d\n", uid);
85 exit(1);
86 }
8a7d0639 87#ifdef POSIX
88 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
89#else
e19df9fb 90 sigsetmask(mask);
8a7d0639 91#endif
de56407f 92 execlp(str, str, (char *)NULL);
93 n = errno;
8a7d0639 94#ifdef POSIX
95 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
96#else
6143ee87 97 sigsetmask(mask);
8a7d0639 98#endif
de56407f 99 log_priority = log_ERROR;
100 com_err(whoami, n, ": %s", str);
101 (void) send_object(conn, (char *)&n, INTEGER_T);
102 exit(1);
103 default:
104 do {
105 n = wait(&waitb);
106 } while (n != -1 && n != pid);
8a7d0639 107#ifdef POSIX
108 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
109#else
6143ee87 110 sigsetmask(mask);
8a7d0639 111#endif
112#ifdef POSIX
113 if (WIFEXITED(waitb)) {
984bd8ef 114 n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
de56407f 115 log_priority = log_ERROR;
984bd8ef 116 com_err(whoami, n, " child exited with status %d",
117 WEXITSTATUS(waitb));
8a7d0639 118#else
119 if (waitb.w_status) {
120 n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
121 log_priority = log_ERROR;
122 com_err(whoami, n, " child exited with status %d",
123 waitb.w_retcode);
124#endif
de56407f 125 code = send_object(conn, (char *)&n, INTEGER_T);
c8dc853f 126 if (code) {
de56407f 127 exit(1);
c8dc853f 128 }
129 } else {
de56407f 130 code = send_ok();
131 if (code)
c8dc853f 132 exit(1);
de56407f 133 }
134 }
135}
This page took 0.388375 seconds and 5 git commands to generate.