src/plugin.c: Add a user_data_t pointer to notification callbacks.
[collectd.git] / src / exec.c
index a80de1e..cdcf6ad 100644 (file)
@@ -78,7 +78,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 +490,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) /* {{{ */
@@ -690,16 +690,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 +712,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);
@@ -760,7 +761,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 +802,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 +835,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 */