Question
Is it possible to disable signal boost ( SIGPIPE) when writing to pipe()FD, without installing my own signal handler or disabling / masking the signal globally?
Background
I am working on a small library that sometimes creates a pipe, and fork()a temporary child / dummy process, waiting for messages from the parent. When a child process receives a message from the parent, it dies (intentionally).
Problem
The child process, in circumstances beyond my control, runs the code from another (third party) library that is prone to failure, so I can not always be sure that the child process is alive before I go write()to the channel,
This leads to the fact that sometimes I try to execute write()for a channel with a child process, the end of which is already dead / closed, and it raises SIGPIPEin the parent process. I am in a library that other clients will use, so my library should be as autonomous and transparent as possible for the calling application. Installing a custom signal handler may break the client code.
Still working
I have a problem with sockets using setsockopt(..., MSG_NOSIGNAL), but I cannot find anything functionally equivalent for pipes. I looked at the temporary installation of the signal handler to catch SIGPIPE, but I see no way to limit its scope to the calling function in my library, and not the whole process (and this is not atomic).
SO, ,, , , poll()/select() , ( ) , select() write().
()
, , , , SIGPIPE? , , ? , , , "crashy" , , .