Menu

#5 Writing to closed process raises SIGPIPE

open
None
7
2013-01-20
2002-12-09
No

The streambuf doesn't check whether the read end of the
pipe is open when writing to the process' stdin. This
means that if the shell command fails, or if the new
process is created but then exits for any reason,
writing to the pstream will cause a SIGPIPE to be raised.
To prevent this, the user must call
pstreambuf::wait(false) to check that the process is
still running, but this allowse a race condition. (N.B.
pstreambuf::is_open() is not sufficient, it will only
tell you if the process was created, not whether it
subsequently exited).
Solution: pstreambuf::overflow() must check that the
read end of the pipe is open (not just that the write
end is open) before attempting to empty the buffer.
pstreambuf::is_open() could be made to check that the
remote process is still running - but this would make
it a non-const, non-atomic operation.
pstreambuf::wait() should probably close the pipes when
the process has exited.

Discussion


Log in to post a comment.