#include <sys/socket.h>
#include <sys/un.h>
-#include <sys/poll.h>
#include <grp.h>
value_cache_t *vc;
int i;
- DEBUG ("unixsock plugin: cache_insert: ds->ds_num = %i;"
+ DEBUG ("unixsock plugin: cache_insert: ds->type = %s; ds->ds_num = %i;"
" vl->values_len = %i;",
- ds->ds_num, vl->values_len);
+ ds->type, ds->ds_num, vl->values_len);
+#if COLLECT_DEBUG
assert (ds->ds_num == vl->values_len);
+#else
+ if (ds->ds_num != vl->values_len)
+ {
+ ERROR ("unixsock plugin: ds->type = %s: (ds->ds_num = %i) != "
+ "(vl->values_len = %i)",
+ ds->type, ds->ds_num, vl->values_len);
+ return (-1);
+ }
+#endif
vc = (value_cache_t *) malloc (sizeof (value_cache_t));
if (vc == NULL)
vc = cache_search (name);
+ /* pthread_mutex_lock is called by cache_insert. */
if (vc == NULL)
return (cache_insert (ds, vl));
assert (vc->values_num == ds->ds_num);
assert (vc->values_num == vl->values_len);
+ /* Avoid floating-point exceptions due to division by zero. */
+ if (vc->time >= vl->time)
+ {
+ pthread_mutex_unlock (&cache_lock);
+ ERROR ("unixsock plugin: vc->time >= vl->time. vc->time = %u; "
+ "vl->time = %u; vl = %s;",
+ (unsigned int) vc->time, (unsigned int) vl->time,
+ name);
+ return (-1);
+ } /* if (vc->time >= vl->time) */
+
/*
* Update the values. This is possibly a lot more that you'd expect
* because we honor min and max values and handle counter overflows here.
status = format_name (name, sizeof (name),
hostname, plugin, plugin_instance, type, type_instance);
- /* FIXME: Send some response */
if (status != 0)
+ {
+ fprintf (fh, "-1 format_name failed.\n");
return (-1);
+ }
pthread_mutex_lock (&cache_lock);
return (-1);
}
- /* FIXME: Send some response */
if ((strlen (hostname) > sizeof (vl.host))
|| (strlen (plugin) > sizeof (vl.plugin))
|| ((plugin_instance != NULL)
&& (strlen (plugin_instance) > sizeof (vl.plugin_instance)))
|| ((type_instance != NULL)
&& (strlen (type_instance) > sizeof (vl.type_instance))))
+ {
+ fprintf (fh, "-1 Identifier too long.");
return (-1);
+ }
strcpy (vl.host, hostname);
strcpy (vl.plugin, plugin);
char *t = fields[2];
char *v = strchr (t, ':');
if (v == NULL)
+ {
+ fprintf (fh, "-1 No time found.");
return (-1);
+ }
*v = '\0'; v++;
vl.time = (time_t) atoi (t);
return (-1);
value_ptr = (char **) calloc (ds->ds_num, sizeof (char *));
- /* FIXME: Send some response */
if (value_ptr == NULL)
+ {
+ fprintf (fh, "-1 calloc failed.");
return (-1);
-
+ }
{ /* parse the value-list. It's colon-separated. */
char *dummy;
if (i != ds->ds_num)
{
sfree (value_ptr);
- /* FIXME: Send some response */
+ fprintf (fh, "-1 Number of values incorrect: Got %i, "
+ "expected %i.", i, ds->ds_num);
return (-1);
}
} /* done parsing the value-list */
if (vl.values == NULL)
{
sfree (value_ptr);
+ fprintf (fh, "-1 malloc failed.");
return (-1);
}
DEBUG ("value_ptr = 0x%p; vl.values = 0x%p;", (void *) value_ptr, (void *) vl.values);
}
else
{
- fprintf (fh, "Unknown command: %s\n", fields[0]);
+ fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
fflush (fh);
}
} /* while (fgets) */
close (sock_fd);
sock_fd = -1;
+ status = unlink ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH);
+ if (status != 0)
+ {
+ char errbuf[1024];
+ NOTICE ("unixsock plugin: unlink (%s) failed: %s",
+ (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+
return ((void *) 0);
} /* void *us_server_thread */
return (0);
}
-void module_register (modreg_e load)
+void module_register (void)
{
plugin_register_config ("unixsock", us_config,
config_keys, config_keys_num);