sigpipe.c (621B)
1 /* examples/sigpipe.c */ 2 3 static void 4 catcher (int sig) 5 { 6 /* Ignore the signal */ 7 } 8 9 10 static void 11 ignore_sigpipe (void) 12 { 13 struct sigaction oldsig; 14 struct sigaction sig; 15 16 sig.sa_handler = &catcher; 17 sigemptyset (&sig.sa_mask); 18 #ifdef SA_INTERRUPT 19 sig.sa_flags = SA_INTERRUPT; /* SunOS */ 20 #else 21 sig.sa_flags = SA_RESTART; 22 #endif 23 if (0 != sigaction (SIGPIPE, 24 &sig, 25 &oldsig)) 26 fprintf (stderr, 27 "Failed to install SIGPIPE handler: %s\n", strerror (errno)); 28 } 29 30 31 int 32 main () 33 { 34 ignore_sigpipe (); 35 /* Do actual application work here */ 36 return 0; 37 }