chiark / gitweb /
@@ -3,6 +3,8 @@
authorian <ian>
Sat, 1 Nov 2003 00:18:38 +0000 (00:18 +0000)
committerian <ian>
Sat, 1 Nov 2003 00:18:38 +0000 (00:18 +0000)
     their use of strtoul.  (Thanks to report from Peter Benie.)
+  * Close unwanted pipes in client-side cat subprocesses, to avoid
+    wedging at termination.  (Thanks to patchlet from Peter Benie.)

client.c
debian/changelog

index 9fb76df18c34be6822de85c953d57bc3d9a0ef7a..0af49e868e16926b545ece7e357505fcb84dc828 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1163,6 +1163,21 @@ static void prepare_asynchsignals(void) {
   if (alarm(timeout)<0) syscallerror("set up timeout alarm");
 }
 
   if (alarm(timeout)<0) syscallerror("set up timeout alarm");
 }
 
+
+static void cat_close_unwanted_pipes(void) {
+  int fd;
+
+  for (fd=0; fd<fdsetupsize; fd++) {
+    if (!fdsetup[fd].filename) continue;
+    if (close(fdsetup[fd].pipefd)) fsyscallerror("close pipe fd for %d",fd);
+    if (fdsetup[fd].copyfd>2)
+      if (close(fdsetup[fd].copyfd))
+       if (errno != EBADF)
+         /* EBADF can be induced if cmd line specifies same fd twice */
+         fsyscallerror("close real fd for %d",fd);
+  }
+}
+
 static void catdup(const char *which, int from, int to) {
   if (dup2(from,to)<0) {
     blocksignals(SIG_BLOCK);
 static void catdup(const char *which, int from, int to) {
   if (dup2(from,to)<0) {
     blocksignals(SIG_BLOCK);
@@ -1205,6 +1220,7 @@ static void connect_pipes(void) {
       reading= fdsetup[fd].mods & fdm_read;
       catdup(catnamebuf, fdsetup[fd].copyfd, reading ? 0 : 1);
       catdup(catnamebuf, fdsetup[fd].pipefd, reading ? 1 : 0);
       reading= fdsetup[fd].mods & fdm_read;
       catdup(catnamebuf, fdsetup[fd].copyfd, reading ? 0 : 1);
       catdup(catnamebuf, fdsetup[fd].pipefd, reading ? 1 : 0);
+      cat_close_unwanted_pipes();
       execl("/bin/cat",catnamebuf,(char*)0);
       fprintf(stderr,"userv: %s: cannot exec `cat': %s\n",catnamebuf,strerror(errno));
       exit(-1);
       execl("/bin/cat",catnamebuf,(char*)0);
       fprintf(stderr,"userv: %s: cannot exec `cat': %s\n",catnamebuf,strerror(errno));
       exit(-1);
index e7e6bf55ddb4a7265355a6c115d1bb3dc6ce3fd2..b9bd3453346c8c20d65b8352c0618c596d18eee9 100644 (file)
@@ -3,6 +3,8 @@ userv (1.0.1.99.2) unstable; urgency=low
   * Actually ship uservd(8) !
   * Fix fd modifier, signal, and exit status parsing to be rigourous in
     their use of strtoul.  (Thanks to report from Peter Benie.)
   * Actually ship uservd(8) !
   * Fix fd modifier, signal, and exit status parsing to be rigourous in
     their use of strtoul.  (Thanks to report from Peter Benie.)
+  * Close unwanted pipes in client-side cat subprocesses, to avoid
+    wedging at termination.  (Thanks to patchlet from Peter Benie.)
 
  --
 
 
  --