Re: [Fwd: Re: [Fwd: Re: Last item on TODO list for mc before 4.6.1]]



Leonard den Ottolander wrote:
Hm. pipethrough "ls" gives me "Broken pipe" :p .

Here's a patch. According to both the Linux documentation and POSIX-1003.1-2001 the write() call returns EPIPE when SIGPIPE is ignored, so this time there should be an output of ("write: " + strerror(EPIPE)).

I couldn't reproduce it on my system, but the cause might be that "ls" is too fast and the writing is not atomical. So here is what might happen:

parent: select(...) [returns: you can write to "ls"]
child:  execl("/bin/sh", "/bin/sh", "-c", "ls", NULL);
child:  ...
child:  _exit(0);
parent: write(ls's stdin, "hello, world", 13)

Roland
Index: pipethrough.c
===================================================================
RCS file: /home/roland/cvsroot/pipethrough/pipethrough.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pipethrough.c	23 Sep 2004 15:28:34 -0000	1.8
+++ pipethrough.c	24 Sep 2004 08:47:27 -0000	1.9
@@ -1,4 +1,5 @@
 #include <errno.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -158,6 +159,8 @@
 	/* globals internalState, fileSystem, errno, stderr; @*/
 	/* modifies internalState, fileSystem, errno, *stderr, *buf; @*/
 {
+	typedef void (*my_sighandler_fn) (int);
+	my_sighandler_fn old_sigpipe = signal(SIGPIPE, SIG_IGN);
 	ssize_t wr = write(buf->fd, &(((const char *) buf->data)[buf->pos]),
 	                   buf->size - buf->pos);
 	if (wr == (ssize_t) -1) {
@@ -171,6 +174,7 @@
 		}
 		buf->ok = false;
 	}
+	signal(SIGPIPE, old_sigpipe);
 }
 
 static void writer_buffer_finalize(/* special@*/ struct writer_buffer *buf)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]