-/*
- * $Source$
- * $Header$
+/* $Id$
+ *
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
-/* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
-/* For copying and distribution information, please see the file */
-/* <mit-copyright.h>. */
-
-#ifndef lint
-static char *rcsid_exec_002_c = "$Header$";
-#endif
#include <mit-copyright.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <gdb.h>
#include <moira.h>
+#include "update_server.h"
#include "update.h"
-extern CONNECTION conn;
-extern int code, errno, uid, log_priority, have_authorization;
-extern char *whoami;
+#include <sys/wait.h>
-int exec_002(char *str)
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+RCSID("$Header$");
+
+void exec_002(int conn, char *str)
{
- int waitb;
+ int waitb, n;
sigset_t mask, oldmask;
- int n, pid;
+ pid_t pid;
+ long code;
if (!have_authorization)
{
- reject_call(MR_PERM);
- return 0;
+ send_int(conn, MR_PERM);
+ return;
}
if (config_lookup("noexec"))
{
- code = EPERM;
- send_object(conn, (char *)&code, INTEGER_T);
- com_err(whoami, code, "Not allowed to execute");
- return 0;
+ send_int(conn, EPERM);
+ com_err(whoami, EPERM, "Not allowed to execute");
+ return;
}
+
str += 8;
while (*str == ' ')
str++;
case -1:
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);
+ com_err(whoami, n, ": can't fork to run install script");
+ code = send_int(conn, n);
if (code)
exit(1);
- return 0;
+ return;
+
case 0:
if (setuid(uid) < 0)
{
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);
+ send_int(conn, n);
exit(1);
+
default:
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 with status %d",
WEXITSTATUS(waitb));
}
- code = send_object(conn, (char *)&n, INTEGER_T);
+ code = send_int(conn, n);
if (code)
exit(1);
}
else
{
- code = send_ok();
+ code = send_ok(conn);
if (code)
exit(1);
}
}
+ return;
}