diff options
author | djm@openbsd.org <djm@openbsd.org> | 2020-10-03 09:22:26 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-10-03 19:34:24 +1000 |
commit | 396d32f3a1a16e54df2a76b2a9b237868580dcbe (patch) | |
tree | 77019a916fcb969986a349aaede7409a25778b6a /mux.c | |
parent | 1286981d08b8429a64613215ce8bff3f6b32488a (diff) |
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 'mux.c')
-rw-r--r-- | mux.c | 26 |
1 files changed, 7 insertions, 19 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: mux.c,v 1.83 2020/07/05 23:59:45 djm Exp $ */ +/* $OpenBSD: mux.c,v 1.84 2020/10/03 09:22:26 djm Exp $ */ /* * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org> * @@ -1902,7 +1902,7 @@ mux_client_request_session(int fd) const char *term; u_int echar, rid, sid, esid, exitval, type, exitval_seen; extern char **environ; - int r, i, devnull, rawmode; + int r, i, rawmode; debug3("%s: entering", __func__); @@ -1913,14 +1913,8 @@ mux_client_request_session(int fd) ssh_signal(SIGPIPE, SIG_IGN); - if (stdin_null_flag) { - if ((devnull = open(_PATH_DEVNULL, O_RDONLY)) == -1) - fatal("open(/dev/null): %s", strerror(errno)); - if (dup2(devnull, STDIN_FILENO) == -1) - fatal("dup2: %s", strerror(errno)); - if (devnull > STDERR_FILENO) - close(devnull); - } + if (stdin_null_flag && stdfd_devnull(1, 0, 0) == -1) + fatal("%s: stdfd_devnull failed", __func__); if ((term = getenv("TERM")) == NULL) term = ""; @@ -2137,7 +2131,7 @@ mux_client_request_stdio_fwd(int fd) struct sshbuf *m; char *e; u_int type, rid, sid; - int r, devnull; + int r; debug3("%s: entering", __func__); @@ -2148,14 +2142,8 @@ mux_client_request_stdio_fwd(int fd) ssh_signal(SIGPIPE, SIG_IGN); - if (stdin_null_flag) { - if ((devnull = open(_PATH_DEVNULL, O_RDONLY)) == -1) - fatal("open(/dev/null): %s", strerror(errno)); - if (dup2(devnull, STDIN_FILENO) == -1) - fatal("dup2: %s", strerror(errno)); - if (devnull > STDERR_FILENO) - close(devnull); - } + if (stdin_null_flag && stdfd_devnull(1, 0, 0) == -1) + fatal("%s: stdfd_devnull failed", __func__); if ((m = sshbuf_new()) == NULL) fatal("%s: sshbuf_new", __func__); |