summaryrefslogtreecommitdiff
path: root/source3/winbindd/winbindd.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-03-02 18:22:10 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-03-04 10:14:34 +0100
commit769cee44a2ed1b68cb757246efd72d63aa36a4d0 (patch)
treef3b5edddc515ddd653f9198991fdc8fd99491e9d /source3/winbindd/winbindd.c
parent807f5f1a8b02176e03b00f4415c0cae1927b44a4 (diff)
downloadsamba-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
Diffstat (limited to 'source3/winbindd/winbindd.c')
-rw-r--r--source3/winbindd/winbindd.c48
1 files changed, 46 insertions, 2 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)) {