summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-11-30 14:08:28 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-02-28 12:01:08 +0100
commit1da318d97da6c7f9e8d5d389fc06619b423fcda0 (patch)
tree8edab711a51491b0a84914f7424546a4fae7bed5 /source3/smbd
parent645fcc5375325b700ac58cb25c498f6f7b91421b (diff)
downloadsamba-1da318d97da6c7f9e8d5d389fc06619b423fcda0.tar.gz
samba-1da318d97da6c7f9e8d5d389fc06619b423fcda0.tar.bz2
samba-1da318d97da6c7f9e8d5d389fc06619b423fcda0.zip
smbd: detect EOF on stdin in --foreground mode
if EOF is detected on stdin then exit
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/server.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index f89bfd4475..986eb21439 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -857,6 +857,23 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
return true;
}
+
+/*
+ handle stdin becoming readable when we are in --foreground mode
+ */
+static void smbd_stdin_handler(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags,
+ void *private_data)
+{
+ char c;
+ if (read(0, &c, 1) != 1) {
+ /* we have reached EOF on stdin, which means the
+ parent has exited. Shutdown the server */
+ exit_server_cleanly("EOF on stdin");
+ }
+}
+
static void smbd_parent_loop(struct tevent_context *ev_ctx,
struct smbd_parent_context *parent)
{
@@ -1409,6 +1426,14 @@ extern void build_options(bool screen);
/* make sure we always have a valid stackframe */
frame = talloc_stackframe();
+ if (!Fork) {
+ /* 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(ev_ctx, parent, 0, TEVENT_FD_READ, smbd_stdin_handler, NULL);
+ }
+
smbd_parent_loop(ev_ctx, parent);
exit_server_cleanly(NULL);