From: Florian Forster Date: Thu, 19 Mar 2009 18:46:01 +0000 (+0100) Subject: exec plugin: Allow executed programs to close STDERR. X-Git-Tag: collectd-4.5.4~28 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=5e1c92743686af477770abe7029083d1e7100455 exec plugin: Allow executed programs to close STDERR. 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 :) --- diff --git a/src/exec.c b/src/exec.c index a78f902f..afce839a 100644 --- a/src/exec.c +++ b/src/exec.c @@ -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);