From: Florian Forster Date: Fri, 30 Mar 2007 19:45:38 +0000 (+0200) Subject: exec plugin: Send SIGTERM to all running child-processes when exiting. X-Git-Tag: collectd-4.0.0~119 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c61f8f8b9758ca326074467bc711dd1b6e167c41;p=collectd.git exec plugin: Send SIGTERM to all running child-processes when exiting. --- diff --git a/src/exec.c b/src/exec.c index 82c7efa6..5bddfc59 100644 --- a/src/exec.c +++ b/src/exec.c @@ -25,6 +25,7 @@ #include #include +#include #include @@ -334,6 +335,7 @@ static void *exec_read_one (void *arg) pl->pid = 0; pthread_exit ((void *) 0); + return (NULL); } /* void *exec_read_one */ static int exec_read (void) @@ -356,6 +358,32 @@ static int exec_read (void) return (0); } /* int exec_read */ +static int exec_shutdown (void) +{ + program_list_t *pl; + program_list_t *next; + + pl = pl_head; + while (pl != NULL) + { + next = pl->next; + + if (pl->pid > 0) + { + kill (pl->pid, SIGTERM); + INFO ("exec plugin: Sent SIGTERM to %hu", (unsigned short int) pl->pid); + } + + sfree (pl->user); + sfree (pl); + + pl = next; + } /* while (pl) */ + pl_head = NULL; + + return (0); +} /* int exec_shutdown */ + void module_register (modreg_e load) { if (load & MR_DATASETS) @@ -368,6 +396,7 @@ void module_register (modreg_e load) { plugin_register_config ("exec", exec_config, config_keys, config_keys_num); plugin_register_read ("exec", exec_read); + plugin_register_shutdown ("exec", exec_shutdown); } } /* void module_register */