[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: man-db segfault: problem found (but need help for the solution :-)



Fabrizio Polacco wrote:
> Why the hell the closed stdout _and_ stderr produce a redirection to a
> different stream?
> 
> Can somebody help me to understand this?

Hm... well, file descriptors are assigned sequentially when files
are opened.  Normally stdin is 0, stdout is 1, and stderr is 2.
But with the latter two closed, 1 and 2 are available again.

The function testmandirs() first opens the directory to scan
("/usr/man"), and the directory gets descriptor 1.  Then it
opens the database, which gets descriptor 2.

Then it writes to stderr.  The stdio library apparently did not
know that stderr started out closed, and happily writes to file
descriptor 2.  I think this is a bug in the stdio library.

If you want a quick hack, just put

     /* Skip fd's 0 through 2 even if they are available */
     open("/dev/null", O_WRONLY);
     open("/dev/null", O_WRONLY);
     open("/dev/null", O_WRONLY);

in main() somewhere close to the beginning.

Richard Braakman


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . Trouble? 
e-mail to templin@bucknell.edu .


Reply to: