]> andersk Git - moira.git/blame - update/exec_002.c
include <sys/types.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$";
11#endif lint
12
546bc43b 13#include <mit-copyright.h>
de56407f 14#include <stdio.h>
15#include <sys/wait.h>
6143ee87 16#include <signal.h>
c8dc853f 17#include <gdb.h>
2ad0a777 18#include <moira.h>
de56407f 19#include "update.h"
de56407f 20
21extern CONNECTION conn;
22extern int code, errno;
23
24int
25exec_002(str)
26 char *str;
27{
28 union wait waitb;
6143ee87 29 int n, pid, mask;
de56407f 30
31 str += 8;
32 while (*str == ' ')
33 str++;
6143ee87 34 mask = sigblock(sigmask(SIGCHLD));
de56407f 35 pid = fork();
36 switch (pid) {
37 case -1:
38 n = errno;
6143ee87 39 sigsetmask(mask);
de56407f 40 log_priority = log_ERROR;
41 com_err(whoami, errno, ": can't fork to run install script");
42 code = send_object(conn, (char *)&n, INTEGER_T);
43 if (code)
44 exit(1);
45 return;
46 case 0:
e19df9fb 47 sigsetmask(mask);
de56407f 48 execlp(str, str, (char *)NULL);
49 n = errno;
6143ee87 50 sigsetmask(mask);
de56407f 51 log_priority = log_ERROR;
52 com_err(whoami, n, ": %s", str);
53 (void) send_object(conn, (char *)&n, INTEGER_T);
54 exit(1);
55 default:
56 do {
57 n = wait(&waitb);
58 } while (n != -1 && n != pid);
6143ee87 59 sigsetmask(mask);
de56407f 60 if (waitb.w_status) {
b33c0986 61 n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
de56407f 62 log_priority = log_ERROR;
c8dc853f 63 com_err(whoami, n, " child exited with status %d", waitb.w_retcode);
de56407f 64 code = send_object(conn, (char *)&n, INTEGER_T);
c8dc853f 65 if (code) {
de56407f 66 exit(1);
c8dc853f 67 }
68 } else {
de56407f 69 code = send_ok();
70 if (code)
c8dc853f 71 exit(1);
de56407f 72 }
73 }
74}
This page took 0.085858 seconds and 5 git commands to generate.