Prevent SIGPIPE being sent#155
Conversation
|
This is the default behavior of UNIX-like operating systems, for some historic reason. Should we really override that? Applications can choose the behavior by installing a SIGPIPE handler (or masking the signal), but if we use MSG_NOSIGNAL, applications have no choice anymore. What is your rationale for that? |
|
I'm only learning about SIGPIPE myself at the moment, but from what I understand SIGPIPE is mainly used to simplify error handling for applications so you can I looked at some mpd clients listed in https://www.musicpd.org/clients/, and some of them ignore SIGPIPE, others leave it at the default, which means the client would terminate when the mpd server stops/restarts, which is probably not the intended behavior. Also I think the client terminating due to a SIGPIPE when the server restarts/stops might give some debugging headaches to people not to familiar with UNIX signals, as here the default behavior is probably not the one that would be expected. For example i3status is using SIGPIPE to get notified when no one is reading from stdout anymore. If someone would write an mpd module for it, i3status would also exit when the mpd server stopped. |
Those who leave it at the default will get default behavior. Those who do not want default behavior shall opt out of the default behavior. I don't like that default behavior - it's a bad design for people who are too lazy to implement proper error handling. I wish SIGPIPE had never been invented. All of my software disables SIGPIPE.
That's not how SIGPIPE works. That would be more akin to SIGHUP. SIGPIPE is not a notification of some external event. You only ever get SIGPIPE when failing to write. As long as you don't write to that pipe, you won't get SIGPIPE. |
My point is that since libmpdclient is forcibly emitting SIGPIPE without control of the library user, using SIGPIPE as above (which I believe to be the intended use case of SIGPIPE) is no longer possible. As far as I can tell SIGPIPE is only useful if one can control which |
When trying to call
mpd_async_writefor a server that has disconnected,sendmakes the kernel generate SIGPIPE, which will terminate the calling process if it is not ignored. (Some clients like ncmpcpp ignore SIGPIPE, and use the EPIPE error generated bysendto handle the error which seems like the sensible thing to do.)This SIGPIPE can confuse processes which rely on SIGPIPE to terminate when the reading end of stdout has been closed. (like a status bar content generator.)
This sets the
MSG_NOSIGNALflag forsend, which prevents SIGPIPE from being sent.