Subject: Re: fork(2) vs. pthread_create() (fwd)
To: None <>
From: David Laight <>
List: tech-userlevel
Date: 06/11/2004 22:34:33
> > > How can you output a warning? You're in a library. You can't depend on
> > > stdout or stderr, and trying to play with syslog seems wrong too.
> > 
> > We are able to output error messages...
> From a library? No. You can't.

We had to fix a nasty bug, a daemon process (written when max fd was 19)
did close(0), close(1) and close(2) then used them for specific purposes.
fd 1 was used as a pipe to a different daemon.

A coding error meant that an sprintf() call was actually a printf(),
since it was only generating a log message no one had noticed that
the text was incorrect (the buffer contained text from a previous call).
Everything ran fine until over a hundred cycles through the buggy code,
at that point the stdio buffer filled and got flushed to fd 1 - the
daemon at the other end took 4 ascii characters as a message length
and went into a discard loop for the overlong message.

This wasn't actually easy to find - but trivial to fix!

However it could equally well happen if a library routine wrote to
stdout, stderr, fd==0 or fd==1.
About the only valid places are /dev/tty, /dev/console or via syslog().

malloc() is borked...


David Laight: