[comp.unix.questions] odd file-flushing problem

les@chinet.chi.il.us (Leslie Mikesell) (08/30/90)

I just ran across a strange problem and am still wondering if I
diagnosed what is happening correctly.  Under SysVr3.2 on 3B2's
and 386's it seems like there are certain conditions where unflushed
stdio buffers are not written out when a program exits.  (I don't
know how to set up those conditions, though...)
I wrote a small program to be executed by the Starlan DOS Server
as a printer script that would peek at the file contents to decide
what to do with it (our DOS users have trouble keeping the network
links in sync with the printer drivers that their applications are
using). It just writes a log entry using fprintf(), then executes the
final command with system(), and exits.  If a shell wrapper is
used around the command to explicitly redirect or close both stdin
and stderr, the log entry would be written, otherwise it wouldn't until
I added an fflush() at the appropriate place.  Of course it all worked
as expected from the unix command line.
My theory is that the stdout/stderr inherited from the DOS Server program
is broken to such an extent that the exit() library function won't
continue to flush the rest of the open files.  Is this possible or
can something else be happening here?

Les Mikesell
  les@chinet.chi.il.us