X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=1f8a9ac0ebfb4a7ccfb933192368630c63cd3844;hb=7f71f1b7a38d7b50af44f403b79aa034b3882f2a;hp=cdcf6adebdba0f886aa2515cb92e7ac9b21a92d7;hpb=e4b8a186516b61f16d94a76db0aa102a3270d46c;p=collectd.git diff --git a/src/exec.c b/src/exec.c index cdcf6ade..1f8a9ac0 100644 --- a/src/exec.c +++ b/src/exec.c @@ -1,6 +1,8 @@ /** * collectd - src/exec.c - * Copyright (C) 2007,2008 Florian octo Forster + * Copyright (C) 2007-2009 Florian octo Forster + * Copyright (C) 2007-2009 Sebastian Harl + * Copyright (C) 2008 Peter Holik * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,8 +19,12 @@ * * Authors: * Florian octo Forster + * Sebastian Harl + * Peter Holik **/ +#define _BSD_SOURCE /* For setgroups */ + #include "collectd.h" #include "common.h" #include "plugin.h" @@ -585,7 +591,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 +631,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 +645,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); @@ -712,7 +730,8 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); - plugin_notification_meta_free (n->meta); + if (n->meta != NULL) + plugin_notification_meta_free (n->meta); n->meta = NULL; sfree (arg); pthread_exit ((void *) 0);