]> andersk Git - moira.git/blame - update/exec_002.c
Fixes single-quote bug. Really.
[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>
de56407f 17#include <sys/wait.h>
6143ee87 18#include <signal.h>
c8dc853f 19#include <gdb.h>
2ad0a777 20#include <moira.h>
de56407f 21#include "update.h"
de56407f 22
23extern CONNECTION conn;
8b3ba58e 24extern int code, errno, uid;
25extern char *whoami;
26
984bd8ef 27#if defined(vax) || defined(ibm032)
28#define WEXITSTATUS(waitb) ((waitb).w_retcode)
29#endif
30
de56407f 31
32int
33exec_002(str)
34 char *str;
35{
8a7d0639 36#ifdef POSIX
984bd8ef 37 int waitb;
8a7d0639 38 sigset_t mask,oldmask;
984bd8ef 39#else
de56407f 40 union wait waitb;
8a7d0639 41 int mask;
984bd8ef 42#endif
8a7d0639 43 int n, pid;
de56407f 44
8b3ba58e 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");
984bd8ef 49 return(0);
8b3ba58e 50 }
de56407f 51 str += 8;
52 while (*str == ' ')
53 str++;
8a7d0639 54#ifdef POSIX
55 sigemptyset(&mask);
56 sigaddset(&mask,SIGCHLD);
57 sigprocmask(SIG_BLOCK,&mask,&oldmask);
58#else
6143ee87 59 mask = sigblock(sigmask(SIGCHLD));
8a7d0639 60#endif
de56407f 61 pid = fork();
62 switch (pid) {
63 case -1:
64 n = errno;
8a7d0639 65#ifdef POSIX
66 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
67#else
6143ee87 68 sigsetmask(mask);
8a7d0639 69#endif
de56407f 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);
984bd8ef 75 return(0);
de56407f 76 case 0:
8b3ba58e 77 if (setuid(uid) < 0) {
78 com_err(whoami, errno, "Unable to setuid to %d\n", uid);
79 exit(1);
80 }
8a7d0639 81#ifdef POSIX
82 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
83#else
e19df9fb 84 sigsetmask(mask);
8a7d0639 85#endif
de56407f 86 execlp(str, str, (char *)NULL);
87 n = errno;
8a7d0639 88#ifdef POSIX
89 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
90#else
6143ee87 91 sigsetmask(mask);
8a7d0639 92#endif
de56407f 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);
8a7d0639 101#ifdef POSIX
102 sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
103#else
6143ee87 104 sigsetmask(mask);
8a7d0639 105#endif
106#ifdef POSIX
107 if (WIFEXITED(waitb)) {
984bd8ef 108 n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
de56407f 109 log_priority = log_ERROR;
984bd8ef 110 com_err(whoami, n, " child exited with status %d",
111 WEXITSTATUS(waitb));
8a7d0639 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
de56407f 119 code = send_object(conn, (char *)&n, INTEGER_T);
c8dc853f 120 if (code) {
de56407f 121 exit(1);
c8dc853f 122 }
123 } else {
de56407f 124 code = send_ok();
125 if (code)
c8dc853f 126 exit(1);
de56407f 127 }
128 }
129}
This page took 0.097314 seconds and 5 git commands to generate.