]> andersk Git - moira.git/blobdiff - update/exec_002.c
Code style cleanup. (No functional changes)
[moira.git] / update / exec_002.c
index fcf0d96ff1437003f3b94aada4c684f686e65d80..50f817392d5789c585222dc8962a941b7f225be5 100644 (file)
@@ -14,13 +14,7 @@ static char *rcsid_exec_002_c = "$Header$";
 #include <stdio.h>
 #include <errno.h>
 #include <sys/types.h>
-#ifdef _AIX
-#undef _BSD
-#endif
 #include <sys/wait.h>
-#ifdef _AIX
-#define _BSD 44
-#endif
 #include <signal.h>
 #include <gdb.h>
 #include <moira.h>
@@ -30,116 +24,86 @@ extern CONNECTION conn;
 extern int code, errno, uid, log_priority, have_authorization;
 extern char *whoami;
 
-#if defined(vax) || defined(ibm032)
-#define WEXITSTATUS(waitb) ((waitb).w_retcode)
-#endif
-
-
-int
-exec_002(str)
-    char *str;
+int exec_002(char *str)
 {
-#ifdef POSIX
-    int waitb;
-    sigset_t mask,oldmask;
-#else
-    union wait waitb;
-    int mask;
-#endif
-    int n, pid;
+  int waitb;
+  sigset_t mask, oldmask;
+  int n, pid;
 
-    if (!have_authorization) {
-       reject_call(MR_PERM);
-       return(0);
+  if (!have_authorization)
+    {
+      reject_call(MR_PERM);
+      return 0;
     }
-    if (config_lookup("noexec")) {
-       code = EPERM;
-       send_object(conn, (char *)&code, INTEGER_T);
-       com_err(whoami, code, "Not allowed to execute");
-       return(0);
+  if (config_lookup("noexec"))
+    {
+      code = EPERM;
+      send_object(conn, (char *)&code, INTEGER_T);
+      com_err(whoami, code, "Not allowed to execute");
+      return 0;
     }
-    str += 8;
-    while (*str == ' ')
-       str++;
-#ifdef POSIX
-    sigemptyset(&mask);
-    sigaddset(&mask,SIGCHLD);
-    sigprocmask(SIG_BLOCK,&mask,&oldmask);
-#else
-    mask = sigblock(sigmask(SIGCHLD));
-#endif
-    pid = fork();
-    switch (pid) {
+  str += 8;
+  while (*str == ' ')
+    str++;
+  sigemptyset(&mask);
+  sigaddset(&mask, SIGCHLD);
+  sigprocmask(SIG_BLOCK, &mask, &oldmask);
+  pid = fork();
+  switch (pid)
+    {
     case -1:
-       n = errno;
-#ifdef POSIX
-       sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
-#else
-       sigsetmask(mask);
-#endif
-       log_priority = log_ERROR;
-       com_err(whoami, errno, ": can't fork to run install script");
-       code = send_object(conn, (char *)&n, INTEGER_T);
-       if (code)
-           exit(1);
-       return(0);
+      n = errno;
+      sigprocmask(SIG_UNBLOCK, &oldmask, &mask);
+      log_priority = log_ERROR;
+      com_err(whoami, errno, ": can't fork to run install script");
+      code = send_object(conn, (char *)&n, INTEGER_T);
+      if (code)
+       exit(1);
+      return 0;
     case 0:
-       if (setuid(uid) < 0) {
-           com_err(whoami, errno, "Unable to setuid to %d\n", uid);
-           exit(1);
+      if (setuid(uid) < 0)
+       {
+         com_err(whoami, errno, "Unable to setuid to %d\n", uid);
+         exit(1);
        }
-#ifdef POSIX
-       sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
-#else
-       sigsetmask(mask);
-#endif
-       execlp(str, str, (char *)NULL);
-       n = errno;
-#ifdef POSIX
-       sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
-#else
-       sigsetmask(mask);
-#endif
-       log_priority = log_ERROR;
-       com_err(whoami, n, ": %s", str);
-       (void) send_object(conn, (char *)&n, INTEGER_T);
-       exit(1);
+      sigprocmask(SIG_UNBLOCK, &oldmask, &mask);
+      execlp(str, str, NULL);
+      n = errno;
+      sigprocmask(SIG_UNBLOCK, &oldmask, &mask);
+      log_priority = log_ERROR;
+      com_err(whoami, n, ": %s", str);
+      send_object(conn, (char *)&n, INTEGER_T);
+      exit(1);
     default:
-       do {
-           n = wait(&waitb);
-       } while (n != -1 && n != pid);
-#ifdef POSIX
-       sigprocmask(SIG_UNBLOCK,&oldmask,&mask);
-#else
-       sigsetmask(mask);
-#endif
-#ifdef POSIX
-       if ( (WIFEXITED(waitb) && (WEXITSTATUS(waitb)!=0)) || WIFSIGNALED(waitb)  ) {
-           log_priority = log_ERROR;
-           if (WIFSIGNALED(waitb)) {
-               n = MR_COREDUMP;
-               com_err(whoami, n, " child exited on signal %d",
-                       WTERMSIG(waitb));
-           } else {
-               n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
-               com_err(whoami, n, " child exited with status %d",
-                       WEXITSTATUS(waitb));
+      do
+       n = wait(&waitb);
+      while (n != -1 && n != pid);
+      sigprocmask(SIG_UNBLOCK, &oldmask, &mask);
+      if ((WIFEXITED(waitb) && (WEXITSTATUS(waitb) != 0)) ||
+         WIFSIGNALED(waitb))
+       {
+         log_priority = log_ERROR;
+         if (WIFSIGNALED(waitb))
+           {
+             n = MR_COREDUMP;
+             com_err(whoami, n, " child exited on signal %d",
+                     WTERMSIG(waitb));
            }
-#else
-       if (waitb.w_status) {
-           n = waitb.w_retcode + ERROR_TABLE_BASE_sms;
-           log_priority = log_ERROR;
-           com_err(whoami, n, " child exited with status %d",
-                   waitb.w_retcode);
-#endif
-           code = send_object(conn, (char *)&n, INTEGER_T);
-           if (code) {
-               exit(1);
+         else
+           {
+             n = WEXITSTATUS(waitb) + ERROR_TABLE_BASE_sms;
+             com_err(whoami, n, " child exited with status %d",
+                     WEXITSTATUS(waitb));
            }
-       } else {
-           code = send_ok();
-           if (code)
-             exit(1);
+         code = send_object(conn, (char *)&n, INTEGER_T);
+         if (code)
+           exit(1);
+       }
+      else
+       {
+         code = send_ok();
+         if (code)
+           exit(1);
        }
     }
 }
This page took 0.06088 seconds and 4 git commands to generate.