80cb4bd6b22f49134fec440dba889e734019cb71
1 /**
2 * collectd - src/email.c
3 * Copyright (C) 2006 Sebastian Harl
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; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Author:
20 * Sebastian Harl <sh at tokkee.org>
21 **/
23 /*
24 * This plugin communicates with a spam filter, a virus scanner or similar
25 * software using a UNIX socket and a very simple protocol:
26 *
27 * e-mail type (e.g. ham, spam, virus, ...) and size
28 * e:<type>:<bytes>
29 *
30 * spam score
31 * s:<value>
32 *
33 * successful spam checks
34 * c:<type1>[,<type2>,...]
35 */
37 #include "collectd.h"
38 #include "common.h"
39 #include "plugin.h"
41 #include "configfile.h"
43 #if HAVE_LIBPTHREAD
44 # include <pthread.h>
45 # define EMAIL_HAVE_READ 1
46 #else
47 # define EMAIL_HAVE_READ 0
48 #endif
50 #if HAVE_SYS_SELECT_H
51 # include <sys/select.h>
52 #endif /* HAVE_SYS_SELECT_H */
54 #if HAVE_SYS_SOCKET_H
55 # include <sys/socket.h>
56 #endif /* HAVE_SYS_SOCKET_H */
58 /* *sigh* glibc does not define UNIX_PATH_MAX in sys/un.h ... */
59 #if HAVE_LINUX_UN_H
60 # include <linux/un.h>
61 #elif HAVE_SYS_UN_H
62 # include <sys/un.h>
63 #endif /* HAVE_LINUX_UN_H | HAVE_SYS_UN_H */
65 #if HAVE_GRP_H
66 # include <grp.h>
67 #endif /* HAVE_GRP_H */
69 #define MODULE_NAME "email"
71 /* 256 bytes ought to be enough for anybody ;-) */
72 #define BUFSIZE 256
74 #define SOCK_PATH "/tmp/.collectd-email"
75 #define MAX_CONNS 5
76 #define MAX_CONNS_LIMIT 16384
78 /*
79 * Private data structures
80 */
81 #if EMAIL_HAVE_READ
82 /* linked list of email and check types */
83 typedef struct type {
84 char *name;
85 int value;
86 struct type *next;
87 } type_t;
89 typedef struct {
90 type_t *head;
91 type_t *tail;
92 } type_list_t;
94 /* linked list of collector thread control information */
95 typedef struct collector {
96 pthread_t thread;
98 /* socket to read data from */
99 int socket;
101 /* buffer to read data to */
102 char buffer[BUFSIZE];
103 int idx; /* current position in buffer */
105 struct collector *next;
106 } collector_t;
108 typedef struct {
109 collector_t *head;
110 collector_t *tail;
111 } collector_list_t;
112 #endif /* EMAIL_HAVE_READ */
114 /*
115 * Private variables
116 */
117 #if EMAIL_HAVE_READ
118 /* valid configuration file keys */
119 static char *config_keys[] =
120 {
121 "SocketGroup",
122 "SocketPerms",
123 "MaxConns",
124 NULL
125 };
126 static int config_keys_num = 3;
128 /* socket configuration */
129 static char *sock_group = COLLECTD_GRP_NAME;
130 static int sock_perms = S_IRWXU | S_IRWXG;
131 static int max_conns = MAX_CONNS;
133 /* state of the plugin */
134 static int disabled = 0;
136 /* thread managing "client" connections */
137 static pthread_t connector;
138 static int connector_socket;
140 /* tell the connector thread that a collector is available */
141 static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
143 /* collector threads that are in use */
144 static pthread_mutex_t active_mutex = PTHREAD_MUTEX_INITIALIZER;
145 static collector_list_t active;
147 /* collector threads that are available for use */
148 static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER;
149 static collector_list_t available;
151 static pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
152 static type_list_t count;
154 static pthread_mutex_t size_mutex = PTHREAD_MUTEX_INITIALIZER;
155 static type_list_t size;
157 static pthread_mutex_t score_mutex = PTHREAD_MUTEX_INITIALIZER;
158 static double score;
159 static int score_count;
161 static pthread_mutex_t check_mutex = PTHREAD_MUTEX_INITIALIZER;
162 static type_list_t check;
163 #endif /* EMAIL_HAVE_READ */
165 #define COUNT_FILE "email/email-%s.rrd"
166 static char *count_ds_def[] =
167 {
168 "DS:count:GAUGE:"COLLECTD_HEARTBEAT":0:U",
169 NULL
170 };
171 static int count_ds_num = 1;
173 #define SIZE_FILE "email/email_size-%s.rrd"
174 static char *size_ds_def[] =
175 {
176 "DS:size:GAUGE:"COLLECTD_HEARTBEAT":0:U",
177 NULL
178 };
179 static int size_ds_num = 1;
181 #define SCORE_FILE "email/spam_score.rrd"
182 static char *score_ds_def[] =
183 {
184 "DS:score:GAUGE:"COLLECTD_HEARTBEAT":U:U",
185 NULL
186 };
187 static int score_ds_num = 1;
189 #define CHECK_FILE "email/spam_check-%s.rrd"
190 static char *check_ds_def[] =
191 {
192 "DS:hits:GAUGE:"COLLECTD_HEARTBEAT":0:U",
193 NULL
194 };
195 static int check_ds_num = 1;
197 #if EMAIL_HAVE_READ
198 static int email_config (char *key, char *value)
199 {
200 if (0 == strcasecmp (key, "SocketGroup")) {
201 sock_group = sstrdup (value);
202 }
203 else if (0 == strcasecmp (key, "SocketPerms")) {
204 /* the user is responsible for providing reasonable values */
205 sock_perms = (int)strtol (value, NULL, 0);
206 }
207 else if (0 == strcasecmp (key, "MaxConns")) {
208 long int tmp = strtol (value, NULL, 0);
210 if (tmp < 1) {
211 fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
212 "value %li, will use default %i.\n",
213 tmp, MAX_CONNS);
214 max_conns = MAX_CONNS;
215 }
216 else if (tmp > MAX_CONNS_LIMIT) {
217 fprintf (stderr, "email plugin: `MaxConns' was set to invalid "
218 "value %li, will use hardcoded limit %i.\n",
219 tmp, MAX_CONNS_LIMIT);
220 max_conns = MAX_CONNS_LIMIT;
221 }
222 else {
223 max_conns = (int)tmp;
224 }
225 }
226 else {
227 return -1;
228 }
229 return 0;
230 } /* static int email_config (char *, char *) */
232 /* Increment the value of the given name in the given list by incr. */
233 static void type_list_incr (type_list_t *list, char *name, int incr)
234 {
235 if (NULL == list->head) {
236 list->head = (type_t *)smalloc (sizeof (type_t));
238 list->head->name = sstrdup (name);
239 list->head->value = incr;
240 list->head->next = NULL;
242 list->tail = list->head;
243 }
244 else {
245 type_t *ptr;
247 for (ptr = list->head; NULL != ptr; ptr = ptr->next) {
248 if (0 == strcmp (name, ptr->name))
249 break;
250 }
252 if (NULL == ptr) {
253 list->tail->next = (type_t *)smalloc (sizeof (type_t));
254 list->tail = list->tail->next;
256 list->tail->name = sstrdup (name);
257 list->tail->value = incr;
258 list->tail->next = NULL;
259 }
260 else {
261 ptr->value += incr;
262 }
263 }
264 return;
265 } /* static void type_list_incr (type_list_t *, char *) */
267 /* Read a single character from the socket. If an error occurs or end-of-file
268 * is reached return '\0'. */
269 char read_char (collector_t *src)
270 {
271 char ret = '\0';
273 fd_set fdset;
275 FD_ZERO (&fdset);
276 FD_SET (src->socket, &fdset);
278 if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
279 syslog (LOG_ERR, "select() failed: %s", strerror (errno));
280 return '\0';
281 }
283 assert (FD_ISSET (src->socket, &fdset));
285 do {
286 ssize_t len = 0;
288 errno = 0;
289 if (0 > (len = read (src->socket, (void *)&ret, 1))) {
290 if (EINTR != errno) {
291 syslog (LOG_ERR, "read() failed: %s", strerror (errno));
292 return '\0';
293 }
294 }
296 if (0 == len)
297 return '\0';
298 } while (EINTR == errno);
299 return ret;
300 } /* char read_char (collector_t *) */
302 /* Read a single line (terminated by '\n') from the the socket.
303 *
304 * The return value is zero terminated and does not contain any newline
305 * characters. In case that no complete line is available (non-blocking mode
306 * should be enabled) an empty string is returned.
307 *
308 * If an error occurs or end-of-file is reached return NULL.
309 *
310 * IMPORTANT NOTE: If there is no newline character found in BUFSIZE
311 * characters of the input stream, the line will will be ignored! By
312 * definition we should not get any longer input lines, thus this is
313 * acceptable in this case ;-) */
314 char *read_line (collector_t *src)
315 {
316 int i = 0;
317 char *ret;
319 assert (BUFSIZE > src->idx);
321 for (i = 0; i < src->idx; ++i) {
322 if ('\n' == src->buffer[i])
323 break;
324 }
326 if ('\n' != src->buffer[i]) {
327 fd_set fdset;
329 ssize_t len = 0;
331 FD_ZERO (&fdset);
332 FD_SET (src->socket, &fdset);
334 if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
335 syslog (LOG_ERR, "select() failed: %s", strerror (errno));
336 return NULL;
337 }
339 assert (FD_ISSET (src->socket, &fdset));
341 do {
342 errno = 0;
343 if (0 > (len = read (src->socket,
344 (void *)(&(src->buffer[0]) + src->idx),
345 BUFSIZE - src->idx))) {
346 if (EINTR != errno) {
347 syslog (LOG_ERR, "read() failed: %s", strerror (errno));
348 return NULL;
349 }
350 }
352 if (0 == len)
353 return NULL;
354 } while (EINTR == errno);
356 src->idx += len;
358 for (i = src->idx - len; i < src->idx; ++i) {
359 if ('\n' == src->buffer[i])
360 break;
361 }
363 if ('\n' != src->buffer[i]) {
364 ret = (char *)smalloc (1);
366 ret[0] = '\0';
368 if (BUFSIZE == src->idx) { /* no space left in buffer */
369 while ('\n' != read_char (src))
370 /* ignore complete line */;
372 src->idx = 0;
373 }
374 return ret;
375 }
376 }
378 ret = (char *)smalloc (i + 1);
379 memcpy (ret, &(src->buffer[0]), i + 1);
380 ret[i] = '\0';
382 src->idx -= (i + 1);
384 if (0 == src->idx)
385 src->buffer[0] = '\0';
386 else
387 memmove (&(src->buffer[0]), &(src->buffer[i + 1]), src->idx);
388 return ret;
389 } /* char *read_line (collector_t *) */
391 static void *collect (void *arg)
392 {
393 collector_t *this = (collector_t *)arg;
395 int loop = 1;
397 { /* put the socket in non-blocking mode */
398 int flags = 0;
400 errno = 0;
401 if (-1 == fcntl (this->socket, F_GETFL, &flags)) {
402 syslog (LOG_ERR, "fcntl() failed: %s", strerror (errno));
403 loop = 0;
404 }
406 errno = 0;
407 if (-1 == fcntl (this->socket, F_SETFL, flags | O_NONBLOCK)) {
408 syslog (LOG_ERR, "fcntl() failed: %s", strerror (errno));
409 loop = 0;
410 }
411 }
413 while (loop) {
414 char *line = read_line (this);
416 if (NULL == line) {
417 loop = 0;
418 break;
419 }
421 if ('\0' == line[0]) {
422 free (line);
423 continue;
424 }
426 if (':' != line[1]) {
427 syslog (LOG_ERR, "email: syntax error in line '%s'", line);
428 free (line);
429 continue;
430 }
432 if ('e' == line[0]) { /* e:<type>:<bytes> */
433 char *ptr = NULL;
434 char *type = strtok_r (line + 2, ":", &ptr);
435 char *tmp = strtok_r (NULL, ":", &ptr);
436 int bytes = 0;
438 if (NULL == tmp) {
439 syslog (LOG_ERR, "email: syntax error in line '%s'", line);
440 free (line);
441 continue;
442 }
444 bytes = atoi (tmp);
446 pthread_mutex_lock (&count_mutex);
447 type_list_incr (&count, type, 1);
448 pthread_mutex_unlock (&count_mutex);
450 pthread_mutex_lock (&size_mutex);
451 type_list_incr (&size, type, bytes);
452 pthread_mutex_unlock (&size_mutex);
453 }
454 else if ('s' == line[0]) { /* s:<value> */
455 pthread_mutex_lock (&score_mutex);
456 score = (score * (double)score_count + atof (line + 2))
457 / (double)(score_count + 1);
458 ++score_count;
459 pthread_mutex_unlock (&score_mutex);
460 }
461 else if ('c' == line[0]) { /* c:<type1>[,<type2>,...] */
462 char *ptr = NULL;
463 char *type = strtok_r (line + 2, ",", &ptr);
465 do {
466 pthread_mutex_lock (&check_mutex);
467 type_list_incr (&check, type, 1);
468 pthread_mutex_unlock (&check_mutex);
469 } while (NULL != (type = strtok_r (NULL, ",", &ptr)));
470 }
471 else {
472 syslog (LOG_ERR, "email: unknown type '%c'", line[0]);
473 }
475 free (line);
476 }
478 /* put this thread back into the available list */
479 pthread_mutex_lock (&active_mutex);
480 {
481 collector_t *last;
482 collector_t *ptr;
484 last = NULL;
486 for (ptr = active.head; NULL != ptr; last = ptr, ptr = ptr->next) {
487 if (0 != pthread_equal (ptr->thread, this->thread))
488 break;
489 }
491 /* the current thread _has_ to be in the active list */
492 assert (NULL != ptr);
494 if (NULL == last) {
495 active.head = ptr->next;
496 }
497 else {
498 last->next = ptr->next;
500 if (NULL == last->next) {
501 active.tail = last;
502 }
503 }
504 }
505 pthread_mutex_unlock (&active_mutex);
507 this->next = NULL;
509 pthread_mutex_lock (&available_mutex);
511 if (NULL == available.head) {
512 available.head = this;
513 available.tail = this;
514 }
515 else {
516 available.tail->next = this;
517 available.tail = this;
518 }
520 pthread_mutex_unlock (&available_mutex);
522 pthread_cond_signal (&collector_available);
523 pthread_exit ((void *)0);
524 } /* void *collect (void *) */
526 static void *open_connection (void *arg)
527 {
528 struct sockaddr_un addr;
530 /* create UNIX socket */
531 errno = 0;
532 if (-1 == (connector_socket = socket (PF_UNIX, SOCK_STREAM, 0))) {
533 disabled = 1;
534 syslog (LOG_ERR, "socket() failed: %s", strerror (errno));
535 pthread_exit ((void *)1);
536 }
538 addr.sun_family = AF_UNIX;
540 strncpy (addr.sun_path, SOCK_PATH, (size_t)(UNIX_PATH_MAX - 1));
541 addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
542 unlink (addr.sun_path);
544 errno = 0;
545 if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
546 offsetof (struct sockaddr_un, sun_path)
547 + strlen(addr.sun_path))) {
548 disabled = 1;
549 syslog (LOG_ERR, "bind() failed: %s", strerror (errno));
550 pthread_exit ((void *)1);
551 }
553 errno = 0;
554 if (-1 == listen (connector_socket, 5)) {
555 disabled = 1;
556 syslog (LOG_ERR, "listen() failed: %s", strerror (errno));
557 pthread_exit ((void *)1);
558 }
560 if ((uid_t)0 == geteuid ()) {
561 struct group *grp;
563 errno = 0;
564 if (NULL != (grp = getgrnam (sock_group))) {
565 errno = 0;
566 if (0 != chown (SOCK_PATH, (uid_t)-1, grp->gr_gid)) {
567 syslog (LOG_WARNING, "chown() failed: %s", strerror (errno));
568 }
569 }
570 else {
571 syslog (LOG_WARNING, "getgrnam() failed: %s", strerror (errno));
572 }
573 }
574 else {
575 syslog (LOG_WARNING, "not running as root");
576 }
578 errno = 0;
579 if (0 != chmod (SOCK_PATH, sock_perms)) {
580 syslog (LOG_WARNING, "chmod() failed: %s", strerror (errno));
581 }
583 { /* initialize queue of available threads */
584 int i = 0;
586 collector_t *last;
588 active.head = NULL;
589 active.tail = NULL;
591 available.head = (collector_t *)smalloc (sizeof (collector_t));
592 available.tail = available.head;
593 available.tail->next = NULL;
595 last = available.head;
597 for (i = 1; i < max_conns; ++i) {
598 last->next = (collector_t *)smalloc (sizeof (collector_t));
599 last = last->next;
600 available.tail = last;
601 available.tail->next = NULL;
602 }
603 }
605 while (1) {
606 int remote = 0;
607 int err = 0;
609 collector_t *collector;
611 pthread_attr_t ptattr;
613 pthread_mutex_lock (&available_mutex);
614 while (NULL == available.head) {
615 pthread_cond_wait (&collector_available, &available_mutex);
616 }
617 pthread_mutex_unlock (&available_mutex);
619 do {
620 errno = 0;
621 if (-1 == (remote = accept (connector_socket, NULL, NULL))) {
622 if (EINTR != errno) {
623 disabled = 1;
624 syslog (LOG_ERR, "accept() failed: %s", strerror (errno));
625 pthread_exit ((void *)1);
626 }
627 }
628 } while (EINTR == errno);
630 /* assign connection to next available thread */
631 pthread_mutex_lock (&available_mutex);
633 collector = available.head;
634 collector->socket = remote;
636 if (available.head == available.tail) {
637 available.head = NULL;
638 available.tail = NULL;
639 }
640 else {
641 available.head = available.head->next;
642 }
644 pthread_mutex_unlock (&available_mutex);
646 collector->idx = 0;
647 collector->next = NULL;
649 pthread_attr_init (&ptattr);
650 pthread_attr_setdetachstate (&ptattr, PTHREAD_CREATE_DETACHED);
652 if (0 == (err = pthread_create (&collector->thread, &ptattr, collect,
653 (void *)collector))) {
654 pthread_mutex_lock (&active_mutex);
656 if (NULL == active.head) {
657 active.head = collector;
658 active.tail = collector;
659 }
660 else {
661 active.tail->next = collector;
662 active.tail = collector;
663 }
665 pthread_mutex_unlock (&active_mutex);
666 }
667 else {
668 pthread_mutex_lock (&available_mutex);
670 if (NULL == available.head) {
671 available.head = collector;
672 available.tail = collector;
673 }
674 else {
675 available.tail->next = collector;
676 available.tail = collector;
677 }
679 pthread_mutex_unlock (&available_mutex);
681 close (remote);
682 syslog (LOG_ERR, "pthread_create() failed: %s", strerror (err));
683 }
685 pthread_attr_destroy (&ptattr);
686 }
687 pthread_exit ((void *)0);
688 } /* void *open_connection (void *) */
689 #endif /* EMAIL_HAVE_READ */
691 static void email_init (void)
692 {
693 #if EMAIL_HAVE_READ
694 int err = 0;
696 if (0 != (err = pthread_create (&connector, NULL,
697 open_connection, NULL))) {
698 disabled = 1;
699 syslog (LOG_ERR, "pthread_create() failed: %s", strerror (err));
700 return;
701 }
702 #endif /* EMAIL_HAVE_READ */
703 return;
704 } /* static void email_init (void) */
706 #if EMAIL_HAVE_READ
707 static void email_shutdown (void)
708 {
709 collector_t *ptr;
711 if (disabled)
712 return;
714 close (connector_socket);
715 pthread_kill (connector, SIGTERM);
717 pthread_mutex_lock (&active_mutex);
719 for (ptr = active.head; NULL != ptr; ptr = ptr->next) {
720 close (ptr->socket);
721 pthread_kill (ptr->thread, SIGTERM);
722 }
724 pthread_mutex_unlock (&active_mutex);
726 unlink (SOCK_PATH);
727 return;
728 } /* static void email_shutdown (void) */
729 #endif /* EMAIL_HAVE_READ */
731 static void count_write (char *host, char *inst, char *val)
732 {
733 char file[BUFSIZE] = "";
734 int len = 0;
736 len = snprintf (file, BUFSIZE, COUNT_FILE, inst);
737 if ((len < 0) || (len >= BUFSIZE))
738 return;
740 rrd_update_file (host, file, val, count_ds_def, count_ds_num);
741 return;
742 } /* static void email_write (char *host, char *inst, char *val) */
744 static void size_write (char *host, char *inst, char *val)
745 {
746 char file[BUFSIZE] = "";
747 int len = 0;
749 len = snprintf (file, BUFSIZE, SIZE_FILE, inst);
750 if ((len < 0) || (len >= BUFSIZE))
751 return;
753 rrd_update_file (host, file, val, size_ds_def, size_ds_num);
754 return;
755 } /* static void size_write (char *host, char *inst, char *val) */
757 static void score_write (char *host, char *inst, char *val)
758 {
759 rrd_update_file (host, SCORE_FILE, val, score_ds_def, score_ds_num);
760 return;
761 } /* static void score_write (char *host, char *inst, char *val) */
763 static void check_write (char *host, char *inst, char *val)
764 {
765 char file[BUFSIZE] = "";
766 int len = 0;
768 len = snprintf (file, BUFSIZE, CHECK_FILE, inst);
769 if ((len < 0) || (len >= BUFSIZE))
770 return;
772 rrd_update_file (host, file, val, check_ds_def, check_ds_num);
773 return;
774 } /* static void check_write (char *host, char *inst, char *val) */
776 #if EMAIL_HAVE_READ
777 static void type_submit (char *plugin, char *inst, int value)
778 {
779 char buf[BUFSIZE] = "";
780 int len = 0;
782 if (0 == value)
783 return;
785 len = snprintf (buf, BUFSIZE, "%u:%i", (unsigned int)curtime, value);
786 if ((len < 0) || (len >= BUFSIZE))
787 return;
789 plugin_submit (plugin, inst, buf);
790 return;
791 } /* static void type_submit (char *, char *, int) */
793 static void score_submit (double value)
794 {
795 char buf[BUFSIZE] = "";
796 int len = 0;
798 if (0.0 == value)
799 return;
801 len = snprintf (buf, BUFSIZE, "%u:%.2f", (unsigned int)curtime, value);
802 if ((len < 0) || (len >= BUFSIZE))
803 return;
805 plugin_submit ("email_spam_score", NULL, buf);
806 return;
807 }
809 static void email_read (void)
810 {
811 type_t *ptr;
813 if (disabled)
814 return;
816 pthread_mutex_lock (&count_mutex);
818 for (ptr = count.head; NULL != ptr; ptr = ptr->next) {
819 type_submit ("email_count", ptr->name, ptr->value);
820 ptr->value = 0;
821 }
823 pthread_mutex_unlock (&count_mutex);
825 pthread_mutex_lock (&size_mutex);
827 for (ptr = size.head; NULL != ptr; ptr = ptr->next) {
828 type_submit ("email_size", ptr->name, ptr->value);
829 ptr->value = 0;
830 }
832 pthread_mutex_unlock (&size_mutex);
834 pthread_mutex_lock (&score_mutex);
836 score_submit (score);
837 score = 0.0;
838 score_count = 0;
840 pthread_mutex_unlock (&score_mutex);
842 pthread_mutex_lock (&check_mutex);
844 for (ptr = check.head; NULL != ptr; ptr = ptr->next) {
845 type_submit ("email_spam_check", ptr->name, ptr->value);
846 ptr->value = 0;
847 }
849 pthread_mutex_unlock (&check_mutex);
850 return;
851 } /* static void read (void) */
852 #else /* if !EMAIL_HAVE_READ */
853 # define email_read NULL
854 #endif
856 void module_register (void)
857 {
858 plugin_register (MODULE_NAME, email_init, email_read, NULL);
859 plugin_register ("email_count", NULL, NULL, count_write);
860 plugin_register ("email_size", NULL, NULL, size_write);
861 plugin_register ("email_spam_score", NULL, NULL, score_write);
862 plugin_register ("email_spam_check", NULL, NULL, check_write);
863 #if EMAIL_HAVE_READ
864 plugin_register_shutdown (MODULE_NAME, email_shutdown);
865 cf_register (MODULE_NAME, email_config, config_keys, config_keys_num);
866 #endif /* EMAIL_HAVE_READ */
867 return;
868 } /* void module_register (void) */
870 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */