diff options
author | djm@openbsd.org <djm@openbsd.org> | 2020-10-03 11:22:26 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-10-03 11:34:24 +0200 |
commit | 396d32f3a1a16e54df2a76b2a9b237868580dcbe (patch) | |
tree | 77019a916fcb969986a349aaede7409a25778b6a /sshconnect.c | |
parent | upstream: enable UpdateHostkeys by default when the configuration (diff) | |
download | openssh-396d32f3a1a16e54df2a76b2a9b237868580dcbe.tar.xz openssh-396d32f3a1a16e54df2a76b2a9b237868580dcbe.zip |
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 'sshconnect.c')
-rw-r--r-- | sshconnect.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/sshconnect.c b/sshconnect.c index 3c80756bc..b87dc0993 100644 --- a/sshconnect.c +++ b/sshconnect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.c,v 1.333 2020/10/03 08:11:28 djm Exp $ */ +/* $OpenBSD: sshconnect.c,v 1.334 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 @@ -105,24 +105,6 @@ expand_proxy_command(const char *proxy_command, const char *user, return ret; } -static void -stderr_null(void) -{ - int devnull; - - if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) { - error("Can't open %s for stderr redirection: %s", - _PATH_DEVNULL, strerror(errno)); - return; - } - if (devnull == STDERR_FILENO) - return; - if (dup2(devnull, STDERR_FILENO) == -1) - error("Cannot redirect stderr to %s", _PATH_DEVNULL); - if (devnull > STDERR_FILENO) - close(devnull); -} - /* * Connect to the given ssh server using a proxy command that passes a * a connected fd back to us. @@ -169,8 +151,8 @@ ssh_proxy_fdpass_connect(struct ssh *ssh, const char *host, * error messages may be printed on the user's terminal. */ if (!debug_flag && options.control_path != NULL && - options.control_persist) - stderr_null(); + options.control_persist && stdfd_devnull(0, 0, 1) == -1) + error("%s: stdfd_devnull failed", __func__); argv[0] = shell; argv[1] = "-c"; @@ -252,8 +234,8 @@ ssh_proxy_connect(struct ssh *ssh, const char *host, const char *host_arg, * error messages may be printed on the user's terminal. */ if (!debug_flag && options.control_path != NULL && - options.control_persist) - stderr_null(); + options.control_persist && stdfd_devnull(0, 0, 1) == -1) + error("%s: stdfd_devnull failed", __func__); argv[0] = shell; argv[1] = "-c"; |