From 9662a937db493485358bdc64f2a25bc658a3913c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 7 Dec 2001 19:59:51 +0000 Subject: Add CAVEATS section pointing out the dangers of closing fds <= 2 as found by Markus. --- lib/libc/gen/daemon.3 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/libc/gen') diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3 index 8acc08b3b53..d90c38f6c2e 100644 --- a/lib/libc/gen/daemon.3 +++ b/lib/libc/gen/daemon.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: daemon.3,v 1.7 1999/09/22 22:01:25 aaron Exp $ +.\" $OpenBSD: daemon.3,v 1.8 2001/12/07 19:59:50 millert Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -81,3 +81,22 @@ The .Fn daemon function first appeared in .Bx 4.4 . +.Sh CAVEATS +Unless the +.Ar noclose +argument is non-zero, +.Fn daemon +will close the first three file descriptors and redirect them to +.Pa /dev/null . +Normally, these correspond to standard input, standard output and +standard error. +However, if any of those file descriptors refer to something else they +will still be closed, resulting in incorrect behavior of the calling program. +This can happen if any of standard input, standard output or standard error +have been closed before the program was run. +Programs using +.Fn daemon +should therefor be care to either call +.Fn daemon +before opening any files or sockets or, alternately, verifying that +any file descriptors obtained have a value greater than 2. -- cgit v1.2.3