]> git.tuebingen.mpg.de Git - micoforia.git/commitdiff
Simplify xexec().
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 22 Mar 2025 18:26:07 +0000 (19:26 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 22 Mar 2025 19:29:10 +0000 (20:29 +0100)
Nobody passes in a non-NULL iov.

m7a.h
micoforia.c
util.c

diff --git a/m7a.h b/m7a.h
index 77c3cad6fb67dfabfbe2c6da2954d2c3740f1c3a..f220ffc6688a0fcf901083b8fed806259ea511fb 100644 (file)
--- a/m7a.h
+++ b/m7a.h
@@ -84,7 +84,7 @@ void die_empty_arg(const char *opt);
 
 void check_range(uint32_t val, uint32_t min, uint32_t max, const char *opt);
 
-bool xexec(char * const argv[], const struct iovec *iov);
+bool xexec(char * const argv[]);
 void valid_fd012(void);
 void check_name(const char *arg);
 void parse_compound_arg(const char *arg, const char *opt, char **name, char **val);
index 9afd269c1d5d18c05d6b55d4c47934a0454a2b2a..d23566c153ef20b605c860f668d4417beb6ef7c6 100644 (file)
@@ -598,7 +598,7 @@ static bool run_pre_start_hook(const struct container *c)
        free(ifspec);
 
        INFO_LOG("running pre-start hook %s\n", cmd);
-       success = xexec(argv, NULL);
+       success = xexec(argv);
        free(cmd);
        if (!success)
                ERROR_LOG("pre-start hook failed\n");
@@ -615,7 +615,7 @@ static void run_pre_exec_hook(const struct container *c)
 
        INFO_LOG("/bin/sh -c '%s'\n", cmd);
        set_m7a_root_dir_env(c);
-       if (!xexec(argv, NULL))
+       if (!xexec(argv))
                die("%s: pre-exec hook failed", c->name);
        free(cmd);
        unsetenv("MICOFORIA_ROOT_DIR");
@@ -1777,7 +1777,7 @@ static bool list_container_processes(const struct container *c)
        if (!OPT_GIVEN(PS, ALL) && !request_init_pid(c->name, &pid))
                return false;
        sprintf(str, "%d", pid);
-       success = xexec(argv, NULL);
+       success = xexec(argv);
        return success;
 }
 
@@ -1909,7 +1909,7 @@ static bool com_edit(void)
        char *ed = getenv("EDITOR"); /* must not be freed */
        char *conf = get_config_file_path();
        char *argv[] = {ed? ed : "vi", conf, NULL};
-       bool success = xexec(argv, NULL);
+       bool success = xexec(argv);
 
        free(conf);
        return success;
@@ -1960,7 +1960,7 @@ static bool com_enter(void)
                if (tcgetattr(STDIN_FILENO, &tios) >= 0)
                        tty = true;
        }
-       success = xexec(argv, NULL);
+       success = xexec(argv);
        if (tty) { /* reset terminal settings */
                /*
                 * First give up the controlling terminal. Without this, the
@@ -1987,7 +1987,7 @@ static bool com_log(void)
                die_lopsub(ret, &errctx);
        logfile = get_container_logfile(lls_input(0, sublpr));
                argv[1] = logfile;
-       success = xexec(argv, NULL);
+       success = xexec(argv);
        free(logfile);
        return success;
 }
diff --git a/util.c b/util.c
index 08f4832956d5ed1e6003d86b37494bb2a69793e7..997f9eb194f8e5474874ed6c24ed25f1f2975178 100644 (file)
--- a/util.c
+++ b/util.c
@@ -156,45 +156,25 @@ bool fd2buf(int fd, const struct iovec *iov)
        }
 }
 
-bool xexec(char * const argv[], const struct iovec *iov)
+bool xexec(char * const argv[])
 {
        pid_t pid;
-       int pipefd[2] = {-1, -1};
        unsigned n;
 
        for (n = 0; argv[n]; n++)
                DEBUG_LOG("argv[%u]=%s\n", n, argv[n]);
-       if (iov) {
-               if (pipe(pipefd) < 0)
-                       die_errno("pipe");
-       }
        if ((pid = fork()) < 0)
                die_errno("fork");
        if (pid > 0) { /* parent */
                int wstatus;
-               bool success = true;
-               if (iov) {
-                       close(pipefd[1]);
-                       success = fd2buf(pipefd[0], iov);
-                       close(pipefd[0]);
-               }
                if (waitpid(pid, &wstatus, 0) < 0)
                        die_errno("waitp");
-               if (!success)
-                       return false;
                if (!WIFEXITED(wstatus))
                        return false;
                if (WEXITSTATUS(wstatus) != EXIT_SUCCESS)
                        return false;
                return true;
        }
-       if (pipefd[0] >= 0)
-               close(pipefd[0]);
-       if (pipefd[1] >= 0 && pipefd[1] != STDOUT_FILENO) {
-               if (dup2(pipefd[1], STDOUT_FILENO) < 0)
-                       die_errno("dup2()");
-               close(pipefd[1]);
-       }
        execvp(argv[0], argv);
        EMERG_LOG("execvp error: %s\n", strerror(errno));
        _exit(EXIT_FAILURE);