#define _BSD_SOURCE /* For setgroups */
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include <grp.h>
#include <signal.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
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)
CDTIME_T_TO_DOUBLE (plugin_get_interval ()));
setenv ("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
- ssnprintf (buffer, sizeof (buffer), "%s", hostname_g);
+ sstrncpy (buffer, hostname_g, sizeof (buffer));
setenv ("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
#else
ssnprintf (buffer, sizeof (buffer), "COLLECTD_INTERVAL=%.3f",
else if (pid == 0)
{
int fd_num;
- int fd;
/* 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])
static int parse_line (char *buffer) /* {{{ */
{
if (strncasecmp ("PUTVAL", buffer, strlen ("PUTVAL")) == 0)
- return (handle_putval (stdout, buffer));
+ return (cmd_handle_putval (stdout, buffer));
else if (strncasecmp ("PUTNOTIF", buffer, strlen ("PUTNOTIF")) == 0)
return (handle_putnotif (stdout, buffer));
else
{
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;
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);
sigaction (SIGCHLD, &sa, NULL);
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SETUID) && defined(CAP_SETGID)
+ if ((check_capability (CAP_SETUID) != 0) ||
+ (check_capability (CAP_SETGID) != 0))
+ {
+ if (getuid () == 0)
+ WARNING ("exec plugin: Running collectd as root, but the CAP_SETUID "
+ "or CAP_SETGID capabilities are missing. The plugin's read function "
+ "will probably fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("exec plugin: collectd doesn't have the CAP_SETUID or "
+ "CAP_SETGID capabilities. If you don't want to run collectd as root, "
+ "try running \"setcap 'cap_setuid=ep cap_setgid=ep'\" on the "
+ "collectd binary.");
+ }
+#endif
+
return (0);
} /* int exec_init }}} */
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;
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;
- 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;