summaryrefslogtreecommitdiff
path: root/ssh-agent.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 /ssh-agent.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 'ssh-agent.c')
-rw-r--r--ssh-agent.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/ssh-agent.c b/ssh-agent.c
index e1fd1f3f..853841b5 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-agent.c,v 1.264 2020/09/18 08:16:38 djm Exp $ */
+/* $OpenBSD: ssh-agent.c,v 1.265 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
@@ -1273,7 +1273,7 @@ int
main(int ac, char **av)
{
int c_flag = 0, d_flag = 0, D_flag = 0, k_flag = 0, s_flag = 0;
- int sock, fd, ch, result, saved_errno;
+ int sock, ch, result, saved_errno;
char *shell, *format, *pidstr, *agentsocket = NULL;
#ifdef HAVE_SETRLIMIT
struct rlimit rlim;
@@ -1493,14 +1493,8 @@ main(int ac, char **av)
}
(void)chdir("/");
- if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- /* XXX might close listen socket */
- (void)dup2(fd, STDIN_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd > 2)
- close(fd);
- }
+ if (stdfd_devnull(1, 1, 1) == -1)
+ error("%s: stdfd_devnull failed", __func__);
#ifdef HAVE_SETRLIMIT
/* deny core dumps, since memory contains unencrypted private keys */