X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=ea31b3022bea5d45f609276699faf37594379a91;hb=52f41fed6e32f66f5817a82ae175fd443084f8a3;hp=a80de1e7a321b452b0971e2263ab0c1be9c2abf2;hpb=5e700757575fa6606cf201947cb0efb57ce12e6d;p=collectd.git diff --git a/src/exec.c b/src/exec.c index a80de1e7..ea31b302 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,6 +19,8 @@ * * Authors: * Florian octo Forster + * Sebastian Harl + * Peter Holik **/ #include "collectd.h" @@ -78,7 +82,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; @@ -490,19 +494,19 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) static int parse_line (char *buffer) /* {{{ */ { - char *fields[256]; - int fields_num; - - fields[0] = "PUTVAL"; - fields_num = strsplit (buffer, fields + 1, STATIC_ARRAY_SIZE(fields) - 1); - - if (strcasecmp (fields[1], "putval") == 0) - return (handle_putval (stdout, fields + 1, fields_num)); - else if (strcasecmp (fields[1], "putnotif") == 0) - return (handle_putnotif (stdout, fields + 1, fields_num)); - - /* compatibility code */ - return (handle_putval (stdout, fields, fields_num + 1)); + if (strncasecmp ("PUTVAL", buffer, strlen ("PUTVAL")) == 0) + return (handle_putval (stdout, buffer)); + else if (strncasecmp ("PUTNOTIF", buffer, strlen ("PUTNOTIF")) == 0) + return (handle_putnotif (stdout, buffer)); + else + { + /* For backwards compatibility */ + char tmp[1220]; + /* Let's annoy the user a bit.. */ + INFO ("exec plugin: Prepending `PUTVAL' to this line: %s", buffer); + ssnprintf (tmp, sizeof (tmp), "PUTVAL %s", buffer); + return (handle_putval (stdout, tmp)); + } } /* int parse_line }}} */ static void *exec_read_one (void *arg) /* {{{ */ @@ -585,7 +589,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 +629,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 +643,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 +706,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 +728,8 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); - plugin_notification_meta_free (n); + plugin_notification_meta_free (n->meta); + n->meta = NULL; sfree (arg); pthread_exit ((void *) 0); return (NULL);