Skip to contentSkip to conversation

gnutv should not ignore SIGPIPE

DISCUSSION Brian J. Murrell 2 participants 4 messages Nov 25, 2011 – Nov 29, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

Currently, (at least in rev. 1355) gnutv is ignoring SIGPIPE:

	signal(SIGPIPE, SIG_IGN);

This means though that if it is used as such:

gnutv -out stdout -channels /home/mythtv/channels.conf.found 91-472 | mplayer -

It will not terminate as it should when/if it's consumer (mplayer in the above example) is killed.

Is there a good reason I am not seeing why gnutv should be ignoring SIGPIPE?

Cheers,
b.

#1 lore raw

Le vendredi 25 novembre 2011 15:05:44 Brian J. Murrell, vous avez écrit :

Quoted 2 lines

Is there a good reason I am not seeing why gnutv should be ignoring SIGPIPE?

In general, ignoring SIGPIPE is the easiest way to protect against denial of service when a peer connection socket is hung up remotely. MSG_NOSIGNAL is a more modern alternative.

Anyway, the problem is not so mucgh ignoring SIGPIPE as ignoring EPIPE write errors.

Signature · 3 lines
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis
#2 lore raw
Quoted 3 lines · Rémi Denis-Courmont

Anyway, the problem is not so mucgh ignoring SIGPIPE as ignoring EPIPE write errors.

Yes, that is the other way to skin that cat I suppose.

What's the best/proper way to go about getting this fixed?

Cheers,
b.

#3 lore raw
Quoted 2 lines · Brian J. Murrell

Yes, that is the other way to skin that cat I suppose.

I couldn't figure out what the right thing for writer thread to do to terminate the application so I used SIGPIPE instead. Here's the patch:

util/gnutv/gnutv_data.c +4 -1
@@ -265,7 +265,10 @@
 		while(written < size) {
 			int tmp = write(outfd, buf + written, size - written);
 			if (tmp == -1) {
-				if (errno != EINTR) {
+				if (errno == EPIPE) {
+					fprintf(stderr, "processing EPIPE\n");
+					return 0;
+				} else if (errno != EINTR) {
 					fprintf(stderr, "Write error: %m\n");
 					break;
 				}
util/gnutv/gnutv.c.new renamed from util/gnutv/gnutv.c +1 -1
@@ -262,7 +262,7 @@
 
 	// setup any signals
 	signal(SIGINT, signal_handler);
-	signal(SIGPIPE, SIG_IGN);
+	signal(SIGPIPE, signal_handler);
 
 	// start the CA stuff
 	gnutv_ca_params.adapter_id = adapter_id;