From: Florian Forster Date: Fri, 28 Dec 2007 20:02:55 +0000 (+0100) Subject: exec plugin: The execution of notification handling programs seems to work now. X-Git-Tag: collectd-4.3.0beta0~48 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f9e1b3ec37fc4cd9d92b4444a7eec34af7d076c5;p=collectd.git exec plugin: The execution of notification handling programs seems to work now. --- diff --git a/src/exec.c b/src/exec.c index 288e18ee..df912a6c 100644 --- a/src/exec.c +++ b/src/exec.c @@ -65,7 +65,7 @@ struct program_list_s typedef struct program_list_and_notification_s { program_list_t *pl; - const notification_t *n; + notification_t n; } program_list_and_notification_t; /* @@ -566,7 +566,7 @@ 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; + const notification_t *n = &((program_list_and_notification_t *) arg)->n; int fd; FILE *fh; int pid; @@ -609,6 +609,7 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); + sfree (arg); pthread_exit ((void *) 0); return (NULL); } /* void *exec_notification_one }}} */ @@ -658,13 +659,14 @@ static int exec_read (void) /* {{{ */ static int exec_notification (const notification_t *n) { program_list_t *pl; + program_list_and_notification_t *pln; for (pl = pl_head; pl != NULL; pl = pl->next) { pthread_t t; pthread_attr_t attr; - /* Only execute `normal' and `nagios' style executables here. */ + /* Only execute `notification' style executables here. */ if ((pl->flags & PL_NOTIF_ACTION) == 0) continue; @@ -672,9 +674,20 @@ static int exec_notification (const notification_t *n) if (pl->pid != 0) continue; + pln = (program_list_and_notification_t *) malloc (sizeof + (program_list_and_notification_t)); + if (pln == NULL) + { + ERROR ("exec plugin: malloc failed."); + continue; + } + + pln->pl = pl; + memcpy (&pln->n, n, sizeof (notification_t)); + pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&t, &attr, exec_notification_one, (void *) pl); + pthread_create (&t, &attr, exec_notification_one, (void *) pln); } /* for (pl) */ return (0);