[Libguestfs] avoid ignoring SIGPIPE globally

Jim Meyering jim at meyering.net
Thu Sep 17 16:58:43 UTC 2009


Richard W.M. Jones wrote:
> On Thu, Sep 17, 2009 at 04:44:11PM +0200, Jim Meyering wrote:
...
>> Second, I saw this in the context:
>>
>> >    /* Make sure SIGPIPE doesn't kill us. */
>> >    memset (&sa, 0, sizeof sa);
>> >    sa.sa_handler = SIG_IGN;
>>
>> Have you considered alternate ways of ignoring SIGPIPE?
>> Ignoring SIGPIPE across the board can cause problems (albeit subtle)
>> in unsuspecting child processes.
>
> I didn't know there were alternate ways to ignore SIGPIPE.  Can you
> give some examples of how it should be done?  (Possibly in a new
> thread -- seems a separate issue from the patch at hand).

Depending on portability (this is mandated by POSIX 2006 and in glibc
long before then), and context (sockets) you can use the MSG_NOSIGNAL flag:

    The SIGPIPE signal shall be sent to a thread that attempts to send data on
    a socket that is no longer able to send (one that is no longer connected),
    except that the signal is suppressed if the MSG_NOSIGNAL flag is used
    in calls to send(), sendto(), and sendmsg().

>From "Socket Types" in
http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_06




More information about the Libguestfs mailing list