projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1856 from rubenk/snmp-dont-dispatch-values-with-empty-type-instance
[collectd.git]
/
src
/
exec.c
diff --git
a/src/exec.c
b/src/exec.c
index
699be61
..
e90f83c
100644
(file)
--- a/
src/exec.c
+++ b/
src/exec.c
@@
-27,6
+27,7
@@
#define _BSD_SOURCE /* For setgroups */
#include "collectd.h"
#define _BSD_SOURCE /* For setgroups */
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
@@
-38,8
+39,6
@@
#include <grp.h>
#include <signal.h>
#include <grp.h>
#include <signal.h>
-#include <pthread.h>
-
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
@@
-126,13
+125,12
@@
static int exec_config_exec (oconfig_item_t *ci) /* {{{ */
return (-1);
}
return (-1);
}
- pl =
(program_list_t *) malloc (sizeof (program_list_t
));
+ pl =
calloc (1, sizeof (*pl
));
if (pl == NULL)
{
if (pl == NULL)
{
- ERROR ("exec plugin:
m
alloc failed.");
+ ERROR ("exec plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (pl, '\0', sizeof (program_list_t));
if (strcasecmp ("NotificationExec", ci->key) == 0)
pl->flags |= PL_NOTIF_ACTION;
if (strcasecmp ("NotificationExec", ci->key) == 0)
pl->flags |= PL_NOTIF_ACTION;
@@
-163,16
+161,15
@@
static int exec_config_exec (oconfig_item_t *ci) /* {{{ */
return (-1);
}
return (-1);
}
- pl->argv =
(char **) malloc (ci->values_num * sizeof (char *
));
+ pl->argv =
calloc (ci->values_num, sizeof (*pl->argv
));
if (pl->argv == NULL)
{
if (pl->argv == NULL)
{
- ERROR ("exec plugin:
m
alloc failed.");
+ ERROR ("exec plugin:
c
alloc failed.");
sfree (pl->exec);
sfree (pl->user);
sfree (pl);
return (-1);
}
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, '/');
{
char *tmp = strrchr (ci->values[1].value.string, '/');
@@
-184,7
+181,7
@@
static int exec_config_exec (oconfig_item_t *ci) /* {{{ */
pl->argv[0] = strdup (buffer);
if (pl->argv[0] == NULL)
{
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);
sfree (pl->argv);
sfree (pl->exec);
sfree (pl->user);
@@
-249,9
+246,7
@@
static int exec_config_exec (oconfig_item_t *ci) /* {{{ */
static int exec_config (oconfig_item_t *ci) /* {{{ */
{
static int exec_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if ((strcasecmp ("Exec", child->key) == 0)
{
oconfig_item_t *child = ci->children + i;
if ((strcasecmp ("Exec", child->key) == 0)
@@
-350,7
+345,6
@@
static void reset_signal_mask (void) /* {{{ */
{
sigset_t ss;
{
sigset_t ss;
- memset (&ss, 0, sizeof (ss));
sigemptyset (&ss);
sigprocmask (SIG_SETMASK, &ss, /* old mask = */ NULL);
} /* }}} void reset_signal_mask */
sigemptyset (&ss);
sigprocmask (SIG_SETMASK, &ss, /* old mask = */ NULL);
} /* }}} void reset_signal_mask */
@@
-475,11
+469,10
@@
static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err)
else if (pid == 0)
{
int fd_num;
else if (pid == 0)
{
int fd_num;
- int fd;
/* Close all file descriptors but the pipe end we need. */
fd_num = getdtablesize ();
/* Close all file descriptors but the pipe end we need. */
fd_num = getdtablesize ();
- for (fd = 0; fd < fd_num; fd++)
+ for (
int
fd = 0; fd < fd_num; fd++)
{
if ((fd == fd_pipe_in[0])
|| (fd == fd_pipe_out[1])
{
if ((fd == fd_pipe_in[0])
|| (fd == fd_pipe_out[1])
@@
-725,7
+718,6
@@
static void *exec_notification_one (void *arg) /* {{{ */
{
program_list_t *pl = ((program_list_and_notification_t *) arg)->pl;
notification_t *n = &((program_list_and_notification_t *) arg)->n;
{
program_list_t *pl = ((program_list_and_notification_t *) arg)->pl;
notification_t *n = &((program_list_and_notification_t *) arg)->n;
- notification_meta_t *meta;
int fd;
FILE *fh;
int pid;
int fd;
FILE *fh;
int pid;
@@
-773,7
+765,7
@@
static void *exec_notification_one (void *arg) /* {{{ */
if (strlen (n->type_instance) > 0)
fprintf (fh, "TypeInstance: %s\n", n->type_instance);
if (strlen (n->type_instance) > 0)
fprintf (fh, "TypeInstance: %s\n", n->type_instance);
- for (meta = n->meta; meta != NULL; meta = meta->next)
+ for (
notification_meta_t *
meta = n->meta; meta != NULL; meta = meta->next)
{
if (meta->type == NM_TYPE_STRING)
fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string);
{
if (meta->type == NM_TYPE_STRING)
fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string);
@@
-808,10
+800,10
@@
static void *exec_notification_one (void *arg) /* {{{ */
static int exec_init (void) /* {{{ */
{
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);
sigaction (SIGCHLD, &sa, NULL);
return (0);
@@
-819,9
+811,7
@@
static int exec_init (void) /* {{{ */
static int exec_read (void) /* {{{ */
{
static int exec_read (void) /* {{{ */
{
- program_list_t *pl;
-
- for (pl = pl_head; pl != NULL; pl = pl->next)
+ for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next)
{
pthread_t t;
pthread_attr_t attr;
{
pthread_t t;
pthread_attr_t attr;
@@
-852,10
+842,9
@@
static int exec_read (void) /* {{{ */
static int exec_notification (const notification_t *n, /* {{{ */
user_data_t __attribute__((unused)) *user_data)
{
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;
program_list_and_notification_t *pln;
- for (pl = pl_head; pl != NULL; pl = pl->next)
+ for (p
rogram_list_t *p
l = pl_head; pl != NULL; pl = pl->next)
{
pthread_t t;
pthread_attr_t attr;
{
pthread_t t;
pthread_attr_t attr;
@@
-868,8
+857,7
@@
static int exec_notification (const notification_t *n, /* {{{ */
if (pl->pid != 0)
continue;
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.");
if (pln == NULL)
{
ERROR ("exec plugin: malloc failed.");