[Libevent-users] SIGPIPE in multithreaded program
William Ahern
william at 25thandClement.com
Mon Jan 21 19:56:22 EST 2008
On Tue, Jan 22, 2008 at 01:06:30AM +0100, Ron Arts wrote:
> Hi,
>
> I am using libevent in a multithreaded program, the main
> thread containing the libevent loop, and other threads
> doing disk I/O. From mail from this list, and the changelogs
> I was under the impression that libevent handles signals
> better in a multithreaded environment since 1.3, but now
> I think I was wrong.
>
> Is it necessary to specifically ignore signals in every
> thread I create?
In Unix it's necessary to change the default behavior of SIGPIPE if you
don't want your process killed. libevent, AFAIK, won't do this for you. If
won't independently setup handlers for all the different signals. Most
daemon applications ignore SIGPIPE as part of their initialization. The
default behavior caters to simple shell applications that can't be bothered
to check the return value of a write.
#include <signal.h>
struct sigaction sa;
sa = sa_initializer;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if (0 != sigaction(SIGPIPE, &sa, 0))
err(EXIT_FAILURE, "sigaction");
More information about the Libevent-users
mailing list