diff options
Diffstat (limited to 'readconf.c')
-rw-r--r-- | readconf.c | 19 |
1 files changed, 4 insertions, 15 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: readconf.c,v 1.336 2020/10/03 08:30:47 djm Exp $ */ +/* $OpenBSD: readconf.c,v 1.337 2020/10/03 09:22:26 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -509,7 +509,7 @@ execute_in_shell(const char *cmd) { char *shell; pid_t pid; - int devnull, status; + int status; if ((shell = getenv("SHELL")) == NULL) shell = _PATH_BSHELL; @@ -519,23 +519,14 @@ execute_in_shell(const char *cmd) shell, strerror(errno)); } - /* Need this to redirect subprocess stdin/out */ - if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) - fatal("open(/dev/null): %s", strerror(errno)); - debug("Executing command: '%.500s'", cmd); /* Fork and execute the command. */ if ((pid = fork()) == 0) { char *argv[4]; - /* Redirect child stdin and stdout. Leave stderr */ - if (dup2(devnull, STDIN_FILENO) == -1) - fatal("dup2: %s", strerror(errno)); - if (dup2(devnull, STDOUT_FILENO) == -1) - fatal("dup2: %s", strerror(errno)); - if (devnull > STDERR_FILENO) - close(devnull); + if (stdfd_devnull(1, 1, 0) == -1) + fatal("%s: stdfd_devnull failed", __func__); closefrom(STDERR_FILENO + 1); argv[0] = shell; @@ -554,8 +545,6 @@ execute_in_shell(const char *cmd) if (pid == -1) fatal("%s: fork: %.100s", __func__, strerror(errno)); - close(devnull); - while (waitpid(pid, &status, 0) == -1) { if (errno != EINTR && errno != EAGAIN) fatal("%s: waitpid: %s", __func__, strerror(errno)); |