{
DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
"updated. Reloading.\n"));
+ change_to_root_user();
reload_services(False);
}
}
#endif /* DEVELOPER */
-struct child_pid {
- struct child_pid *prev, *next;
- pid_t pid;
-};
-
-static void add_child_pid(pid_t pid)
+/*
+ * Parent smbd process sets its own debug level first and then
+ * sends a message to all the smbd children to adjust their debug
+ * level to that of the parent.
+ */
+
+static void smbd_msg_debug(struct messaging_context *msg_ctx,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id server_id,
+ DATA_BLOB *data)
{
struct child_pid *child;
- if (lp_max_smbd_processes() == 0) {
- /* Don't bother with the child list if we don't care anyway */
- return;
+ debug_message(msg_ctx, private_data, MSG_DEBUG, server_id, data);
+
+ for (child = children; child != NULL; child = child->next) {
+ messaging_send_buf(msg_ctx, pid_to_procid(child->pid),
+ MSG_DEBUG,
+ data->data,
+ strlen((char *) data->data) + 1);
}
+}
+
+static void add_child_pid(pid_t pid)
+{
+ struct child_pid *child;
child = SMB_MALLOC_P(struct child_pid);
if (child == NULL) {
MSG_SMB_UNLOCK, NULL, 0, NULL);
}
- if (lp_max_smbd_processes() == 0) {
- /* Don't bother with the child list if we don't care anyway */
- return;
- }
-
for (child = children; child != NULL; child = child->next) {
if (child->pid == pid) {
struct child_pid *tmp = child;
pid = sys_fork();
if (pid == 0) {
+ NTSTATUS status = NT_STATUS_OK;
/* Child code ... */
am_parent = 0;
talloc_free(s->parent);
s = NULL;
- if (!reinit_after_fork(
- smbd_messaging_context(),
- smbd_event_context(),
- true)) {
+ status = reinit_after_fork(smbd_messaging_context(),
+ smbd_event_context(), true);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,
+ NT_STATUS_TOO_MANY_OPENED_FILES)) {
+ DEBUG(0,("child process cannot initialize "
+ "because too many files are open\n"));
+ goto exit;
+ }
DEBUG(0,("reinit_after_fork() failed\n"));
smb_panic("reinit_after_fork() failed");
}
smbd_setup_sig_hup_handler();
smbd_process();
+ exit:
exit_server_cleanly("end of child");
return;
} else if (pid < 0) {
MSG_SMB_CONF_UPDATED, smb_conf_updated);
messaging_register(smbd_messaging_context(), NULL,
MSG_SMB_STAT_CACHE_DELETE, smb_stat_cache_delete);
+ messaging_register(smbd_messaging_context(), NULL,
+ MSG_DEBUG, smbd_msg_debug);
brl_register_msgs(smbd_messaging_context());
#ifdef CLUSTER_SUPPORT
static void exit_server_common(enum server_exit_reason how,
const char *const reason)
{
- bool had_open_conn;
+ bool had_open_conn = false;
+ struct smbd_server_connection *sconn = smbd_server_conn;
if (!exit_firsttime)
exit(0);
change_to_root_user();
- if (negprot_global_auth_context) {
- (negprot_global_auth_context->free)(&negprot_global_auth_context);
+ if (sconn && sconn->smb1.negprot.auth_context) {
+ struct auth_context *a = sconn->smb1.negprot.auth_context;
+ a->free(&sconn->smb1.negprot.auth_context);
}
- had_open_conn = conn_close_all();
-
- invalidate_all_vuids();
+ if (sconn) {
+ had_open_conn = conn_close_all(sconn);
+ invalidate_all_vuids(sconn);
+ }
/* 3 second timeout. */
print_notify_send_messages(smbd_messaging_context(), 3);
locking_end();
printing_end();
+ /*
+ * we need to force the order of freeing the following,
+ * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
+ */
+ sconn = NULL;
+ TALLOC_FREE(smbd_server_conn);
+ TALLOC_FREE(smbd_msg_ctx);
+ TALLOC_FREE(smbd_event_ctx);
+
if (how != SERVER_EXIT_NORMAL) {
int oldlevel = DEBUGLEVEL;
} else {
DEBUG(3,("Server exit (%s)\n",
(reason ? reason : "normal exit")));
+ if (am_parent) {
+ pidfile_unlink();
+ }
+ gencache_stabilize();
}
/* if we had any open SMB connections when we exited then we
if (!init_names())
return False;
- conn_init();
-
file_init();
- init_dptrs();
-
if (!secrets_init())
return False;
gain_root_privilege();
gain_root_group_privilege();
+ /*
+ * Ensure we have CAP_KILL capability set on Linux,
+ * where we need this to communicate with threads.
+ * This is inherited by new threads, but not by new
+ * processes across exec().
+ */
+ set_effective_capability(KILL_CAPABILITY);
+
fault_setup((void (*)(void *))exit_server_fault);
dump_core_setup("smbd");
BlockSignals(False, SIGUSR1);
BlockSignals(False, SIGTERM);
+ /* Ensure we leave no zombies until we
+ * correctly set up child handling below. */
+
+ CatchChild();
+
/* we want total control over the permissions on created files,
so set our umask to 0 */
umask(0);
if (is_daemon)
pidfile_create("smbd");
- if (!reinit_after_fork(smbd_messaging_context(),
- smbd_event_context(), false)) {
+ if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
+ smbd_event_context(), false))) {
DEBUG(0,("reinit_after_fork() failed\n"));
exit(1);
}
return -1;
}
+ /* Open the share_info.tdb here, so we don't have to open
+ after the fork on every single connection. This is a small
+ performance improvment and reduces the total number of system
+ fds used. */
+ if (!share_info_db_init()) {
+ DEBUG(0,("ERROR: failed to load share info db.\n"));
+ exit(1);
+ }
+
/* only start the background queue daemon if we are
running as a daemon -- bad things will happen if
smbd is launched via inetd and we fork a copy of
/* close our standard file descriptors */
close_low_fds(False); /* Don't close stderr */
+#ifdef HAVE_ATEXIT
+ atexit(killkids);
+#endif
+
+ /* Stop zombies */
+ smbd_setup_sig_chld_handler();
+
smbd_process();
exit_server_cleanly(NULL);