1 /**
2 * collectd - src/unixsock.c
3 * Copyright (C) 2007 Florian octo Forster
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * Author:
19 * Florian octo Forster <octo at verplant.org>
20 **/
22 #include "collectd.h"
23 #include "common.h"
24 #include "plugin.h"
25 #include "configfile.h"
27 /* Folks without pthread will need to disable this plugin. */
28 #include <pthread.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
33 #include <grp.h>
35 #ifndef UNIX_PATH_MAX
36 # define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
37 #endif
39 #define US_DEFAULT_PATH PREFIX"/var/run/"PACKAGE_NAME"-unixsock"
41 /*
42 * Private data structures
43 */
44 /* linked list of cached values */
45 typedef struct value_cache_s
46 {
47 char name[4*DATA_MAX_NAME_LEN];
48 int values_num;
49 gauge_t *gauge;
50 counter_t *counter;
51 const data_set_t *ds;
52 time_t time;
53 struct value_cache_s *next;
54 } value_cache_t;
56 /*
57 * Private variables
58 */
59 /* valid configuration file keys */
60 static const char *config_keys[] =
61 {
62 "SocketFile",
63 "SocketGroup",
64 "SocketPerms",
65 NULL
66 };
67 static int config_keys_num = 3;
69 static int loop = 0;
71 /* socket configuration */
72 static int sock_fd = -1;
73 static char *sock_file = NULL;
74 static char *sock_group = NULL;
75 static int sock_perms = S_IRWXU | S_IRWXG;
77 static pthread_t listen_thread = (pthread_t) 0;
79 /* Linked list and auxilliary variables for saving values */
80 static value_cache_t *cache_head = NULL;
81 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
82 static unsigned int cache_oldest = UINT_MAX;
84 /*
85 * Functions
86 */
87 static value_cache_t *cache_search (const char *name)
88 {
89 value_cache_t *vc;
91 for (vc = cache_head; vc != NULL; vc = vc->next)
92 {
93 if (strcmp (vc->name, name) == 0)
94 break;
95 } /* for vc = cache_head .. NULL */
97 return (vc);
98 } /* value_cache_t *cache_search */
100 static int cache_insert (const data_set_t *ds, const value_list_t *vl)
101 {
102 /* We're called from `cache_update' so we don't need to lock the mutex */
103 value_cache_t *vc;
104 int i;
106 DEBUG ("unixsock plugin: cache_insert: ds->type = %s; ds->ds_num = %i;"
107 " vl->values_len = %i;",
108 ds->type, ds->ds_num, vl->values_len);
109 #if COLLECT_DEBUG
110 assert (ds->ds_num == vl->values_len);
111 #else
112 if (ds->ds_num != vl->values_len)
113 {
114 ERROR ("unixsock plugin: ds->type = %s: (ds->ds_num = %i) != "
115 "(vl->values_len = %i)",
116 ds->type, ds->ds_num, vl->values_len);
117 return (-1);
118 }
119 #endif
121 vc = (value_cache_t *) malloc (sizeof (value_cache_t));
122 if (vc == NULL)
123 {
124 char errbuf[1024];
125 pthread_mutex_unlock (&cache_lock);
126 ERROR ("unixsock plugin: malloc failed: %s",
127 sstrerror (errno, errbuf, sizeof (errbuf)));
128 return (-1);
129 }
131 vc->gauge = (gauge_t *) malloc (sizeof (gauge_t) * vl->values_len);
132 if (vc->gauge == NULL)
133 {
134 char errbuf[1024];
135 pthread_mutex_unlock (&cache_lock);
136 ERROR ("unixsock plugin: malloc failed: %s",
137 sstrerror (errno, errbuf, sizeof (errbuf)));
138 free (vc);
139 return (-1);
140 }
142 vc->counter = (counter_t *) malloc (sizeof (counter_t) * vl->values_len);
143 if (vc->counter == NULL)
144 {
145 char errbuf[1024];
146 pthread_mutex_unlock (&cache_lock);
147 ERROR ("unixsock plugin: malloc failed: %s",
148 sstrerror (errno, errbuf, sizeof (errbuf)));
149 free (vc->gauge);
150 free (vc);
151 return (-1);
152 }
154 if (FORMAT_VL (vc->name, sizeof (vc->name), vl, ds))
155 {
156 pthread_mutex_unlock (&cache_lock);
157 ERROR ("unixsock plugin: FORMAT_VL failed.");
158 free (vc->counter);
159 free (vc->gauge);
160 free (vc);
161 return (-1);
162 }
164 for (i = 0; i < ds->ds_num; i++)
165 {
166 if (ds->ds[i].type == DS_TYPE_COUNTER)
167 {
168 vc->gauge[i] = 0.0;
169 vc->counter[i] = vl->values[i].counter;
170 }
171 else if (ds->ds[i].type == DS_TYPE_GAUGE)
172 {
173 vc->gauge[i] = vl->values[i].gauge;
174 vc->counter[i] = 0;
175 }
176 else
177 {
178 vc->gauge[i] = 0.0;
179 vc->counter[i] = 0;
180 }
181 }
182 vc->values_num = ds->ds_num;
183 vc->ds = ds;
185 vc->next = cache_head;
186 cache_head = vc;
188 vc->time = vl->time;
189 if (vc->time < cache_oldest)
190 cache_oldest = vc->time;
192 pthread_mutex_unlock (&cache_lock);
193 return (0);
194 } /* int cache_insert */
196 static int cache_update (const data_set_t *ds, const value_list_t *vl)
197 {
198 char name[4*DATA_MAX_NAME_LEN];;
199 value_cache_t *vc;
200 int i;
202 if (FORMAT_VL (name, sizeof (name), vl, ds) != 0)
203 return (-1);
205 pthread_mutex_lock (&cache_lock);
207 vc = cache_search (name);
209 /* pthread_mutex_lock is called by cache_insert. */
210 if (vc == NULL)
211 return (cache_insert (ds, vl));
213 assert (vc->values_num == ds->ds_num);
214 assert (vc->values_num == vl->values_len);
216 /* Avoid floating-point exceptions due to division by zero. */
217 if (vc->time >= vl->time)
218 {
219 pthread_mutex_unlock (&cache_lock);
220 ERROR ("unixsock plugin: vc->time >= vl->time. vc->time = %u; "
221 "vl->time = %u; vl = %s;",
222 (unsigned int) vc->time, (unsigned int) vl->time,
223 name);
224 return (-1);
225 } /* if (vc->time >= vl->time) */
227 /*
228 * Update the values. This is possibly a lot more that you'd expect
229 * because we honor min and max values and handle counter overflows here.
230 */
231 for (i = 0; i < ds->ds_num; i++)
232 {
233 if (ds->ds[i].type == DS_TYPE_COUNTER)
234 {
235 if (vl->values[i].counter < vc->counter[i])
236 {
237 if (vl->values[i].counter <= 4294967295U)
238 {
239 vc->gauge[i] = ((4294967295U - vl->values[i].counter)
240 + vc->counter[i]) / (vl->time - vc->time);
241 }
242 else
243 {
244 vc->gauge[i] = ((18446744073709551615ULL - vl->values[i].counter)
245 + vc->counter[i]) / (vl->time - vc->time);
246 }
247 }
248 else
249 {
250 vc->gauge[i] = (vl->values[i].counter - vc->counter[i])
251 / (vl->time - vc->time);
252 }
254 vc->counter[i] = vl->values[i].counter;
255 }
256 else if (ds->ds[i].type == DS_TYPE_GAUGE)
257 {
258 vc->gauge[i] = vl->values[i].gauge;
259 vc->counter[i] = 0;
260 }
261 else
262 {
263 vc->gauge[i] = NAN;
264 vc->counter[i] = 0;
265 }
267 if (isnan (vc->gauge[i])
268 || (!isnan (ds->ds[i].min) && (vc->gauge[i] < ds->ds[i].min))
269 || (!isnan (ds->ds[i].max) && (vc->gauge[i] > ds->ds[i].max)))
270 vc->gauge[i] = NAN;
271 } /* for i = 0 .. ds->ds_num */
273 vc->ds = ds;
274 vc->time = vl->time;
276 if (vc->time < cache_oldest)
277 cache_oldest = vc->time;
279 pthread_mutex_unlock (&cache_lock);
280 return (0);
281 } /* int cache_update */
283 static void cache_flush (int max_age)
284 {
285 value_cache_t *this;
286 value_cache_t *prev;
287 time_t now;
289 pthread_mutex_lock (&cache_lock);
291 now = time (NULL);
293 if ((now - cache_oldest) <= max_age)
294 {
295 pthread_mutex_unlock (&cache_lock);
296 return;
297 }
299 cache_oldest = now;
301 prev = NULL;
302 this = cache_head;
304 while (this != NULL)
305 {
306 if ((now - this->time) <= max_age)
307 {
308 if (this->time < cache_oldest)
309 cache_oldest = this->time;
311 prev = this;
312 this = this->next;
313 continue;
314 }
316 if (prev == NULL)
317 cache_head = this->next;
318 else
319 prev->next = this->next;
321 free (this->gauge);
322 free (this->counter);
323 free (this);
325 if (prev == NULL)
326 this = cache_head;
327 else
328 this = prev->next;
329 } /* while (this != NULL) */
331 pthread_mutex_unlock (&cache_lock);
332 } /* int cache_flush */
334 static int us_open_socket (void)
335 {
336 struct sockaddr_un sa;
337 int status;
339 sock_fd = socket (PF_UNIX, SOCK_STREAM, 0);
340 if (sock_fd < 0)
341 {
342 char errbuf[1024];
343 ERROR ("unixsock plugin: socket failed: %s",
344 sstrerror (errno, errbuf, sizeof (errbuf)));
345 return (-1);
346 }
348 memset (&sa, '\0', sizeof (sa));
349 sa.sun_family = AF_UNIX;
350 strncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
351 sizeof (sa.sun_path) - 1);
352 /* unlink (sa.sun_path); */
354 status = bind (sock_fd, (struct sockaddr *) &sa, sizeof (sa));
355 if (status != 0)
356 {
357 char errbuf[1024];
358 sstrerror (errno, errbuf, sizeof (errbuf));
359 DEBUG ("bind failed: %s; sa.sun_path = %s", errbuf, sa.sun_path);
360 ERROR ("unixsock plugin: bind failed: %s", errbuf);
361 close (sock_fd);
362 sock_fd = -1;
363 return (-1);
364 }
366 status = listen (sock_fd, 8);
367 if (status != 0)
368 {
369 char errbuf[1024];
370 ERROR ("unixsock plugin: listen failed: %s",
371 sstrerror (errno, errbuf, sizeof (errbuf)));
372 close (sock_fd);
373 sock_fd = -1;
374 return (-1);
375 }
377 do
378 {
379 char *grpname;
380 struct group *g;
381 struct group sg;
382 char grbuf[2048];
384 grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME;
385 g = NULL;
387 status = getgrnam_r (grpname, &sg, grbuf, sizeof (grbuf), &g);
388 if (status != 0)
389 {
390 char errbuf[1024];
391 WARNING ("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
392 sstrerror (errno, errbuf, sizeof (errbuf)));
393 break;
394 }
395 if (g == NULL)
396 {
397 WARNING ("unixsock plugin: No such group: `%s'",
398 grpname);
399 break;
400 }
402 if (chown ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
403 (uid_t) -1, g->gr_gid) != 0)
404 {
405 char errbuf[1024];
406 WARNING ("unixsock plugin: chown (%s, -1, %i) failed: %s",
407 (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
408 (int) g->gr_gid,
409 sstrerror (errno, errbuf, sizeof (errbuf)));
410 }
411 } while (0);
413 return (0);
414 } /* int us_open_socket */
416 static int us_handle_getval (FILE *fh, char **fields, int fields_num)
417 {
418 char *hostname;
419 char *plugin;
420 char *plugin_instance;
421 char *type;
422 char *type_instance;
423 char name[4*DATA_MAX_NAME_LEN];
424 value_cache_t *vc;
425 int status;
426 int i;
428 if (fields_num != 2)
429 {
430 DEBUG ("unixsock plugin: Wrong number of fields: %i", fields_num);
431 fprintf (fh, "-1 Wrong number of fields: Got %i, expected 2.\n",
432 fields_num);
433 fflush (fh);
434 return (-1);
435 }
436 DEBUG ("unixsock plugin: Got query for `%s'", fields[1]);
438 status = parse_identifier (fields[1], &hostname,
439 &plugin, &plugin_instance,
440 &type, &type_instance);
441 if (status != 0)
442 {
443 DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]);
444 fprintf (fh, "-1 Cannot parse identifier.\n");
445 fflush (fh);
446 return (-1);
447 }
449 status = format_name (name, sizeof (name),
450 hostname, plugin, plugin_instance, type, type_instance);
451 if (status != 0)
452 {
453 fprintf (fh, "-1 format_name failed.\n");
454 return (-1);
455 }
457 pthread_mutex_lock (&cache_lock);
459 DEBUG ("vc = cache_search (%s)", name);
460 vc = cache_search (name);
462 if (vc == NULL)
463 {
464 DEBUG ("Did not find cache entry.");
465 fprintf (fh, "-1 No such value");
466 }
467 else
468 {
469 DEBUG ("Found cache entry.");
470 fprintf (fh, "%i", vc->values_num);
471 for (i = 0; i < vc->values_num; i++)
472 {
473 fprintf (fh, " %s=", vc->ds->ds[i].name);
474 if (isnan (vc->gauge[i]))
475 fprintf (fh, "NaN");
476 else
477 fprintf (fh, "%12e", vc->gauge[i]);
478 }
479 }
481 /* Free the mutex as soon as possible and definitely before flushing */
482 pthread_mutex_unlock (&cache_lock);
484 fprintf (fh, "\n");
485 fflush (fh);
487 return (0);
488 } /* int us_handle_getval */
490 static int us_handle_putval (FILE *fh, char **fields, int fields_num)
491 {
492 char *hostname;
493 char *plugin;
494 char *plugin_instance;
495 char *type;
496 char *type_instance;
497 int status;
498 int i;
500 const data_set_t *ds;
501 value_list_t vl = VALUE_LIST_INIT;
503 char **value_ptr;
505 if (fields_num != 3)
506 {
507 DEBUG ("unixsock plugin: Wrong number of fields: %i", fields_num);
508 fprintf (fh, "-1 Wrong number of fields: Got %i, expected 3.\n",
509 fields_num);
510 fflush (fh);
511 return (-1);
512 }
514 status = parse_identifier (fields[1], &hostname,
515 &plugin, &plugin_instance,
516 &type, &type_instance);
517 if (status != 0)
518 {
519 DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]);
520 fprintf (fh, "-1 Cannot parse identifier.\n");
521 fflush (fh);
522 return (-1);
523 }
525 if ((strlen (hostname) >= sizeof (vl.host))
526 || (strlen (plugin) >= sizeof (vl.plugin))
527 || ((plugin_instance != NULL)
528 && (strlen (plugin_instance) >= sizeof (vl.plugin_instance)))
529 || ((type_instance != NULL)
530 && (strlen (type_instance) >= sizeof (vl.type_instance))))
531 {
532 fprintf (fh, "-1 Identifier too long.");
533 return (-1);
534 }
536 strcpy (vl.host, hostname);
537 strcpy (vl.plugin, plugin);
538 if (plugin_instance != NULL)
539 strcpy (vl.plugin_instance, plugin_instance);
540 if (type_instance != NULL)
541 strcpy (vl.type_instance, type_instance);
543 { /* parse the time */
544 char *t = fields[2];
545 char *v = strchr (t, ':');
546 if (v == NULL)
547 {
548 fprintf (fh, "-1 No time found.");
549 return (-1);
550 }
551 *v = '\0'; v++;
553 vl.time = (time_t) atoi (t);
554 if (vl.time == 0)
555 vl.time = time (NULL);
557 fields[2] = v;
558 }
560 ds = plugin_get_ds (type);
561 if (ds == NULL)
562 return (-1);
564 value_ptr = (char **) calloc (ds->ds_num, sizeof (char *));
565 if (value_ptr == NULL)
566 {
567 fprintf (fh, "-1 calloc failed.");
568 return (-1);
569 }
571 { /* parse the value-list. It's colon-separated. */
572 char *dummy;
573 char *ptr;
574 char *saveptr;
576 i = 0;
577 dummy = fields[2];
578 saveptr = NULL;
579 while ((ptr = strtok_r (dummy, ":", &saveptr)) != NULL)
580 {
581 dummy = NULL;
582 if (i >= ds->ds_num)
583 {
584 i = ds->ds_num + 1;
585 break;
586 }
587 value_ptr[i] = ptr;
588 i++;
589 }
591 if (i != ds->ds_num)
592 {
593 sfree (value_ptr);
594 fprintf (fh, "-1 Number of values incorrect: Got %i, "
595 "expected %i.", i, ds->ds_num);
596 return (-1);
597 }
598 } /* done parsing the value-list */
600 vl.values_len = ds->ds_num;
601 vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
602 if (vl.values == NULL)
603 {
604 sfree (value_ptr);
605 fprintf (fh, "-1 malloc failed.");
606 return (-1);
607 }
608 DEBUG ("value_ptr = 0x%p; vl.values = 0x%p;", (void *) value_ptr, (void *) vl.values);
610 for (i = 0; i < ds->ds_num; i++)
611 {
612 if (strcmp (value_ptr[i], "U") == 0)
613 vl.values[i].gauge = NAN;
614 else if (ds->ds[i].type == DS_TYPE_COUNTER)
615 vl.values[i].counter = atoll (value_ptr[i]);
616 else if (ds->ds[i].type == DS_TYPE_GAUGE)
617 vl.values[i].gauge = atof (value_ptr[i]);
618 } /* for (i = 2 .. fields_num) */
620 plugin_dispatch_values (type, &vl);
622 DEBUG ("value_ptr = 0x%p; vl.values = 0x%p;", (void *) value_ptr, (void *) vl.values);
624 sfree (value_ptr);
625 sfree (vl.values);
627 fprintf (fh, "0 Success\n");
628 fflush (fh);
630 return (0);
631 } /* int us_handle_putval */
633 static void *us_handle_client (void *arg)
634 {
635 int fd;
636 FILE *fh;
637 char buffer[1024];
638 char *fields[128];
639 int fields_num;
641 fd = *((int *) arg);
642 free (arg);
643 arg = NULL;
645 DEBUG ("Reading from fd #%i", fd);
647 fh = fdopen (fd, "r+");
648 if (fh == NULL)
649 {
650 char errbuf[1024];
651 ERROR ("unixsock plugin: fdopen failed: %s",
652 sstrerror (errno, errbuf, sizeof (errbuf)));
653 close (fd);
654 pthread_exit ((void *) 1);
655 }
657 while (fgets (buffer, sizeof (buffer), fh) != NULL)
658 {
659 int len;
661 len = strlen (buffer);
662 while ((len > 0)
663 && ((buffer[len - 1] == '\n') || (buffer[len - 1] == '\r')))
664 buffer[--len] = '\0';
666 if (len == 0)
667 continue;
669 DEBUG ("fgets -> buffer = %s; len = %i;", buffer, len);
671 fields_num = strsplit (buffer, fields,
672 sizeof (fields) / sizeof (fields[0]));
674 if (fields_num < 1)
675 {
676 close (fd);
677 break;
678 }
680 if (strcasecmp (fields[0], "getval") == 0)
681 {
682 us_handle_getval (fh, fields, fields_num);
683 }
684 else if (strcasecmp (fields[0], "putval") == 0)
685 {
686 us_handle_putval (fh, fields, fields_num);
687 }
688 else
689 {
690 fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
691 fflush (fh);
692 }
693 } /* while (fgets) */
695 DEBUG ("Exiting..");
696 close (fd);
698 pthread_exit ((void *) 0);
699 } /* void *us_handle_client */
701 static void *us_server_thread (void *arg)
702 {
703 int status;
704 int *remote_fd;
705 pthread_t th;
706 pthread_attr_t th_attr;
708 if (us_open_socket () != 0)
709 pthread_exit ((void *) 1);
711 while (loop != 0)
712 {
713 DEBUG ("Calling accept..");
714 status = accept (sock_fd, NULL, NULL);
715 if (status < 0)
716 {
717 char errbuf[1024];
719 if (errno == EINTR)
720 continue;
722 ERROR ("unixsock plugin: accept failed: %s",
723 sstrerror (errno, errbuf, sizeof (errbuf)));
724 close (sock_fd);
725 sock_fd = -1;
726 pthread_exit ((void *) 1);
727 }
729 remote_fd = (int *) malloc (sizeof (int));
730 if (remote_fd == NULL)
731 {
732 char errbuf[1024];
733 WARNING ("unixsock plugin: malloc failed: %s",
734 sstrerror (errno, errbuf, sizeof (errbuf)));
735 close (status);
736 continue;
737 }
738 *remote_fd = status;
740 DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd);
742 pthread_attr_init (&th_attr);
743 pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED);
745 status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd);
746 if (status != 0)
747 {
748 char errbuf[1024];
749 WARNING ("unixsock plugin: pthread_create failed: %s",
750 sstrerror (errno, errbuf, sizeof (errbuf)));
751 close (*remote_fd);
752 free (remote_fd);
753 continue;
754 }
755 } /* while (loop) */
757 close (sock_fd);
758 sock_fd = -1;
760 status = unlink ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH);
761 if (status != 0)
762 {
763 char errbuf[1024];
764 NOTICE ("unixsock plugin: unlink (%s) failed: %s",
765 (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
766 sstrerror (errno, errbuf, sizeof (errbuf)));
767 }
769 return ((void *) 0);
770 } /* void *us_server_thread */
772 static int us_config (const char *key, const char *val)
773 {
774 if (strcasecmp (key, "SocketFile") == 0)
775 {
776 sfree (sock_file);
777 sock_file = strdup (val);
778 }
779 else if (strcasecmp (key, "SocketGroup") == 0)
780 {
781 sfree (sock_group);
782 sock_group = strdup (val);
783 }
784 else if (strcasecmp (key, "SocketPerms") == 0)
785 {
786 sock_perms = (int) strtol (val, NULL, 8);
787 }
788 else
789 {
790 return (-1);
791 }
793 return (0);
794 } /* int us_config */
796 static int us_init (void)
797 {
798 int status;
800 loop = 1;
802 status = pthread_create (&listen_thread, NULL, us_server_thread, NULL);
803 if (status != 0)
804 {
805 char errbuf[1024];
806 ERROR ("unixsock plugin: pthread_create failed: %s",
807 sstrerror (errno, errbuf, sizeof (errbuf)));
808 return (-1);
809 }
811 return (0);
812 } /* int us_init */
814 static int us_shutdown (void)
815 {
816 void *ret;
818 loop = 0;
820 if (listen_thread != (pthread_t) 0)
821 {
822 pthread_kill (listen_thread, SIGTERM);
823 pthread_join (listen_thread, &ret);
824 listen_thread = (pthread_t) 0;
825 }
827 plugin_unregister_init ("unixsock");
828 plugin_unregister_write ("unixsock");
829 plugin_unregister_shutdown ("unixsock");
831 return (0);
832 } /* int us_shutdown */
834 static int us_write (const data_set_t *ds, const value_list_t *vl)
835 {
836 cache_update (ds, vl);
837 cache_flush (2 * interval_g);
839 return (0);
840 }
842 void module_register (void)
843 {
844 plugin_register_config ("unixsock", us_config,
845 config_keys, config_keys_num);
846 plugin_register_init ("unixsock", us_init);
847 plugin_register_write ("unixsock", us_write);
848 plugin_register_shutdown ("unixsock", us_shutdown);
849 } /* void module_register (void) */
851 /* vim: set sw=4 ts=4 sts=4 tw=78 : */