popen ...

Michael Davidson md at sco.COM
Tue Jun 25 04:22:46 AEST 1991


svec5 at menudo.uh.edu (T.C. Zhao) writes:

[ ... ]
>everything seems working ok except when more quits prematurely(q),
>the program exits. I do not think this is the way popen supposed to
>work, but I would like to make sure.( smell bugs in the program
>somewhere.) The other question is  how to catch the premature exit 
>of more in the program (broken pipe?), checking fprintf return
>does not seem do the trick.

You almost have the answer - the problem is the broken pipe caused
when "more" exits. The solution is to alter the default signal
handling behaviour for SIGPIPE. You can set up a signal handler for
SIGPIPE - all it needs to do is to set a global flag to indicate
that a SIGPIPE was caught, and then return. Alternatively you should
simply be able to set the behaviour for SIGPIPE to SIG_IGN and then
you should get an error back from your attmpts to write to the pipe
(but beware of the layer of buffering that stdio may be adding to
your writes, and also beware of the fact that the fwrite() and
fprintf() routines don't guarantee anything about the contents of
errno ...)



More information about the Comp.unix.programmer mailing list