summaryrefslogtreecommitdiffstats
path: root/ssh.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-10-25 02:21:37 +0200
committerDamien Miller <djm@mindrot.org>2017-10-25 03:26:21 +0200
commit4d5456c7de108e17603a0920c4d15bca87244921 (patch)
treefbeae4ad24e358172f127c7189e8dcd6e1e3ce63 /ssh.c
parentupstream commit (diff)
downloadopenssh-4d5456c7de108e17603a0920c4d15bca87244921.tar.xz
openssh-4d5456c7de108e17603a0920c4d15bca87244921.zip
upstream commit
transfer ownership of stdout to the session channel by dup2'ing /dev/null to fd 1. This allows propagation of remote stdout close to the local side; reported by David Newall, ok markus@ Upstream-ID: 8d9ac18a11d89e6b0415f0cbf67b928ac67f0e79
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/ssh.c b/ssh.c
index 74056985b..ae468d286 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.466 2017/10/23 05:08:00 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.467 2017/10/25 00:21:37 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1817,7 +1817,7 @@ ssh_session2_open(struct ssh *ssh)
static int
ssh_session2(struct ssh *ssh, struct passwd *pw)
{
- int id = -1;
+ int devnull, id = -1;
char *cp, *tun_fwd_ifname = NULL;
/* XXX should be pre-session */
@@ -1901,6 +1901,20 @@ ssh_session2(struct ssh *ssh, struct passwd *pw)
ssh_local_cmd(options.local_command);
/*
+ * stdout is now owned by the session channel; clobber it here
+ * so future channel closes are propagated to the local fd.
+ * NB. this can only happen after LocalCommand has completed,
+ * as it may want to write to stdout.
+ */
+ if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1)
+ error("%s: open %s: %s", __func__,
+ _PATH_DEVNULL, strerror(errno));
+ if (dup2(devnull, STDOUT_FILENO) < 0)
+ fatal("%s: dup2() stdout failed", __func__);
+ if (devnull > STDERR_FILENO)
+ close(devnull);
+
+ /*
* If requested and we are not interested in replies to remote
* forwarding requests, then let ssh continue in the background.
*/