Paolo Bonzini wrote: > > If you want both scenarios - the "don't know which of the two terminates > > first" > > and the "writer must terminate first" - to be supported by close_stream and > > close_stdout, IMO the program needs to be able to tell these functions about > > it, probably through a global variable 'bool ignore_epipe' or similar. > > I think this is not necessary. Most of the time, programs have no need > to distinguish *which* pipe was in error, so they are okay with SIGPIPE > or SIGCHLD. The global would be needed for programs that deal with > multiple pipes, cannot rely on SIGCHLD (including the case when they > want to be 100% correct and don't want to muddle with > async-signal-safety), *and* need to error out if the reader terminates > first.
I think you have misunderstood something. We are discussing different scenarios where SIGPIPE is set to SIG_IGN. SIGCHLD is not usable because - as Jim pointed out - there may not be a parent-child relationship between the pipe writer and the pipe reader, and SIGCHLD is a can of worms anyway (race conditions). Jim's scenario is "writer must terminate first", and if the reader terminates first, the writer should show an error message. My scenario is "don't know which of the two terminates first", and if the reader terminates first, the writer should acknowledge it and continue its normal processing. What else do you propose to cover these cases, if not a global variable? Bruno