X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=a80de1e7a321b452b0971e2263ab0c1be9c2abf2;hb=b4d9bd23f3e04f9b42204d9954842524e2a7eb61;hp=07c35c9bcf36d0e307ebbc48a93fb1e7fafa57e1;hpb=7a36927e0c5411c701d9e1bfd3f02a9c2f254d0f;p=collectd.git diff --git a/src/exec.c b/src/exec.c index 07c35c9b..a80de1e7 100644 --- a/src/exec.c +++ b/src/exec.c @@ -170,10 +170,9 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { char *tmp = strrchr (ci->values[1].value.string, '/'); if (tmp == NULL) - strncpy (buffer, ci->values[1].value.string, sizeof (buffer)); + sstrncpy (buffer, ci->values[1].value.string, sizeof (buffer)); else - strncpy (buffer, tmp + 1, sizeof (buffer)); - buffer[sizeof (buffer) - 1] = '\0'; + sstrncpy (buffer, tmp + 1, sizeof (buffer)); } pl->argv[0] = strdup (buffer); if (pl->argv[0] == NULL) @@ -196,17 +195,16 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER) { - snprintf (buffer, sizeof (buffer), "%lf", + ssnprintf (buffer, sizeof (buffer), "%lf", ci->values[i + 1].value.number); } else { if (ci->values[i + 1].value.boolean) - strncpy (buffer, "true", sizeof (buffer)); + sstrncpy (buffer, "true", sizeof (buffer)); else - strncpy (buffer, "false", sizeof (buffer)); + sstrncpy (buffer, "false", sizeof (buffer)); } - buffer[sizeof (buffer) - 1] = '\0'; pl->argv[i] = strdup (buffer); } @@ -639,7 +637,8 @@ static void *exec_read_one (void *arg) /* {{{ */ static void *exec_notification_one (void *arg) /* {{{ */ { program_list_t *pl = ((program_list_and_notification_t *) arg)->pl; - const notification_t *n = &((program_list_and_notification_t *) arg)->n; + notification_t *n = &((program_list_and_notification_t *) arg)->n; + notification_meta_t *meta; int fd; FILE *fh; int pid; @@ -688,6 +687,21 @@ static void *exec_notification_one (void *arg) /* {{{ */ if (strlen (n->type_instance) > 0) fprintf (fh, "TypeInstance: %s\n", n->type_instance); + 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); + else if (meta->type == NM_TYPE_SIGNED_INT) + fprintf (fh, "%s: %"PRIi64"\n", meta->name, meta->value_signed_int); + else if (meta->type == NM_TYPE_UNSIGNED_INT) + fprintf (fh, "%s: %"PRIu64"\n", meta->name, meta->value_unsigned_int); + else if (meta->type == NM_TYPE_DOUBLE) + fprintf (fh, "%s: %e\n", meta->name, meta->value_double); + else if (meta->type == NM_TYPE_BOOLEAN) + fprintf (fh, "%s: %s\n", meta->name, + meta->value_boolean ? "true" : "false"); + } + fprintf (fh, "\n%s\n", n->message); fflush (fh); @@ -698,6 +712,7 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); + plugin_notification_meta_free (n); sfree (arg); pthread_exit ((void *) 0); return (NULL); @@ -774,6 +789,11 @@ static int exec_notification (const notification_t *n) pln->pl = pl; memcpy (&pln->n, n, sizeof (notification_t)); + /* Set the `meta' member to NULL, otherwise `plugin_notification_meta_copy' + * will run into an endless loop. */ + pln->n.meta = NULL; + plugin_notification_meta_copy (&pln->n, n); + pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); pthread_create (&t, &attr, exec_notification_one, (void *) pln);