X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=ee37c607e4d4c5f6b6174c977a74677ce6b0abe4;hb=d6021a800b12c89b5a78877af2c5b9abc1a8e609;hp=c5ea155ebc53f10e4d191bc84dca0828476a953a;hpb=3904b4b9fd1a53c93f31d8fec709a7b7b8300513;p=collectd.git diff --git a/src/exec.c b/src/exec.c index c5ea155e..ee37c607 100644 --- a/src/exec.c +++ b/src/exec.c @@ -492,7 +492,7 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) close (fd_pipe_out[1]); } - /* Now connect the `out' pipe to STDOUT */ + /* Now connect the `err' pipe to STDERR */ if (fd_pipe_err[1] != STDERR_FILENO) { dup2 (fd_pipe_err[1], STDERR_FILENO); @@ -635,17 +635,22 @@ static void *exec_read_one (void *arg) /* {{{ */ if (len < 0) { - if (errno == EAGAIN || errno == EINTR) continue; + if (errno == EAGAIN || errno == EINTR) + continue; break; } else if (len == 0) { /* We've reached EOF */ - NOTICE ("exec plugin: Program `%s' has closed STDERR.", - pl->exec); - close (fd_err); + NOTICE ("exec plugin: Program `%s' has closed STDERR.", pl->exec); + + /* Remove file descriptor form select() set. */ FD_CLR (fd_err, &fdset); + copy = fdset; highest_fd = fd; + + /* Clean up file descriptor */ + close (fd_err); fd_err = -1; continue; } @@ -822,6 +827,7 @@ static int exec_read (void) /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&t, &attr, exec_read_one, (void *) pl); + pthread_attr_destroy (&attr); } /* for (pl) */ return (0); @@ -865,6 +871,7 @@ static int exec_notification (const notification_t *n, /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&t, &attr, exec_notification_one, (void *) pln); + pthread_attr_destroy (&attr); } /* for (pl) */ return (0);