summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-03-02 18:21:09 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-03-04 10:14:34 +0100
commit807f5f1a8b02176e03b00f4415c0cae1927b44a4 (patch)
treedadf627f000f2acd06745c0c04e589f1efadfa8a
parentb07d504ca4e476d492beb5552344070e4f96464a (diff)
downloadsamba-807f5f1a8b02176e03b00f4415c0cae1927b44a4.tar.gz
samba-807f5f1a8b02176e03b00f4415c0cae1927b44a4.tar.bz2
samba-807f5f1a8b02176e03b00f4415c0cae1927b44a4.zip
s3-nmbd: Add stdin handler for nmbd
This will help avoid runaway processes in the test env, particularly when the whole selftest.pl is killed. Andrew Bartlett
-rw-r--r--source3/nmbd/nmbd.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 35a9a31f8a..7bd4facbb1 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -88,6 +88,24 @@ static void nmbd_sig_term_handler(struct tevent_context *ev,
terminate(msg);
}
+/*
+ handle stdin becoming readable when we are in --foreground mode
+ */
+static void nmbd_stdin_handler(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags,
+ void *private_data)
+{
+ char c;
+ if (read(0, &c, 1) != 1) {
+ struct messaging_context *msg = talloc_get_type_abort(
+ private_data, struct messaging_context);
+
+ DEBUG(0,("EOF on stdin\n"));
+ terminate(msg);
+ }
+}
+
static bool nmbd_setup_sig_term_handler(struct messaging_context *msg)
{
struct tevent_signal *se;
@@ -105,6 +123,19 @@ static bool nmbd_setup_sig_term_handler(struct messaging_context *msg)
return true;
}
+static bool nmbd_setup_stdin_handler(struct messaging_context *msg, bool foreground)
+{
+ if (foreground) {
+ /* 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(nmbd_event_context(), nmbd_event_context(), 0, TEVENT_FD_READ, nmbd_stdin_handler, msg);
+ }
+
+ return true;
+}
+
static void msg_reload_nmbd_services(struct messaging_context *msg,
void *private_data,
uint32_t msg_type,
@@ -918,6 +949,8 @@ static bool open_sockets(bool isdaemon, int port)
if (!nmbd_setup_sig_term_handler(msg))
exit(1);
+ if (!nmbd_setup_stdin_handler(msg, !Fork))
+ exit(1);
if (!nmbd_setup_sig_hup_handler(msg))
exit(1);