diff options
author | Andrew Bartlett <abartlet@samba.org> | 2012-03-02 18:22:10 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-03-04 10:14:34 +0100 |
commit | 769cee44a2ed1b68cb757246efd72d63aa36a4d0 (patch) | |
tree | f3b5edddc515ddd653f9198991fdc8fd99491e9d | |
parent | 807f5f1a8b02176e03b00f4415c0cae1927b44a4 (diff) | |
download | samba-769cee44a2ed1b68cb757246efd72d63aa36a4d0.tar.gz samba-769cee44a2ed1b68cb757246efd72d63aa36a4d0.tar.bz2 samba-769cee44a2ed1b68cb757246efd72d63aa36a4d0.zip |
s3-winbindd: Add stdin handler for winbind
This will help avoid runaway processes in the test env, particularly when
the whole selftest.pl is killed.
Andrew Bartlett
-rw-r--r-- | source3/winbindd/winbindd.c | 48 | ||||
-rw-r--r-- | source3/winbindd/winbindd_proto.h | 3 |
2 files changed, 48 insertions, 3 deletions
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 5e23859b40..3806eb8b2b 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -203,6 +203,26 @@ static void winbindd_sig_term_handler(struct tevent_context *ev, terminate(*is_parent); } +/* + handle stdin becoming readable when we are in --foreground mode + */ +static void winbindd_stdin_handler(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, + void *private_data) +{ + char c; + if (read(0, &c, 1) != 1) { + bool *is_parent = talloc_get_type_abort(private_data, bool); + + /* we have reached EOF on stdin, which means the + parent has exited. Shutdown the server */ + DEBUG(0,("EOF on stdin (is_parent=%d)\n", + (int)*is_parent)); + terminate(*is_parent); + } +} + bool winbindd_setup_sig_term_handler(bool parent) { struct tevent_signal *se; @@ -251,6 +271,28 @@ bool winbindd_setup_sig_term_handler(bool parent) return true; } +bool winbindd_setup_stdin_handler(bool parent, bool foreground) +{ + bool *is_parent; + + if (foreground) { + is_parent = talloc(winbind_event_context(), bool); + if (!is_parent) { + return false; + } + + *is_parent = parent; + + /* if we are running in the foreground then look for + EOF on stdin, and exit if it happens. This allows + us to die if the parent process dies + */ + tevent_add_fd(winbind_event_context(), is_parent, 0, TEVENT_FD_READ, winbindd_stdin_handler, is_parent); + } + + return true; +} + static void winbindd_sig_hup_handler(struct tevent_context *ev, struct tevent_signal *se, int signum, @@ -1028,12 +1070,14 @@ bool winbindd_use_cache(void) return !opt_nocache; } -void winbindd_register_handlers(void) +void winbindd_register_handlers(bool foreground) { /* Setup signal handlers */ if (!winbindd_setup_sig_term_handler(true)) exit(1); + if (!winbindd_setup_stdin_handler(true, foreground)) + exit(1); if (!winbindd_setup_sig_hup_handler(NULL)) exit(1); if (!winbindd_setup_sig_chld_handler()) @@ -1413,7 +1457,7 @@ int main(int argc, char **argv, char **envp) exit(1); } - winbindd_register_handlers(); + winbindd_register_handlers(!Fork); status = init_system_info(); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index b965fdaf1d..3746fe0268 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -28,10 +28,11 @@ struct messaging_context *winbind_messaging_context(void); void request_error(struct winbindd_cli_state *state); void request_ok(struct winbindd_cli_state *state); bool winbindd_setup_sig_term_handler(bool parent); +bool winbindd_setup_stdin_handler(bool parent, bool foreground); bool winbindd_setup_sig_hup_handler(const char *lfile); bool winbindd_use_idmap_cache(void); bool winbindd_use_cache(void); -void winbindd_register_handlers(void); +void winbindd_register_handlers(bool foreground); const char *get_winbind_pipe_dir(void); char *get_winbind_priv_pipe_dir(void); int main(int argc, char **argv, char **envp); |