Code

exec plugin: Allow executed programs to close STDERR.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 19 Mar 2009 18:46:01 +0000 (19:46 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Thu, 19 Mar 2009 18:46:01 +0000 (19:46 +0100)
When an executed program is closing STDERR but continues running, the
daemon will wait for the child to exit and the child will eventually
block because the pipe is filled up, resulting in no statistics being
collected.

Thanks to Thorsten von Eicken for finding this problem :)

src/exec.c

index a78f902fdef5634b11baaae07045a8ea85578ee5..afce839a058c5d528488e5e00bfcb04e2d4158f7 100644 (file)
@@ -585,7 +585,17 @@ static void *exec_read_one (void *arg) /* {{{ */
         if (errno == EAGAIN || errno == EINTR)  continue;
         break;
       }
-      else if (len == 0) break;  /* We've reached EOF */
+      else if (len == 0)
+      {
+       /* We've reached EOF */
+       NOTICE ("exec plugin: Program `%s' has closed STDERR.",
+           pl->exec);
+       close (fd_err);
+       FD_CLR (fd_err, &fdset);
+       highest_fd = fd;
+       fd_err = -1;
+       continue;
+      }
 
       pbuffer_err[len] = '\0';
 
@@ -615,6 +625,7 @@ static void *exec_read_one (void *arg) /* {{{ */
     copy = fdset;
   }
 
+  DEBUG ("exec plugin: exec_read_one: Waiting for `%s' to exit.", pl->exec);
   if (waitpid (pl->pid, &status, 0) > 0)
     pl->status = status;
 
@@ -628,7 +639,8 @@ static void *exec_read_one (void *arg) /* {{{ */
   pthread_mutex_unlock (&pl_lock);
 
   close (fd);
-  close (fd_err);
+  if (fd_err >= 0)
+    close (fd_err);
 
   pthread_exit ((void *) 0);
   return (NULL);