X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=3a72ebac8e9ff50d4a4e7491fb3e3e1defa4a453;hb=a62bc47e3bea0733c354976c17885e3f579a38c5;hp=d2b2508db209b87fb302ec35dee558016e01cabb;hpb=085a993e0f187ad73d3a28cea508ec6e56c39516;p=collectd.git diff --git a/src/exec.c b/src/exec.c index d2b2508d..3a72ebac 100644 --- a/src/exec.c +++ b/src/exec.c @@ -23,6 +23,8 @@ * Peter Holik **/ +#define _BSD_SOURCE /* For setgroups */ + #include "collectd.h" #include "common.h" #include "plugin.h" @@ -279,8 +281,8 @@ static void exec_child (program_list_t *pl) /* {{{ */ status = getpwnam_r (pl->user, &sp, nambuf, sizeof (nambuf), &sp_ptr); if (status != 0) { - ERROR ("exec plugin: getpwnam_r failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); + ERROR ("exec plugin: Failed to get user information for user ``%s'': %s", + pl->user, sstrerror (errno, errbuf, sizeof (errbuf))); exit (-1); } if (sp_ptr == NULL) @@ -309,7 +311,8 @@ static void exec_child (program_list_t *pl) /* {{{ */ status = getgrnam_r (pl->group, &gr, nambuf, sizeof (nambuf), &gr_ptr); if (0 != status) { - ERROR ("exec plugin: getgrnam_r failed: %s", + ERROR ("exec plugin: Failed to get group information " + "for group ``%s'': %s", pl->group, sstrerror (errno, errbuf, sizeof (errbuf))); exit (-1); } @@ -375,11 +378,20 @@ static void exec_child (program_list_t *pl) /* {{{ */ status = execvp (pl->exec, pl->argv); - ERROR ("exec plugin: exec failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); + ERROR ("exec plugin: Failed to execute ``%s'': %s", + pl->exec, sstrerror (errno, errbuf, sizeof (errbuf))); exit (-1); } /* void exec_child }}} */ +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 */ + /* * Creates three pipes (one for reading, one for writing and one for errors), * forks a child, sets up the pipes so that fd_in is connected to STDIN of @@ -466,6 +478,9 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) close (fd_pipe_err[1]); } + /* Unblock all signals */ + reset_signal_mask (); + exec_child (pl); /* does not return */ } @@ -728,7 +743,8 @@ static void *exec_notification_one (void *arg) /* {{{ */ DEBUG ("exec plugin: Child %i exited with status %i.", pid, status); - plugin_notification_meta_free (n->meta); + if (n->meta != NULL) + plugin_notification_meta_free (n->meta); n->meta = NULL; sfree (arg); pthread_exit ((void *) 0);