X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=71a49181b781ad2d9240263084b33fa6b07b0ee8;hb=dc6f54ccc87c5ae63d29f05eca91714ade689691;hp=f080ad674bac793ceb27feb0f75de67d16385fb4;hpb=0a63e4493d92f7d739a1849bc65d4e971b047004;p=collectd.git diff --git a/src/exec.c b/src/exec.c index f080ad67..71a49181 100644 --- a/src/exec.c +++ b/src/exec.c @@ -38,8 +38,6 @@ #include #include -#include - #define PL_NORMAL 0x01 #define PL_NOTIF_ACTION 0x02 @@ -126,13 +124,12 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl = (program_list_t *) malloc (sizeof (program_list_t)); + pl = calloc (1, sizeof (*pl)); if (pl == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: calloc failed."); return (-1); } - memset (pl, '\0', sizeof (program_list_t)); if (strcasecmp ("NotificationExec", ci->key) == 0) pl->flags |= PL_NOTIF_ACTION; @@ -163,16 +160,15 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl->argv = (char **) malloc (ci->values_num * sizeof (char *)); + pl->argv = calloc (ci->values_num, sizeof (*pl->argv)); if (pl->argv == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: calloc failed."); sfree (pl->exec); sfree (pl->user); sfree (pl); return (-1); } - memset (pl->argv, '\0', ci->values_num * sizeof (char *)); { char *tmp = strrchr (ci->values[1].value.string, '/'); @@ -184,7 +180,7 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ pl->argv[0] = strdup (buffer); if (pl->argv[0] == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: strdup failed."); sfree (pl->argv); sfree (pl->exec); sfree (pl->user); @@ -350,7 +346,6 @@ static void reset_signal_mask (void) /* {{{ */ { sigset_t ss; - memset (&ss, 0, sizeof (ss)); sigemptyset (&ss); sigprocmask (SIG_SETMASK, &ss, /* old mask = */ NULL); } /* }}} void reset_signal_mask */ @@ -744,8 +739,7 @@ static void *exec_notification_one (void *arg) /* {{{ */ char errbuf[1024]; ERROR ("exec plugin: fdopen (%i) failed: %s", fd, sstrerror (errno, errbuf, sizeof (errbuf))); - kill (pl->pid, SIGTERM); - pl->pid = 0; + kill (pid, SIGTERM); close (fd); sfree (arg); pthread_exit ((void *) 1); @@ -809,10 +803,10 @@ static void *exec_notification_one (void *arg) /* {{{ */ static int exec_init (void) /* {{{ */ { - struct sigaction sa; + struct sigaction sa = { + .sa_handler = sigchld_handler + }; - memset (&sa, '\0', sizeof (sa)); - sa.sa_handler = sigchld_handler; sigaction (SIGCHLD, &sa, NULL); return (0); @@ -869,8 +863,7 @@ 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)); + pln = malloc (sizeof (*pln)); if (pln == NULL) { ERROR ("exec plugin: malloc failed.");