Subject: Re: CVS commit: basesrc/usr.sbin
To: Andrew Brown <atatat@atatdot.net>
From: None <itojun@iijlab.net>
List: source-changes
Date: 01/11/2002 15:50:00
>>	in general, yes, if you move daemon(3) carelessly you will get the
>>	sideeffect.
>>	for the above change, "file descriptors" are network sockets,
>>	and there shouldn't be a problem.
>so...this is just to ensure that all of 0, 1, and 2 are properly
>attached to /dev/null before calling, eg, openlog(3), yes?

	here's the reason from openbsd daemon(3).  basically it is to make sure
	that openlog(3)/open(2)/socket(2) do not use file descriptor 0/1/2.

itojun


---
CAVEATS
     Unless the noclose argument is non-zero, daemon() will close the first
     three file descriptors and redirect them to /dev/null. Normally, these
     correspond to standard input, standard output and standard error.  Howev-
     er, 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 er-
     ror have been closed before the program was run.  Programs using daemon()
     should therefor be care to either call daemon() before opening any files
     or sockets or, alternately, verifying that any file descriptors obtained
     have a value greater than 2.