X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=1f8a9ac0ebfb4a7ccfb933192368630c63cd3844;hb=7f71f1b7a38d7b50af44f403b79aa034b3882f2a;hp=711ec996861897bfa87ecb9e5adf1e6bb1078aca;hpb=68ab7da7a51018a00e6e03347182b988a30296a7;p=collectd.git diff --git a/src/exec.c b/src/exec.c index 711ec996..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" @@ -78,7 +84,7 @@ static pthread_mutex_t pl_lock = PTHREAD_MUTEX_INITIALIZER; /* * Functions */ -static void sigchld_handler (int signal) /* {{{ */ +static void sigchld_handler (int __attribute__((unused)) signal) /* {{{ */ { pid_t pid; int status; @@ -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); @@ -690,16 +708,16 @@ static void *exec_notification_one (void *arg) /* {{{ */ for (meta = n->meta; meta != NULL; meta = meta->next) { if (meta->type == NM_TYPE_STRING) - fprintf (fh, "%s: %s\n", meta->name, meta->value_string); + fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string); else if (meta->type == NM_TYPE_SIGNED_INT) - fprintf (fh, "%s: %"PRIi64"\n", meta->name, meta->value_signed_int); + fprintf (fh, "%s: %"PRIi64"\n", meta->name, meta->nm_value.nm_signed_int); else if (meta->type == NM_TYPE_UNSIGNED_INT) - fprintf (fh, "%s: %"PRIu64"\n", meta->name, meta->value_unsigned_int); + fprintf (fh, "%s: %"PRIu64"\n", meta->name, meta->nm_value.nm_unsigned_int); else if (meta->type == NM_TYPE_DOUBLE) - fprintf (fh, "%s: %e\n", meta->name, meta->value_double); + fprintf (fh, "%s: %e\n", meta->name, meta->nm_value.nm_double); else if (meta->type == NM_TYPE_BOOLEAN) fprintf (fh, "%s: %s\n", meta->name, - meta->value_boolean ? "true" : "false"); + meta->nm_value.nm_boolean ? "true" : "false"); } fprintf (fh, "\n%s\n", n->message); @@ -712,7 +730,9 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); - plugin_notification_meta_free (n); + if (n->meta != NULL) + plugin_notification_meta_free (n->meta); + n->meta = NULL; sfree (arg); pthread_exit ((void *) 0); return (NULL); @@ -760,7 +780,8 @@ static int exec_read (void) /* {{{ */ return (0); } /* int exec_read }}} */ -static int exec_notification (const notification_t *n) +static int exec_notification (const notification_t *n, + user_data_t __attribute__((unused)) *user_data) { program_list_t *pl; program_list_and_notification_t *pln; @@ -800,7 +821,7 @@ static int exec_notification (const notification_t *n) } /* for (pl) */ return (0); -} /* int exec_notification */ +} /* }}} int exec_notification */ static int exec_shutdown (void) /* {{{ */ { @@ -833,7 +854,8 @@ void module_register (void) plugin_register_complex_config ("exec", exec_config); plugin_register_init ("exec", exec_init); plugin_register_read ("exec", exec_read); - plugin_register_notification ("exec", exec_notification); + plugin_register_notification ("exec", exec_notification, + /* user_data = */ NULL); plugin_register_shutdown ("exec", exec_shutdown); } /* void module_register */