]> andersk Git - moira.git/blame - update/exec_002.c
remove references to dcm.h
[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$";
7da203a3 11#endif
de56407f 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;
994657b2 30extern int code, errno, uid, log_priority, have_authorization;
8b3ba58e 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
994657b2 51 if (!have_authorization) {
52 reject_call(MR_PERM);
53 return(0);
54 }
8b3ba58e 55 if (config_lookup("noexec")) {
56 code = EPERM;
585b298c 57 send_object(conn, (char *)&code, INTEGER_T);
8b3ba58e 58 com_err(whoami, code, "Not allowed to execute");
984bd8ef 59 return(0);
8b3ba58e 60 }
de56407f 61 str += 8;
62 while (*str == ' ')
63 str++;
8a7d0639 64#ifdef POSIX
65 sigemptyset(&mask);
66 sigaddset(&mask,SIGCHLD);
67 sigprocmask(SIG_BLOCK,&mask,&oldmask);
68#else
6143ee87 69 mask = sigblock(sigmask(SIGCHLD));
8a7d0639 70#endif
de56407f 71 pid = fork();
72 switch (pid) {
73 case -1:
74 n = errno;
8a7d0639 75#ifdef POSIX
76 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
77#else
6143ee87 78 sigsetmask(mask);
8a7d0639 79#endif
de56407f 80 log_priority = log_ERROR;
81 com_err(whoami, errno, ": can't fork to run install script");
82 code = send_object(conn, (char *)&n, INTEGER_T);
83 if (code)
84 exit(1);
984bd8ef 85 return(0);
de56407f 86 case 0:
8b3ba58e 87 if (setuid(uid) < 0) {
88 com_err(whoami, errno, "Unable to setuid to %d\n", uid);
89 exit(1);
90 }
8a7d0639 91#ifdef POSIX
92 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
93#else
e19df9fb 94 sigsetmask(mask);
8a7d0639 95#endif
de56407f 96 execlp(str, str, (char *)NULL);
97 n = errno;
8a7d0639 98#ifdef POSIX
99 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
100#else
6143ee87 101 sigsetmask(mask);
8a7d0639 102#endif
de56407f 103 log_priority = log_ERROR;
104 com_err(whoami, n, ": %s", str);
105 (void) send_object(conn, (char *)&n, INTEGER_T);
106 exit(1);
107 default:
108 do {
109 n = wait(&waitb);
110 } while (n != -1 && n != pid);
8a7d0639 111#ifdef POSIX
112 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
113#else
6143ee87 114 sigsetmask(mask);
8a7d0639 115#endif
116#ifdef POSIX
4aba574b 117 if ( (WIFEXITED(waitb) && (WEXITSTATUS(waitb)!=0)) || WIFSIGNALED(waitb) ) {
de56407f 118 log_priority = log_ERROR;
585b298c 119 if (WIFSIGNALED(waitb)) {
120 n = MR_COREDUMP;
121 com_err(whoami, n, " child exited on signal %d",
122 WTERMSIG(waitb));
123 } else {
124 n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
125 com_err(whoami, n, " child exited with status %d",
126 WEXITSTATUS(waitb));
127 }
8a7d0639 128#else
129 if (waitb.w_status) {
130 n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
131 log_priority = log_ERROR;
132 com_err(whoami, n, " child exited with status %d",
133 waitb.w_retcode);
134#endif
de56407f 135 code = send_object(conn, (char *)&n, INTEGER_T);
c8dc853f 136 if (code) {
de56407f 137 exit(1);
c8dc853f 138 }
139 } else {
de56407f 140 code = send_ok();
141 if (code)
c8dc853f 142 exit(1);
de56407f 143 }
144 }
145}
This page took 1.105977 seconds and 5 git commands to generate.