From c92f67c2cee4deb11f96b79ff10a6f7a5ba49f15 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 18 Mar 2010 14:43:10 +0100 Subject: [PATCH] Metaproxy program kills all children on SIGTERM Metaproxy now kills all child processes that are spawned by modules (in case of fork, exec). --- src/metaproxy_prog.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 11b04b2..c1f6123 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -46,22 +46,30 @@ namespace mp = metaproxy_1; mp::RouterFleXML *routerp = 0; +#if HAVE_UNISTD_H +static pid_t process_group = 0; + static void sig_term_handler(int s) { - if (routerp) - { - delete routerp; - } + kill(-process_group, SIGTERM); /* kill all children processes as well */ exit(0); } +#endif static void handler(void *data) { routerp = (mp::RouterFleXML*) data; + +#if HAVE_UNISTD_H + /* make the current working process group leader */ + setpgid(0, 0); + process_group = getpgid(0); // save process group ID signal(SIGTERM, sig_term_handler); +#endif + mp::Package pack; - pack.router(*routerp).move(); + pack.router(*routerp).move(); /* should never exit */ } static int sc_main( -- 1.7.10.4