Permalink
Browse files

Ignore SIGPIPE

TODO: restore the default handler for the scope of any callbacks.
  • Loading branch information...
1 parent d3dbf7d commit 99e7bc2fc2f0cd2e538d3fd62ab628b4adfc94cb @stash committed Apr 15, 2011
Showing with 9 additions and 2 deletions.
  1. +2 −1 Feersum.xs
  2. +7 −1 lib/Feersum.pm
View
@@ -833,7 +833,6 @@ try_write_again_immediately:
trace("going to write %d off=%d count=%d\n", w->fd, m->offset, m->count);
errno = 0;
- sig_t old = signal(SIGPIPE, SIG_IGN);
ssize_t wrote = writev(w->fd, &m->iov[m->offset], m->count - m->offset);
trace("wrote %"Ssz_df" bytes to %d, errno=%d\n", (Ssz)wrote, w->fd, errno);
@@ -2149,6 +2148,8 @@ accept_on_fd(SV *self, int fd)
trace("going to accept on %d\n",fd);
feersum_ev_loop = EV_DEFAULT;
+ signal(SIGPIPE, SIG_IGN);
+
ev_prepare_init(&ep, prepare_cb);
ev_prepare_start(feersum_ev_loop, &ep);
View
@@ -22,9 +22,10 @@ sub new {
unless ($INSTANCE) {
$INSTANCE = bless {}, __PACKAGE__;
}
+ $SIG{PIPE} = 'IGNORE';
return $INSTANCE;
}
-*endjinn = \&new;
+*endjinn = *new;
sub use_socket {
my ($self, $sock) = @_;
@@ -482,6 +483,11 @@ This could lead to a DoS attack on a Feersum server. Suggested remedy is to
only run Feersum behind some other web server and to use that to limit the
entity size.
+Although not explicitly a bug, the following may cause undesirable behavior.
+Feersum will have set SIGPIPE to be ignored by the time your handler gets
+called. If your handler needs to detect SIGPIPE, be sure to do a
+C<local $SIG{PIPE} = 'DEFAULT'> to make it active just for your lexical scope.
+
=head1 SEE ALSO
http://en.wikipedia.org/wiki/Feersum_Endjinn

0 comments on commit 99e7bc2

Please sign in to comment.