1 /**
2 * collectd - src/exec.c
3 * Copyright (C) 2007,2008 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 * Authors:
19 * Florian octo Forster <octo at verplant.org>
20 **/
22 #include "collectd.h"
23 #include "common.h"
24 #include "plugin.h"
26 #include "utils_cmd_putval.h"
27 #include "utils_cmd_putnotif.h"
29 #include <sys/types.h>
30 #include <pwd.h>
31 #include <grp.h>
32 #include <signal.h>
34 #include <pthread.h>
36 #define PL_NORMAL 0x01
37 #define PL_NOTIF_ACTION 0x02
39 #define PL_RUNNING 0x10
41 /*
42 * Private data types
43 */
44 /*
45 * Access to this structure is serialized using the `pl_lock' lock and the
46 * `PL_RUNNING' flag. The execution of notifications is *not* serialized, so
47 * all functions used to handle notifications MUST NOT write to this structure.
48 * The `pid' and `status' fields are thus unused if the `PL_NOTIF_ACTION' flag
49 * is set.
50 * The `PL_RUNNING' flag is set in `exec_read' and unset in `exec_read_one'.
51 */
52 struct program_list_s;
53 typedef struct program_list_s program_list_t;
54 struct program_list_s
55 {
56 char *user;
57 char *group;
58 char *exec;
59 char **argv;
60 int pid;
61 int status;
62 int flags;
63 program_list_t *next;
64 };
66 typedef struct program_list_and_notification_s
67 {
68 program_list_t *pl;
69 notification_t n;
70 } program_list_and_notification_t;
72 /*
73 * Private variables
74 */
75 static program_list_t *pl_head = NULL;
76 static pthread_mutex_t pl_lock = PTHREAD_MUTEX_INITIALIZER;
78 /*
79 * Functions
80 */
81 static void sigchld_handler (int __attribute__((unused)) signal) /* {{{ */
82 {
83 pid_t pid;
84 int status;
85 while ((pid = waitpid (-1, &status, WNOHANG)) > 0)
86 {
87 program_list_t *pl;
88 for (pl = pl_head; pl != NULL; pl = pl->next)
89 if (pl->pid == pid)
90 break;
91 if (pl != NULL)
92 pl->status = status;
93 } /* while (waitpid) */
94 } /* void sigchld_handler }}} */
96 static int exec_config_exec (oconfig_item_t *ci) /* {{{ */
97 {
98 program_list_t *pl;
99 char buffer[128];
100 int i;
102 if (ci->children_num != 0)
103 {
104 WARNING ("exec plugin: The config option `%s' may not be a block.",
105 ci->key);
106 return (-1);
107 }
108 if (ci->values_num < 2)
109 {
110 WARNING ("exec plugin: The config option `%s' needs at least two "
111 "arguments.", ci->key);
112 return (-1);
113 }
114 if ((ci->values[0].type != OCONFIG_TYPE_STRING)
115 || (ci->values[1].type != OCONFIG_TYPE_STRING))
116 {
117 WARNING ("exec plugin: The first two arguments to the `%s' option must "
118 "be string arguments.", ci->key);
119 return (-1);
120 }
122 pl = (program_list_t *) malloc (sizeof (program_list_t));
123 if (pl == NULL)
124 {
125 ERROR ("exec plugin: malloc failed.");
126 return (-1);
127 }
128 memset (pl, '\0', sizeof (program_list_t));
130 if (strcasecmp ("NotificationExec", ci->key) == 0)
131 pl->flags |= PL_NOTIF_ACTION;
132 else
133 pl->flags |= PL_NORMAL;
135 pl->user = strdup (ci->values[0].value.string);
136 if (pl->user == NULL)
137 {
138 ERROR ("exec plugin: strdup failed.");
139 sfree (pl);
140 return (-1);
141 }
143 pl->group = strchr (pl->user, ':');
144 if (pl->group != NULL)
145 {
146 *pl->group = '\0';
147 pl->group++;
148 }
150 pl->exec = strdup (ci->values[1].value.string);
151 if (pl->exec == NULL)
152 {
153 ERROR ("exec plugin: strdup failed.");
154 sfree (pl->user);
155 sfree (pl);
156 return (-1);
157 }
159 pl->argv = (char **) malloc (ci->values_num * sizeof (char *));
160 if (pl->argv == NULL)
161 {
162 ERROR ("exec plugin: malloc failed.");
163 sfree (pl->exec);
164 sfree (pl->user);
165 sfree (pl);
166 return (-1);
167 }
168 memset (pl->argv, '\0', ci->values_num * sizeof (char *));
170 {
171 char *tmp = strrchr (ci->values[1].value.string, '/');
172 if (tmp == NULL)
173 sstrncpy (buffer, ci->values[1].value.string, sizeof (buffer));
174 else
175 sstrncpy (buffer, tmp + 1, sizeof (buffer));
176 }
177 pl->argv[0] = strdup (buffer);
178 if (pl->argv[0] == NULL)
179 {
180 ERROR ("exec plugin: malloc failed.");
181 sfree (pl->argv);
182 sfree (pl->exec);
183 sfree (pl->user);
184 sfree (pl);
185 return (-1);
186 }
188 for (i = 1; i < (ci->values_num - 1); i++)
189 {
190 if (ci->values[i + 1].type == OCONFIG_TYPE_STRING)
191 {
192 pl->argv[i] = strdup (ci->values[i + 1].value.string);
193 }
194 else
195 {
196 if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER)
197 {
198 ssnprintf (buffer, sizeof (buffer), "%lf",
199 ci->values[i + 1].value.number);
200 }
201 else
202 {
203 if (ci->values[i + 1].value.boolean)
204 sstrncpy (buffer, "true", sizeof (buffer));
205 else
206 sstrncpy (buffer, "false", sizeof (buffer));
207 }
209 pl->argv[i] = strdup (buffer);
210 }
212 if (pl->argv[i] == NULL)
213 {
214 ERROR ("exec plugin: strdup failed.");
215 break;
216 }
217 } /* for (i) */
219 if (i < (ci->values_num - 1))
220 {
221 while ((--i) >= 0)
222 {
223 sfree (pl->argv[i]);
224 }
225 sfree (pl->argv);
226 sfree (pl->exec);
227 sfree (pl->user);
228 sfree (pl);
229 return (-1);
230 }
232 for (i = 0; pl->argv[i] != NULL; i++)
233 {
234 DEBUG ("exec plugin: argv[%i] = %s", i, pl->argv[i]);
235 }
237 pl->next = pl_head;
238 pl_head = pl;
240 return (0);
241 } /* int exec_config_exec }}} */
243 static int exec_config (oconfig_item_t *ci) /* {{{ */
244 {
245 int i;
247 for (i = 0; i < ci->children_num; i++)
248 {
249 oconfig_item_t *child = ci->children + i;
250 if ((strcasecmp ("Exec", child->key) == 0)
251 || (strcasecmp ("NotificationExec", child->key) == 0))
252 exec_config_exec (child);
253 else
254 {
255 WARNING ("exec plugin: Unknown config option `%s'.", child->key);
256 }
257 } /* for (i) */
259 return (0);
260 } /* int exec_config }}} */
262 static void exec_child (program_list_t *pl) /* {{{ */
263 {
264 int status;
265 int uid;
266 int gid;
267 int egid;
269 struct passwd *sp_ptr;
270 struct passwd sp;
271 char nambuf[2048];
272 char errbuf[1024];
274 sp_ptr = NULL;
275 status = getpwnam_r (pl->user, &sp, nambuf, sizeof (nambuf), &sp_ptr);
276 if (status != 0)
277 {
278 ERROR ("exec plugin: getpwnam_r failed: %s",
279 sstrerror (errno, errbuf, sizeof (errbuf)));
280 exit (-1);
281 }
282 if (sp_ptr == NULL)
283 {
284 ERROR ("exec plugin: No such user: `%s'", pl->user);
285 exit (-1);
286 }
288 uid = sp.pw_uid;
289 gid = sp.pw_gid;
290 if (uid == 0)
291 {
292 ERROR ("exec plugin: Cowardly refusing to exec program as root.");
293 exit (-1);
294 }
296 /* The group configured in the configfile is set as effective group, because
297 * this way the forked process can (re-)gain the user's primary group. */
298 egid = -1;
299 if (NULL != pl->group)
300 {
301 if ('\0' != *pl->group) {
302 struct group *gr_ptr = NULL;
303 struct group gr;
305 status = getgrnam_r (pl->group, &gr, nambuf, sizeof (nambuf), &gr_ptr);
306 if (0 != status)
307 {
308 ERROR ("exec plugin: getgrnam_r failed: %s",
309 sstrerror (errno, errbuf, sizeof (errbuf)));
310 exit (-1);
311 }
312 if (NULL == gr_ptr)
313 {
314 ERROR ("exec plugin: No such group: `%s'", pl->group);
315 exit (-1);
316 }
318 egid = gr.gr_gid;
319 }
320 else
321 {
322 egid = gid;
323 }
324 } /* if (pl->group == NULL) */
326 #if HAVE_SETGROUPS
327 if (getuid () == 0)
328 {
329 gid_t glist[2];
330 size_t glist_len;
332 glist[0] = gid;
333 glist_len = 1;
335 if ((gid != egid) && (egid != -1))
336 {
337 glist[1] = egid;
338 glist_len = 2;
339 }
341 setgroups (glist_len, glist);
342 }
343 #endif /* HAVE_SETGROUPS */
345 status = setgid (gid);
346 if (status != 0)
347 {
348 ERROR ("exec plugin: setgid (%i) failed: %s",
349 gid, sstrerror (errno, errbuf, sizeof (errbuf)));
350 exit (-1);
351 }
353 if (egid != -1)
354 {
355 status = setegid (egid);
356 if (status != 0)
357 {
358 ERROR ("exec plugin: setegid (%i) failed: %s",
359 egid, sstrerror (errno, errbuf, sizeof (errbuf)));
360 exit (-1);
361 }
362 }
364 status = setuid (uid);
365 if (status != 0)
366 {
367 ERROR ("exec plugin: setuid (%i) failed: %s",
368 uid, sstrerror (errno, errbuf, sizeof (errbuf)));
369 exit (-1);
370 }
372 status = execvp (pl->exec, pl->argv);
374 ERROR ("exec plugin: exec failed: %s",
375 sstrerror (errno, errbuf, sizeof (errbuf)));
376 exit (-1);
377 } /* void exec_child }}} */
379 /*
380 * Creates three pipes (one for reading, one for writing and one for errors),
381 * forks a child, sets up the pipes so that fd_in is connected to STDIN of
382 * the child and fd_out is connected to STDOUT and fd_err is connected to STDERR
383 * of the child. Then is calls `exec_child'.
384 */
385 static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) /* {{{ */
386 {
387 int fd_pipe_in[2];
388 int fd_pipe_out[2];
389 int fd_pipe_err[2];
390 char errbuf[1024];
391 int status;
392 int pid;
394 if (pl->pid != 0)
395 return (-1);
397 status = pipe (fd_pipe_in);
398 if (status != 0)
399 {
400 ERROR ("exec plugin: pipe failed: %s",
401 sstrerror (errno, errbuf, sizeof (errbuf)));
402 return (-1);
403 }
405 status = pipe (fd_pipe_out);
406 if (status != 0)
407 {
408 ERROR ("exec plugin: pipe failed: %s",
409 sstrerror (errno, errbuf, sizeof (errbuf)));
410 return (-1);
411 }
413 status = pipe (fd_pipe_err);
414 if (status != 0)
415 {
416 ERROR ("exec plugin: pipe failed: %s",
417 sstrerror (errno, errbuf, sizeof (errbuf)));
418 return (-1);
419 }
421 pid = fork ();
422 if (pid < 0)
423 {
424 ERROR ("exec plugin: fork failed: %s",
425 sstrerror (errno, errbuf, sizeof (errbuf)));
426 return (-1);
427 }
428 else if (pid == 0)
429 {
430 int fd_num;
431 int fd;
433 /* Close all file descriptors but the pipe end we need. */
434 fd_num = getdtablesize ();
435 for (fd = 0; fd < fd_num; fd++)
436 {
437 if ((fd == fd_pipe_in[0])
438 || (fd == fd_pipe_out[1])
439 || (fd == fd_pipe_err[1]))
440 continue;
441 close (fd);
442 }
444 /* Connect the `in' pipe to STDIN */
445 if (fd_pipe_in[0] != STDIN_FILENO)
446 {
447 dup2 (fd_pipe_in[0], STDIN_FILENO);
448 close (fd_pipe_in[0]);
449 }
451 /* Now connect the `out' pipe to STDOUT */
452 if (fd_pipe_out[1] != STDOUT_FILENO)
453 {
454 dup2 (fd_pipe_out[1], STDOUT_FILENO);
455 close (fd_pipe_out[1]);
456 }
458 /* Now connect the `out' pipe to STDOUT */
459 if (fd_pipe_err[1] != STDERR_FILENO)
460 {
461 dup2 (fd_pipe_err[1], STDERR_FILENO);
462 close (fd_pipe_err[1]);
463 }
465 exec_child (pl);
466 /* does not return */
467 }
469 close (fd_pipe_in[0]);
470 close (fd_pipe_out[1]);
471 close (fd_pipe_err[1]);
473 if (fd_in != NULL)
474 *fd_in = fd_pipe_in[1];
475 else
476 close (fd_pipe_in[1]);
478 if (fd_out != NULL)
479 *fd_out = fd_pipe_out[0];
480 else
481 close (fd_pipe_out[0]);
483 if (fd_err != NULL)
484 *fd_err = fd_pipe_err[0];
485 else
486 close (fd_pipe_err[0]);
488 return (pid);
489 } /* int fork_child }}} */
491 static int parse_line (char *buffer) /* {{{ */
492 {
493 if (strncasecmp ("PUTVAL", buffer, strlen ("PUTVAL")) == 0)
494 return (handle_putval (stdout, buffer));
495 else if (strncasecmp ("PUTNOTIF", buffer, strlen ("PUTNOTIF")) == 0)
496 return (handle_putnotif (stdout, buffer));
497 else
498 {
499 /* For backwards compatibility */
500 char tmp[1220];
501 /* Let's annoy the user a bit.. */
502 INFO ("exec plugin: Prepending `PUTVAL' to this line: %s", buffer);
503 ssnprintf (tmp, sizeof (tmp), "PUTVAL %s", buffer);
504 return (handle_putval (stdout, tmp));
505 }
506 } /* int parse_line }}} */
508 static void *exec_read_one (void *arg) /* {{{ */
509 {
510 program_list_t *pl = (program_list_t *) arg;
511 int fd, fd_err, highest_fd;
512 fd_set fdset, copy;
513 int status;
514 char buffer[1200]; /* if not completely read */
515 char buffer_err[1024];
516 char *pbuffer = buffer;
517 char *pbuffer_err = buffer_err;
519 status = fork_child (pl, NULL, &fd, &fd_err);
520 if (status < 0)
521 pthread_exit ((void *) 1);
522 pl->pid = status;
524 assert (pl->pid != 0);
526 FD_ZERO( &fdset );
527 FD_SET(fd, &fdset);
528 FD_SET(fd_err, &fdset);
530 /* Determine the highest file descriptor */
531 highest_fd = (fd > fd_err) ? fd : fd_err;
533 /* We use a copy of fdset, as select modifies it */
534 copy = fdset;
536 while (select(highest_fd + 1, ©, NULL, NULL, NULL ) > 0)
537 {
538 int len;
540 if (FD_ISSET(fd, ©))
541 {
542 char *pnl;
544 len = read(fd, pbuffer, sizeof(buffer) - 1 - (pbuffer - buffer));
546 if (len < 0)
547 {
548 if (errno == EAGAIN || errno == EINTR) continue;
549 break;
550 }
551 else if (len == 0) break; /* We've reached EOF */
553 pbuffer[len] = '\0';
555 len += pbuffer - buffer;
556 pbuffer = buffer;
558 while ((pnl = strchr(pbuffer, '\n')))
559 {
560 *pnl = '\0';
561 if (*(pnl-1) == '\r' ) *(pnl-1) = '\0';
563 parse_line (pbuffer);
565 pbuffer = ++pnl;
566 }
567 /* not completely read ? */
568 if (pbuffer - buffer < len)
569 {
570 len -= pbuffer - buffer;
571 memmove(buffer, pbuffer, len);
572 pbuffer = buffer + len;
573 }
574 else
575 pbuffer = buffer;
576 }
577 else if (FD_ISSET(fd_err, ©))
578 {
579 char *pnl;
581 len = read(fd_err, pbuffer_err, sizeof(buffer_err) - 1 - (pbuffer_err - buffer_err));
583 if (len < 0)
584 {
585 if (errno == EAGAIN || errno == EINTR) continue;
586 break;
587 }
588 else if (len == 0) break; /* We've reached EOF */
590 pbuffer_err[len] = '\0';
592 len += pbuffer_err - buffer_err;
593 pbuffer_err = buffer_err;
595 while ((pnl = strchr(pbuffer_err, '\n')))
596 {
597 *pnl = '\0';
598 if (*(pnl-1) == '\r' ) *(pnl-1) = '\0';
600 ERROR ("exec plugin: exec_read_one: error = %s", pbuffer_err);
602 pbuffer_err = ++pnl;
603 }
604 /* not completely read ? */
605 if (pbuffer_err - buffer_err < len)
606 {
607 len -= pbuffer_err - buffer_err;
608 memmove(buffer_err, pbuffer_err, len);
609 pbuffer_err = buffer_err + len;
610 }
611 else
612 pbuffer_err = buffer_err;
613 }
614 /* reset copy */
615 copy = fdset;
616 }
618 if (waitpid (pl->pid, &status, 0) > 0)
619 pl->status = status;
621 DEBUG ("exec plugin: Child %i exited with status %i.",
622 (int) pl->pid, pl->status);
624 pl->pid = 0;
626 pthread_mutex_lock (&pl_lock);
627 pl->flags &= ~PL_RUNNING;
628 pthread_mutex_unlock (&pl_lock);
630 close (fd);
631 close (fd_err);
633 pthread_exit ((void *) 0);
634 return (NULL);
635 } /* void *exec_read_one }}} */
637 static void *exec_notification_one (void *arg) /* {{{ */
638 {
639 program_list_t *pl = ((program_list_and_notification_t *) arg)->pl;
640 notification_t *n = &((program_list_and_notification_t *) arg)->n;
641 notification_meta_t *meta;
642 int fd;
643 FILE *fh;
644 int pid;
645 int status;
646 const char *severity;
648 pid = fork_child (pl, &fd, NULL, NULL);
649 if (pid < 0) {
650 sfree (arg);
651 pthread_exit ((void *) 1);
652 }
654 fh = fdopen (fd, "w");
655 if (fh == NULL)
656 {
657 char errbuf[1024];
658 ERROR ("exec plugin: fdopen (%i) failed: %s", fd,
659 sstrerror (errno, errbuf, sizeof (errbuf)));
660 kill (pl->pid, SIGTERM);
661 pl->pid = 0;
662 close (fd);
663 sfree (arg);
664 pthread_exit ((void *) 1);
665 }
667 severity = "FAILURE";
668 if (n->severity == NOTIF_WARNING)
669 severity = "WARNING";
670 else if (n->severity == NOTIF_OKAY)
671 severity = "OKAY";
673 fprintf (fh,
674 "Severity: %s\n"
675 "Time: %u\n",
676 severity, (unsigned int) n->time);
678 /* Print the optional fields */
679 if (strlen (n->host) > 0)
680 fprintf (fh, "Host: %s\n", n->host);
681 if (strlen (n->plugin) > 0)
682 fprintf (fh, "Plugin: %s\n", n->plugin);
683 if (strlen (n->plugin_instance) > 0)
684 fprintf (fh, "PluginInstance: %s\n", n->plugin_instance);
685 if (strlen (n->type) > 0)
686 fprintf (fh, "Type: %s\n", n->type);
687 if (strlen (n->type_instance) > 0)
688 fprintf (fh, "TypeInstance: %s\n", n->type_instance);
690 for (meta = n->meta; meta != NULL; meta = meta->next)
691 {
692 if (meta->type == NM_TYPE_STRING)
693 fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string);
694 else if (meta->type == NM_TYPE_SIGNED_INT)
695 fprintf (fh, "%s: %"PRIi64"\n", meta->name, meta->nm_value.nm_signed_int);
696 else if (meta->type == NM_TYPE_UNSIGNED_INT)
697 fprintf (fh, "%s: %"PRIu64"\n", meta->name, meta->nm_value.nm_unsigned_int);
698 else if (meta->type == NM_TYPE_DOUBLE)
699 fprintf (fh, "%s: %e\n", meta->name, meta->nm_value.nm_double);
700 else if (meta->type == NM_TYPE_BOOLEAN)
701 fprintf (fh, "%s: %s\n", meta->name,
702 meta->nm_value.nm_boolean ? "true" : "false");
703 }
705 fprintf (fh, "\n%s\n", n->message);
707 fflush (fh);
708 fclose (fh);
710 waitpid (pid, &status, 0);
712 DEBUG ("exec plugin: Child %i exited with status %i.",
713 pid, status);
715 plugin_notification_meta_free (n->meta);
716 n->meta = NULL;
717 sfree (arg);
718 pthread_exit ((void *) 0);
719 return (NULL);
720 } /* void *exec_notification_one }}} */
722 static int exec_init (void) /* {{{ */
723 {
724 struct sigaction sa;
726 memset (&sa, '\0', sizeof (sa));
727 sa.sa_handler = sigchld_handler;
728 sigaction (SIGCHLD, &sa, NULL);
730 return (0);
731 } /* int exec_init }}} */
733 static int exec_read (void) /* {{{ */
734 {
735 program_list_t *pl;
737 for (pl = pl_head; pl != NULL; pl = pl->next)
738 {
739 pthread_t t;
740 pthread_attr_t attr;
742 /* Only execute `normal' style executables here. */
743 if ((pl->flags & PL_NORMAL) == 0)
744 continue;
746 pthread_mutex_lock (&pl_lock);
747 /* Skip if a child is already running. */
748 if ((pl->flags & PL_RUNNING) != 0)
749 {
750 pthread_mutex_unlock (&pl_lock);
751 continue;
752 }
753 pl->flags |= PL_RUNNING;
754 pthread_mutex_unlock (&pl_lock);
756 pthread_attr_init (&attr);
757 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
758 pthread_create (&t, &attr, exec_read_one, (void *) pl);
759 } /* for (pl) */
761 return (0);
762 } /* int exec_read }}} */
764 static int exec_notification (const notification_t *n)
765 {
766 program_list_t *pl;
767 program_list_and_notification_t *pln;
769 for (pl = pl_head; pl != NULL; pl = pl->next)
770 {
771 pthread_t t;
772 pthread_attr_t attr;
774 /* Only execute `notification' style executables here. */
775 if ((pl->flags & PL_NOTIF_ACTION) == 0)
776 continue;
778 /* Skip if a child is already running. */
779 if (pl->pid != 0)
780 continue;
782 pln = (program_list_and_notification_t *) malloc (sizeof
783 (program_list_and_notification_t));
784 if (pln == NULL)
785 {
786 ERROR ("exec plugin: malloc failed.");
787 continue;
788 }
790 pln->pl = pl;
791 memcpy (&pln->n, n, sizeof (notification_t));
793 /* Set the `meta' member to NULL, otherwise `plugin_notification_meta_copy'
794 * will run into an endless loop. */
795 pln->n.meta = NULL;
796 plugin_notification_meta_copy (&pln->n, n);
798 pthread_attr_init (&attr);
799 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
800 pthread_create (&t, &attr, exec_notification_one, (void *) pln);
801 } /* for (pl) */
803 return (0);
804 } /* int exec_notification */
806 static int exec_shutdown (void) /* {{{ */
807 {
808 program_list_t *pl;
809 program_list_t *next;
811 pl = pl_head;
812 while (pl != NULL)
813 {
814 next = pl->next;
816 if (pl->pid > 0)
817 {
818 kill (pl->pid, SIGTERM);
819 INFO ("exec plugin: Sent SIGTERM to %hu", (unsigned short int) pl->pid);
820 }
822 sfree (pl->user);
823 sfree (pl);
825 pl = next;
826 } /* while (pl) */
827 pl_head = NULL;
829 return (0);
830 } /* int exec_shutdown }}} */
832 void module_register (void)
833 {
834 plugin_register_complex_config ("exec", exec_config);
835 plugin_register_init ("exec", exec_init);
836 plugin_register_read ("exec", exec_read);
837 plugin_register_notification ("exec", exec_notification);
838 plugin_register_shutdown ("exec", exec_shutdown);
839 } /* void module_register */
841 /*
842 * vim:shiftwidth=2:softtabstop=2:tabstop=8:fdm=marker
843 */