summaryrefslogtreecommitdiff
path: root/source4/smbd
diff options
context:
space:
mode:
Diffstat (limited to 'source4/smbd')
-rw-r--r--source4/smbd/process_standard.c24
-rw-r--r--source4/smbd/server.c18
2 files changed, 42 insertions, 0 deletions
diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c
index 137e0a7ce0..730e185e5a 100644
--- a/source4/smbd/process_standard.c
+++ b/source4/smbd/process_standard.c
@@ -44,15 +44,31 @@ static int none_setproctitle(const char *fmt, ...)
}
#endif
+/* we hold a pipe open in the parent, and the any child
+ processes wait for EOF on that pipe. This ensures that
+ children die when the parent dies */
+static int child_pipe[2];
+
/*
called when the process model is selected
*/
static void standard_model_init(struct tevent_context *ev)
{
+ pipe(child_pipe);
signal(SIGCHLD, SIG_IGN);
}
/*
+ handle EOF on the child pipe
+*/
+static void standard_pipe_handler(struct tevent_context *event_ctx, struct tevent_fd *fde,
+ uint16_t flags, void *private_data)
+{
+ DEBUG(10,("Child %d exiting\n", (int)getpid()));
+ exit(0);
+}
+
+/*
called when a listening socket becomes readable.
*/
static void standard_accept_connection(struct tevent_context *ev,
@@ -114,6 +130,10 @@ static void standard_accept_connection(struct tevent_context *ev,
DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
}
+ tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
+ standard_pipe_handler, NULL);
+ close(child_pipe[1]);
+
/* Ensure that the forked children do not expose identical random streams */
set_need_random_reseed();
@@ -177,6 +197,10 @@ static void standard_new_task(struct tevent_context *ev,
DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
}
+ tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
+ standard_pipe_handler, NULL);
+ close(child_pipe[1]);
+
/* Ensure that the forked children do not expose identical random streams */
set_need_random_reseed();
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index 635e84fafe..bb2571e819 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -38,6 +38,8 @@
#include "param/secrets.h"
#include "smbd/pidfile.h"
#include "param/param.h"
+#include "dsdb/samdb/samdb.h"
+#include "auth/session.h"
/*
recursively delete a directory tree
@@ -112,6 +114,7 @@ static void sig_term(int sig)
kill(-getpgrp(), SIGTERM);
}
#endif
+ DEBUG(0,("Exiting pid %d on SIGTERM\n", (int)getpid()));
exit(0);
}
@@ -157,6 +160,7 @@ static void server_stdin_handler(struct tevent_context *event_ctx, struct tevent
DEBUG(0,("%s: EOF on stdin - terminating\n", binary_name));
#if HAVE_GETPGRP
if (getpgrp() == getpid()) {
+ DEBUG(0,("Sending SIGTERM from pid %d\n", (int)getpid()));
kill(-getpgrp(), SIGTERM);
}
#endif
@@ -177,6 +181,18 @@ _NORETURN_ static void max_runtime_handler(struct tevent_context *ev,
}
/*
+ pre-open the sam ldb to ensure the schema has been loaded. This
+ saves a lot of time in child processes
+ */
+static void prime_samdb_schema(struct tevent_context *event_ctx)
+{
+ TALLOC_CTX *samdb_context;
+ samdb_context = talloc_new(event_ctx);
+ samdb_connect(samdb_context, event_ctx, cmdline_lp_ctx, system_session(samdb_context, cmdline_lp_ctx));
+ talloc_free(samdb_context);
+}
+
+/*
main server.
*/
static int binary_smbd_main(const char *binary_name, int argc, const char *argv[])
@@ -344,6 +360,8 @@ static int binary_smbd_main(const char *binary_name, int argc, const char *argv[
discard_const(binary_name));
}
+ prime_samdb_schema(event_ctx);
+
DEBUG(0,("%s: using '%s' process model\n", binary_name, model));
status = server_service_startup(event_ctx, cmdline_lp_ctx, model,
lp_server_services(cmdline_lp_ctx));