more BSD strangeness -- syslogd.c

Rob Warnock rpw3 at rigden.wpd.sgi.com
Fri Jun 8 23:08:50 AEST 1990


In article <1990Jun8.070904.7466 at athena.mit.edu> jik at athena.mit.edu
(Jonathan I. Kamens) writes:
+---------------
|   Here's another little gem of code from BSD4.3 that I don't quite
| understand.  Pulled from etc/syslogd.c:
| 	if (!Debug) {
| 		if (fork())
| 			exit(0);
| 		for (i = 0; i < 10; i++)
| 			(void) close(i);
| 		(void) open("/", 0);
| 		(void) dup2(0, 1);
| 		(void) dup2(0, 2);
| 		untty();
| 	}
| 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?
+---------------

Just guessing, but...

Because /dev/null might not be there. Or might have been removed and
now /dev/null is a *plain* file, not a special. [Oh, boy, that can
make things weird!] Or somebody may have mounted a funny file system
on /dev. Or the kernel may have been reconfigured and recompiled and
the major i-node numbers changed and nobody has run MAKEDEVS to fix 'em
all up yet so the device under "/dev/null" isn't /dev/null. [Yup! Seen
*that* one, too!]

But if the system booted at all, "/etc/init" was there, so "/" is there.
And the i-node number for "/" is stored in memory.

-Rob

-----
Rob Warnock, MS-9U/510          rpw3 at sgi.com            rpw3 at pei.com
Silicon Graphics, Inc.          (415)335-1673           Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA  94039-7311



More information about the Comp.unix.wizards mailing list