more BSD strangeness -- syslogd.c

David J. MacKenzie djm at eng.umd.edu
Sat Jun 9 16:46:17 AEST 1990


In article <36447 at sequent.UUCP> keany at sequent.UUCP (Bernard Keany) writes:

>>		(void) open("/", 0);
>>		(void) dup2(0, 1);
>>		(void) dup2(0, 2);

>>OK, so why is it opening "/"?  Is this a poor man's equivalent to
>>/dev/null, and if so, why doesn't it just open /dev/null?

> "Change the working directory to /. Each process has a current working
> directory, and the kernel holds this directory file open during the life
> of the process. If a process has a current directory in a mounted file
> system, the file system is "in use" and cannot be dismounted by the
> administrator without first finding and killing the offending process.

Almost.  That's an *open*, not a *chdir*!  But the principle is the
same: syslog wants to make sure that it doesn't hold open any files on
stdin, stdout, or stderr that would tie up a filesystem.  I presume
that after that it makes no references to stdin, stdout, and stderr.

Not that /dev/null is going to be on a different filesystem, but "/"
is guaranteed to exist, so why not use it?
--
David J. MacKenzie <djm at eng.umd.edu> <djm at ai.mit.edu>



More information about the Comp.unix.wizards mailing list