=head1 VALUE IDENTIFIER
-The values in the collectd are identified using an five-tupel (host, plugin,
+The values in the collectd are identified using an five-tuple (host, plugin,
plugin-instance, type, type-instance) where only plugin-instance and
type-instance may be NULL (or undefined). Many functions expect an
I<%identifier> hash that has at least the members B<host>, B<plugin>, and
=item I<$obj>-E<gt>B<putval> (I<%identifier>, B<time> =E<gt> I<$time>, B<values> =E<gt> [...]);
Submits a value-list to the daemon. If the B<time> argument is omitted
-C<time()> is used. The requierd argument B<values> is a reference to an array
+C<time()> is used. The required argument B<values> is a reference to an array
of values that is to be submitted. The number of values must match the number
of values expected for the given B<type> (see L<VALUE IDENTIFIER>), though this
is checked by the daemon, not the Perl module. Also, gauge data-sources
=head1 ABSTRACTION LAYER
-Shipped with the sourcecode comes the Perl-Module L<Collectd::Unixsock> which
+B<collectd> ships the Perl-Module L<Collectd::Unixsock> which
provides an abstraction layer over the actual socket connection. It can be
-found in the directory F<contrib/PerlLib>. If you want to use Perl to
-communicate with the daemon, you're encouraged to use and expand this module.
+found in the directory F<bindings/perl/> in the source distribution or
+(usually) somewhere near F</usr/share/perl5/> if you're using a package. If
+you want to use Perl to communicate with the daemon, you're encouraged to use
+and expand this module.
=head1 SEE ALSO
static void *us_handle_client (void *arg)
{
int fd;
- FILE *fh;
+ FILE *fhin, *fhout;
char buffer[1024];
char *fields[128];
int fields_num;
DEBUG ("Reading from fd #%i", fd);
- fh = fdopen (fd, "r+");
- if (fh == NULL)
+ fhin = fdopen (fd, "r");
+ if (fhin == NULL)
{
char errbuf[1024];
ERROR ("unixsock plugin: fdopen failed: %s",
pthread_exit ((void *) 1);
}
- while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ fhout = fdopen (fd, "w");
+ if (fhout == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("unixsock plugin: fdopen failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ fclose (fhin); /* this closes fd as well */
+ pthread_exit ((void *) 1);
+ }
+
+ while (fgets (buffer, sizeof (buffer), fhin) != NULL)
{
int len;
if (strcasecmp (fields[0], "getval") == 0)
{
- us_handle_getval (fh, fields, fields_num);
+ us_handle_getval (fhout, fields, fields_num);
}
else if (strcasecmp (fields[0], "putval") == 0)
{
- handle_putval (fh, fields, fields_num);
+ handle_putval (fhout, fields, fields_num);
}
else if (strcasecmp (fields[0], "listval") == 0)
{
- us_handle_listval (fh, fields, fields_num);
+ us_handle_listval (fhout, fields, fields_num);
}
else if (strcasecmp (fields[0], "putnotif") == 0)
{
- handle_putnotif (fh, fields, fields_num);
+ handle_putnotif (fhout, fields, fields_num);
}
else
{
- fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
- fflush (fh);
+ fprintf (fhout, "-1 Unknown command: %s\n", fields[0]);
+ fflush (fhout);
}
} /* while (fgets) */
DEBUG ("Exiting..");
- close (fd);
+ fclose (fhin);
+ fclose (fhout);
pthread_exit ((void *) 0);
return ((void *) 0);
status = parse_option (&n, fields[i]);
if (status != 0)
{
- fprintf (fh, "-1 Error parsing option `%s'", fields[i]);
+ fprintf (fh, "-1 Error parsing option `%s'\n", fields[i]);
break;
}
}
char *value_str = strchr (time_str, ':');
if (value_str == NULL)
{
- fprintf (fh, "-1 No time found.");
+ fprintf (fh, "-1 No time found.\n");
return (-1);
}
*value_str = '\0'; value_str++;
int status;
int i;
+ char *identifier_copy;
+
const data_set_t *ds;
value_list_t vl = VALUE_LIST_INIT;
return (-1);
}
- status = parse_identifier (fields[1], &hostname,
+ /* parse_identifier() modifies its first argument,
+ * returning pointers into it */
+ identifier_copy = sstrdup (fields[1]);
+
+ status = parse_identifier (identifier_copy, &hostname,
&plugin, &plugin_instance,
&type, &type_instance);
if (status != 0)
DEBUG ("cmd putval: Cannot parse `%s'", fields[1]);
fprintf (fh, "-1 Cannot parse identifier.\n");
fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
|| ((type_instance != NULL)
&& (strlen (type_instance) >= sizeof (vl.type_instance))))
{
- fprintf (fh, "-1 Identifier too long.");
+ fprintf (fh, "-1 Identifier too long.\n");
+ fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
strcpy (vl.type_instance, type_instance);
ds = plugin_get_ds (type);
- if (ds == NULL)
+ if (ds == NULL) {
+ sfree (identifier_copy);
return (-1);
+ }
vl.values_len = ds->ds_num;
vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
if (vl.values == NULL)
{
- fprintf (fh, "-1 malloc failed.");
+ fprintf (fh, "-1 malloc failed.\n");
+ fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
{
if (parse_option (&vl, fields[i]) != 0)
{
- fprintf (fh, "-1 Error parsing option `%s'",
+ fprintf (fh, "-1 Error parsing option `%s'\n",
fields[i]);
break;
}
fflush (fh);
sfree (vl.values);
+ sfree (identifier_copy);
return (0);
} /* int handle_putval */