diff options
author | Jeremy Allison <jra@samba.org> | 2017-04-07 15:45:41 -0700 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2017-04-08 16:21:57 +0200 |
commit | 6d6117b5ba510d169cbc0c285edc75c24f60625a (patch) | |
tree | 4408941cac7bf79a70ef63ac90853e1f548a9328 /source4/smbd | |
parent | d354be9e078730505462623225295e675d73fd86 (diff) | |
download | samba-6d6117b5ba510d169cbc0c285edc75c24f60625a.tar.gz |
s4: process_standard: Add a simplified SIGTERM handler based on code from source4/smbd/server.c. Use from a tevent handler added to standard_accept_connection() and standard_new_task()
Allows us to be independent of parent SIGTERM signal handling.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Sat Apr 8 16:21:57 CEST 2017 on sn-devel-144
Diffstat (limited to 'source4/smbd')
-rw-r--r-- | source4/smbd/process_standard.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index 776e497e987..92f07add42c 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -67,6 +67,26 @@ static void sighup_signal_handler(struct tevent_context *ev, debug_schedule_reopen_logs(); } +static void sigterm_signal_handler(struct tevent_context *ev, + struct tevent_signal *se, + int signum, int count, void *siginfo, + void *private_data) +{ +#if HAVE_GETPGRP + if (getpgrp() == getpid()) { + /* + * We're the process group leader, send + * SIGTERM to our process group. + */ + DEBUG(0,("SIGTERM: killing children\n")); + kill(-getpgrp(), SIGTERM); + } +#endif + DEBUG(0,("Exiting pid %u on SIGTERM\n", (unsigned int)getpid())); + talloc_free(ev); + exit(127); +} + /* handle EOF on the parent-to-all-children pipe in the child */ @@ -310,6 +330,16 @@ static void standard_accept_connection(struct tevent_context *ev, smb_panic("Failed to add SIGHUP handler after fork"); } + se = tevent_add_signal(ev, + ev, + SIGTERM, + 0, + sigterm_signal_handler, + NULL); + if (se == NULL) { + smb_panic("Failed to add SIGTERM handler after fork"); + } + /* setup the process title */ c = socket_get_peer_addr(sock2, ev); s = socket_get_my_addr(sock2, ev); @@ -408,6 +438,16 @@ static void standard_new_task(struct tevent_context *ev, smb_panic("Failed to add SIGHUP handler after fork"); } + se = tevent_add_signal(ev, + ev, + SIGTERM, + 0, + sigterm_signal_handler, + NULL); + if (se == NULL) { + smb_panic("Failed to add SIGTERM handler after fork"); + } + setproctitle("task %s server_id[%d]", service_name, (int)pid); /* setup this new task. Cluster ID is PID based for this process model */ |