From d6afd8ad4eff60cca437d463fee176ff05488eb4 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 May 2013 12:58:14 +0000 Subject: [PATCH] -handle SIGPIPE --- src/examples/demo.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/examples/demo.c b/src/examples/demo.c index 8b836a0c..9bd04fee 100644 --- a/src/examples/demo.c +++ b/src/examples/demo.c @@ -781,6 +781,34 @@ generate_page (void *cls, } +static void +catcher (int sig) +{ +} + + +/** + * setup handlers to ignore SIGPIPE. + */ +static void +ignore_sigpipe () +{ + struct sigaction oldsig; + struct sigaction sig; + + sig.sa_handler = &catcher; + sigemptyset (&sig.sa_mask); +#ifdef SA_INTERRUPT + sig.sa_flags = SA_INTERRUPT; /* SunOS */ +#else + sig.sa_flags = SA_RESTART; +#endif + if (0 != sigaction (SIGPIPE, &sig, &oldsig)) + fprintf (stderr, + "Failed to install SIGPIPE handler: %s\n", strerror (errno)); +} + + /** * Entry point to demo. Note: this HTTP server will make all * files in the current directory and its subdirectories available @@ -804,6 +832,7 @@ main (int argc, char *const *argv) "%s PORT\n", argv[0]); return 1; } + ignore_sigpipe (); magic = magic_open (MAGIC_MIME_TYPE); (void) magic_load (magic, NULL);