X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=0d33b290cce6afa2293a247ea7cf3342cc4833e6;hb=4dc9287f4de0283ae986444377075dcbdada2871;hp=95a6831a70795a9b0dcda6b443f459e25887af38;hpb=66c0d62a769d8bb363c8d19e82896d6cf5bdcc2b;p=collectd.git diff --git a/src/exec.c b/src/exec.c index 95a6831a..0d33b290 100644 --- a/src/exec.c +++ b/src/exec.c @@ -1,6 +1,6 @@ /** * collectd - src/exec.c - * Copyright (C) 2007-2009 Florian octo Forster + * Copyright (C) 2007-2010 Florian octo Forster * Copyright (C) 2007-2009 Sebastian Harl * Copyright (C) 2008 Peter Holik * @@ -265,6 +265,27 @@ static int exec_config (oconfig_item_t *ci) /* {{{ */ return (0); } /* int exec_config }}} */ +static void set_environment (void) /* {{{ */ +{ + char buffer[1024]; + +#ifdef HAVE_SETENV + ssnprintf (buffer, sizeof (buffer), "%.3f", CDTIME_T_TO_DOUBLE (interval_g)); + setenv ("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1); + + ssnprintf (buffer, sizeof (buffer), "%s", hostname_g); + setenv ("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1); +#else + ssnprintf (buffer, sizeof (buffer), "COLLECTD_INTERVAL=%.3f", + CDTIME_T_TO_DOUBLE (interval_g)); + putenv (buffer); + + ssnprintf (buffer, sizeof (buffer), "COLLECTD_HOSTNAME=%s", hostname_g); + putenv (buffer); +#endif +} /* }}} void set_environment */ + +__attribute__((noreturn)) static void exec_child (program_list_t *pl) /* {{{ */ { int status; @@ -478,6 +499,8 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) close (fd_pipe_err[1]); } + set_environment (); + /* Unblock all signals */ reset_signal_mask (); @@ -515,12 +538,9 @@ static int parse_line (char *buffer) /* {{{ */ 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)); + ERROR ("exec plugin: Unable to parse command, ignoring line: \"%s\"", + buffer); + return (-1); } } /* int parse_line }}} */ @@ -799,7 +819,7 @@ 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;