The branch, master has been updated via 099df25 source4 smbd: remove global control pipe from process_standard. via 575f1e2 lib/util: Fix build for lttng libraries that does not support tracef via 0ac94ad smb.conf: Update multi-channel warning text from 15d14d6 docs/ntvfshandler: remove duplicate value
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 099df25f567a34bf0c159e18b62cd67b073c3002 Author: Gary Lockyer <g...@catalyst.net.nz> Date: Tue Aug 22 07:58:14 2017 +1200 source4 smbd: remove global control pipe from process_standard. The standard model uses a pipe to signal the worker processes spawned on accept that the controlling process has terminated and that they should shut down. This pipe is currently a static global variable in process_standard.c. This patch replaces that global pipe with a file descriptor passed into the process model init functions, giving a single mechanism across all process models. This paves the way for the addition of a pre-fork process model. Ensuring that the correct file descriptors are closed, is difficult so it is best do this only once rather than require the process models to do this individually. Notes on debugging pipe ownership: Add code to log the process id and the file descriptor of the writeable pipe. run: lsof | grep FIFO | grep samba | grep <process id> this will produce lines like: samba 25624 him 4w FIFO 0,10 0t0 472206 pipe where: 4w is the file descriptor and mode and the number to the left of "pipe" is the pipe id. then: lsof | grep FIFO | grep samba | grep <pipe id> This will display all the processes with the pipe open and the mode only the smbd master process should have it open in write mode. Signed-off-by: Gary Lockyer <g...@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> Autobuild-User(master): Ralph Böhme <s...@samba.org> Autobuild-Date(master): Thu Sep 28 02:08:34 CEST 2017 on sn-devel-144 commit 575f1e2bf51131709f55d565568198f56a0cbdda Author: Christof Schmitt <c...@samba.org> Date: Thu Sep 8 14:03:02 2016 -0700 lib/util: Fix build for lttng libraries that does not support tracef On a system that has older lttng-ust development headers installed that do not yet provide the tracef api, configure fails with: Checking for library lttng-ust : yes ERROR: Target 'lttng-ust' in directory /samba/lib/util re-defined as EMPTY - was SYSLIB Fix the initialization order in waf, to not redefine the lttng-ust target Signed-off-by: Christof Schmitt <c...@samba.org> Reviewed-by: Ralph Boehme <s...@samba.org> commit 0ac94ad963111663813c0a3739d5289ac0a61ba8 Author: Justin Maggard via samba-technical <samba-techni...@lists.samba.org> Date: Thu Sep 7 11:04:55 2017 -0700 smb.conf: Update multi-channel warning text Since Samba 4.4.x is going EOL soon, update the server multi channel support warning text to reflect the fact that it's still experimental in 4.7, and it won't be getting fixed in a future 4.4.x version. Signed-off-by: Justin Maggard <jmagg...@netgear.com> Reviewed-by: Ralph Boehme <s...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> ----------------------------------------------------------------------- Summary of changes: .../protocol/servermultichannelsupport.xml | 6 +- lib/util/wscript_configure | 5 +- source4/smbd/process_model.h | 3 +- source4/smbd/process_single.c | 7 ++- source4/smbd/process_standard.c | 30 +++------ source4/smbd/server.c | 73 ++++++++++++++++++++-- source4/smbd/service.c | 17 +++-- source4/smbd/service_task.c | 9 ++- 8 files changed, 102 insertions(+), 48 deletions(-) Changeset truncated at 500 lines: diff --git a/docs-xml/smbdotconf/protocol/servermultichannelsupport.xml b/docs-xml/smbdotconf/protocol/servermultichannelsupport.xml index 14db171..e397854 100644 --- a/docs-xml/smbdotconf/protocol/servermultichannelsupport.xml +++ b/docs-xml/smbdotconf/protocol/servermultichannelsupport.xml @@ -8,12 +8,12 @@ <manvolnum>8</manvolnum></citerefentry> will support SMB3 multi-channel. </para> - <para>This parameter has been added with version 4.4.</para> + <para>This parameter was added with version 4.4.</para> <para> - Warning: Note that this feature is considered experimental in Samba 4.4. + Warning: Note that this feature is still considered experimental. Use it at your own risk: Even though it may seem to work well in testing, it may result in data corruption under some race conditions. - Future 4.4.x release may improve this situation. + Future releases may improve this situation. </para> </description> diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure index 7c17633..8e5a59c 100644 --- a/lib/util/wscript_configure +++ b/lib/util/wscript_configure @@ -122,6 +122,8 @@ if Options.options.enable_systemd != False: conf.CHECK_LIB('systemd-daemon', shlib=True) conf.CHECK_LIB('systemd-journal', shlib=True) +conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY') + if Options.options.enable_lttng != False: conf.CHECK_CFG(package='lttng-ust', args='--cflags --libs', msg='Checking for lttng-ust', uselib_store="LTTNG-UST") @@ -132,9 +134,6 @@ if (conf.CONFIG_SET('HAVE_LTTNG_TRACEF_H') and conf.CONFIG_SET('HAVE_LTTNG_UST')): conf.DEFINE('HAVE_LTTNG_TRACEF', '1') conf.env['HAVE_LTTNG_TRACEF'] = True -else: - conf.SET_TARGET_TYPE('lttng-ust', 'EMPTY') - conf.undefine('HAVE_LTTNG_TRACEF') conf.env['CPPPATH_GPFS'] = Options.options.gpfs_headers_dir if conf.CHECK_HEADERS('gpfs.h', False, False, "gpfs"): diff --git a/source4/smbd/process_model.h b/source4/smbd/process_model.h index 4399d36..d7bf3c8 100644 --- a/source4/smbd/process_model.h +++ b/source4/smbd/process_model.h @@ -61,7 +61,8 @@ struct model_ops { void (*)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), - void *); + void *, + int); /* function to terminate a connection or task */ void (*terminate)(struct tevent_context *, struct loadparm_context *lp_ctx, diff --git a/source4/smbd/process_single.c b/source4/smbd/process_single.c index f483e00..54169e9 100644 --- a/source4/smbd/process_single.c +++ b/source4/smbd/process_single.c @@ -85,11 +85,12 @@ static void single_accept_connection(struct tevent_context *ev, /* called to startup a new task */ -static void single_new_task(struct tevent_context *ev, +static void single_new_task(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *service_name, - void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), - void *private_data) + void (*new_task)(struct tevent_context *, struct loadparm_context *, struct server_id, void *), + void *private_data, + int from_parent_fd) { pid_t pid = getpid(); /* start our taskids at MAX_INT32, the first 2^31 tasks are is reserved for fd numbers */ diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index 8d962d5..c6cbfc2 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -42,22 +42,13 @@ struct standard_child_state { NTSTATUS process_model_standard_init(TALLOC_CTX *); -/* 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] = { -1, -1 }; +static int from_parent_fd; /* called when the process model is selected */ static void standard_model_init(void) { - int rc; - - rc = pipe(child_pipe); - if (rc < 0) { - smb_panic("Failed to initialize pipe!"); - } } static void sighup_signal_handler(struct tevent_context *ev, @@ -312,17 +303,12 @@ static void standard_accept_connection(struct tevent_context *ev, smb_panic("Failed to re-initialise imessaging after fork"); } - fde = tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ, + fde = tevent_add_fd(ev, ev, from_parent_fd, TEVENT_FD_READ, standard_pipe_handler, NULL); if (fde == NULL) { smb_panic("Failed to add fd handler after fork"); } - if (child_pipe[1] != -1) { - close(child_pipe[1]); - child_pipe[1] = -1; - } - se = tevent_add_signal(ev, ev, SIGHUP, @@ -368,11 +354,12 @@ static void standard_accept_connection(struct tevent_context *ev, /* called to create a new server task */ -static void standard_new_task(struct tevent_context *ev, +static void standard_new_task(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *service_name, void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), - void *private_data) + void *private_data, + int new_from_parent_fd) { pid_t pid; NTSTATUS status; @@ -384,6 +371,7 @@ static void standard_new_task(struct tevent_context *ev, if (state == NULL) { return; } + from_parent_fd = new_from_parent_fd; pid = fork(); @@ -421,15 +409,11 @@ static void standard_new_task(struct tevent_context *ev, smb_panic("Failed to re-initialise imessaging after fork"); } - fde = tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ, + fde = tevent_add_fd(ev, ev, from_parent_fd, TEVENT_FD_READ, standard_pipe_handler, NULL); if (fde == NULL) { smb_panic("Failed to add fd handler after fork"); } - if (child_pipe[1] != -1) { - close(child_pipe[1]); - child_pipe[1] = -1; - } se = tevent_add_signal(ev, ev, diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 249391c..66f2794 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -43,6 +43,11 @@ #include "lib/util/samba_modules.h" #include "nsswitch/winbind_client.h" #include "libds/common/roles.h" +#include "lib/util/tfork.h" + +#ifdef HAVE_PTHREAD +#include <pthread.h> +#endif struct server_state { struct tevent_context *event_ctx; @@ -332,6 +337,20 @@ static int event_ctx_destructor(struct tevent_context *event_ctx) return 0; } +#ifdef HAVE_PTHREAD +static int to_children_fd = -1; +static void atfork_prepare(void) { +} +static void atfork_parent(void) { +} +static void atfork_child(void) { + if (to_children_fd != -1) { + close(to_children_fd); + to_children_fd = -1; + } +} +#endif + /* main server. */ @@ -608,12 +627,54 @@ static int binary_smbd_main(const char *binary_name, DEBUG(0,("%s: using '%s' process model\n", binary_name, model)); - status = server_service_startup(state->event_ctx, cmdline_lp_ctx, model, - lpcfg_server_services(cmdline_lp_ctx)); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(state); - exit_daemon("Samba failed to start services", - NT_STATUS_V(status)); + { + int child_pipe[2]; + int rc; + bool start_services = false; + + rc = pipe(child_pipe); + if (rc < 0) { + TALLOC_FREE(state); + exit_daemon("Samba failed to open process control pipe", + errno); + } + smb_set_close_on_exec(child_pipe[0]); + smb_set_close_on_exec(child_pipe[1]); + +#ifdef HAVE_PTHREAD + to_children_fd = child_pipe[1]; + pthread_atfork(atfork_prepare, atfork_parent, + atfork_child); + start_services = true; +#else + pid_t pid; + struct tfork *t = NULL; + t = tfork_create(); + if (t == NULL) { + exit_daemon( + "Samba unable to fork master process", + 0); + } + pid = tfork_child_pid(t); + if (pid == 0) { + start_services = false; + } else { + /* In the child process */ + start_services = true; + close(child_pipe[1]); + } +#endif + if (start_services) { + status = server_service_startup( + state->event_ctx, cmdline_lp_ctx, model, + lpcfg_server_services(cmdline_lp_ctx), + child_pipe[0]); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(state); + exit_daemon("Samba failed to start services", + NT_STATUS_V(status)); + } + } } if (opt_daemon) { diff --git a/source4/smbd/service.c b/source4/smbd/service.c index 403ae74..61ed684 100644 --- a/source4/smbd/service.c +++ b/source4/smbd/service.c @@ -56,13 +56,16 @@ NTSTATUS register_server_service(TALLOC_CTX *ctx, static NTSTATUS server_service_init(const char *name, struct tevent_context *event_context, struct loadparm_context *lp_ctx, - const struct model_ops *model_ops) + const struct model_ops *model_ops, + int from_parent_fd) { struct registered_server *srv; for (srv=registered_servers; srv; srv=srv->next) { if (strcasecmp(name, srv->service_name) == 0) { - return task_server_startup(event_context, lp_ctx, srv->service_name, - model_ops, srv->task_init); + return task_server_startup(event_context, lp_ctx, + srv->service_name, + model_ops, srv->task_init, + from_parent_fd); } } return NT_STATUS_INVALID_SYSTEM_SERVICE; @@ -72,9 +75,10 @@ static NTSTATUS server_service_init(const char *name, /* startup all of our server services */ -NTSTATUS server_service_startup(struct tevent_context *event_ctx, +NTSTATUS server_service_startup(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, - const char *model, const char **server_services) + const char *model, const char **server_services, + int from_parent_fd) { int i; const struct model_ops *model_ops; @@ -93,7 +97,8 @@ NTSTATUS server_service_startup(struct tevent_context *event_ctx, for (i=0;server_services[i];i++) { NTSTATUS status; - status = server_service_init(server_services[i], event_ctx, lp_ctx, model_ops); + status = server_service_init(server_services[i], event_ctx, + lp_ctx, model_ops, from_parent_fd); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("Failed to start service '%s' - %s\n", server_services[i], nt_errstr(status))); diff --git a/source4/smbd/service_task.c b/source4/smbd/service_task.c index 34f73d9..e0e98f6 100644 --- a/source4/smbd/service_task.c +++ b/source4/smbd/service_task.c @@ -101,7 +101,8 @@ NTSTATUS task_server_startup(struct tevent_context *event_ctx, struct loadparm_context *lp_ctx, const char *service_name, const struct model_ops *model_ops, - void (*task_init)(struct task_server *)) + void (*task_init)(struct task_server *), + int from_parent_fd) { struct task_state *state; @@ -110,8 +111,10 @@ NTSTATUS task_server_startup(struct tevent_context *event_ctx, state->task_init = task_init; state->model_ops = model_ops; - - model_ops->new_task(event_ctx, lp_ctx, service_name, task_server_callback, state); + + state->model_ops->new_task(event_ctx, lp_ctx, service_name, + task_server_callback, state, + from_parent_fd); return NT_STATUS_OK; } -- Samba Shared Repository