summaryrefslogtreecommitdiff
path: root/readconf.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-10-03 09:22:26 +0000
committerDamien Miller <djm@mindrot.org>2020-10-03 19:34:24 +1000
commit396d32f3a1a16e54df2a76b2a9b237868580dcbe (patch)
tree77019a916fcb969986a349aaede7409a25778b6a /readconf.c
parent1286981d08b8429a64613215ce8bff3f6b32488a (diff)
downloadopenssh-git-396d32f3a1a16e54df2a76b2a9b237868580dcbe.tar.gz
upstream: There are lots of place where we want to redirect stdin,
stdout and/or stderr to /dev/null. Factor all these out to a single stdfd_devnull() function that allows selection of which of these to redirect. ok markus@ OpenBSD-Commit-ID: 3033ba5a4c47cacfd5def020d42cabc52fad3099
Diffstat (limited to 'readconf.c')
-rw-r--r--readconf.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/readconf.c b/readconf.c
index 1963a83b..a4f6cba0 100644
--- a/readconf.c
+++ b/readconf.c
@@ -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));