Merge branch 'refs/heads/t/openssl-header-check'
[paraslash.git] / exec.c
diff --git a/exec.c b/exec.c
index bbf1b41addf8aab65363065c9e3b6ad91cae4968..85dbaf9474aa286add74cd761f09d30dc74ad805 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1,13 +1,12 @@
-/*
- * Copyright (C) 2003-2008 Andre Noll <maan@systemlinux.org>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2003 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file exec.c Helper functions for spawning new processes. */
+
+#include <regex.h>
+
 #include "para.h"
-#include "close_on_fork.h"
 #include "error.h"
+#include "fd.h"
 #include "string.h"
 
 /**
@@ -35,15 +34,18 @@ static int para_exec(pid_t *pid, const char *file, char *const *const args, int
        if (fds[2] > 0 && pipe(err) < 0)
                goto err_out;
        if (!fds[0] || !fds[1] || !fds[2]) {
-               ret = -E_NULL_OPEN;
-               null = open("/dev/null", O_RDONLY);
-               if (null < 0)
+               ret = para_open("/dev/null", O_RDWR, 42);
+               if (ret < 0)
                        goto err_out;
+               null = ret;
+       }
+       ret = fork();
+       if (ret < 0) {
+               ret = -ERRNO_TO_PARA_ERROR(errno);
+               goto err_out;
        }
-       if ((*pid = fork()) < 0)
-               exit(EXIT_FAILURE);
+       *pid = ret;
        if (!(*pid)) { /* child */
-               close_listed_fds(); /* close unneeded fds */
                if (fds[0] >= 0) {
                        if (fds[0]) {
                                close(in[1]);
@@ -103,6 +105,7 @@ err_out:
                close(in[1]);
        if (null >= 0)
                close(null);
+       PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        return ret;
 }
 
@@ -110,7 +113,7 @@ err_out:
  * Exec the given command.
  *
  * \param pid Will hold the pid of the created process upon return.
- * \param cmdline Holds the command and its arguments, seperated by spaces.
+ * \param cmdline Holds the command and its arguments, separated by spaces.
  * \param fds A pointer to a value-result array.
  *
  * This function uses fork/exec to create a new process. \a fds must be a
@@ -123,21 +126,19 @@ err_out:
  *     - fd[i] > 0: create a pipe and dup i to one end of that pipe.
  *     Upon return, fd[i] contains the file descriptor of the pipe.
  *
- *     In any case, all unneeded filedescriptors are closed.
+ *     In any case, all unneeded file descriptors are closed.
  *
  * \return Standard.
  */
 int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds)
 {
-       int argc, ret;
+       int ret;
        char **argv;
-       char *tmp = para_strdup(cmdline);
 
-       if (!tmp)
-               exit(EXIT_FAILURE);
-       argc = split_args(tmp, &argv, " \t");
+       ret = create_argv(cmdline, " \t", &argv);
+       if (ret < 0)
+               return ret;
        ret = para_exec(pid, argv[0], argv, fds);
-       free(argv);
-       free(tmp);
+       free_argv(argv);
        return ret;
 }