diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-08-30 23:24:47 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-08-30 23:24:47 +0000 |
commit | 8de0c66a4c16a6a4558a684cdc0888c936393f22 (patch) | |
tree | 95c3b08639223e130aaea10dc840b958dbe7f170 /usr.sbin/lpr | |
parent | 5d6c92a466b908e54d8bebf00576ce2018bbba10 (diff) |
When using dup2() to make a socket be stdout, first check that it
is not already stdout (fd 1). Otherwise we end up closing stdout
which is not the intention. Also use STDOUT_FILENO instead of 1.
From a conversation with huntting@glarp.com.
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r-- | usr.sbin/lpr/lpd/lpd.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index a41d85c6f17..9123a23143d 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.c,v 1.18 2001/08/30 17:38:13 millert Exp $ */ +/* $OpenBSD: lpd.c,v 1.19 2001/08/30 23:24:46 millert Exp $ */ /* $NetBSD: lpd.c,v 1.7 1996/04/24 14:54:06 mrg Exp $ */ /* @@ -45,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpd.c,v 1.18 2001/08/30 17:38:13 millert Exp $"; +static const char rcsid[] = "$OpenBSD: lpd.c,v 1.19 2001/08/30 23:24:46 millert Exp $"; #endif #endif /* not lint */ @@ -288,8 +288,10 @@ main(argc, argv) signal(SIGTERM, SIG_IGN); (void) close(funix); (void) close(finet); - dup2(s, 1); - (void) close(s); + if (s != STDOUT_FILENO) { + dup2(s, STDOUT_FILENO); + (void) close(s); + } if (domain == AF_INET) { from_remote = 1; chkhost(&frominet); |