num_children += 1;
}
+/*
+ at most every smbd:cleanuptime seconds (default 20), we scan the BRL
+ and locking database for entries to cleanup. As a side effect this
+ also cleans up dead entries in the connections database (due to the
+ traversal in message_send_all()
+
+ Using a timer for this prevents a flood of traversals when a large
+ number of clients disconnect at the same time (perhaps due to a
+ network outage).
+*/
+
+static void cleanup_timeout_fn(struct event_context *event_ctx,
+ struct timed_event *te,
+ struct timeval now,
+ void *private_data)
+{
+ struct timed_event **cleanup_te = (struct timed_event **)private_data;
+
+ DEBUG(1,("Cleaning up brl and lock database after unclean shutdown\n"));
+ message_send_all(smbd_messaging_context(), MSG_SMB_UNLOCK, NULL, 0, NULL);
+ messaging_send_buf(smbd_messaging_context(), procid_self(),
+ MSG_SMB_BRL_VALIDATE, NULL, 0);
+ /* mark the cleanup as having been done */
+ (*cleanup_te) = NULL;
+}
+
static void remove_child_pid(pid_t pid, bool unclean_shutdown)
{
struct child_pid *child;
+ static struct timed_event *cleanup_te;
if (unclean_shutdown) {
- /* a child terminated uncleanly so tickle all processes to see
- if they can grab any of the pending locks
- */
- DEBUG(3,(__location__ " Unclean shutdown of pid %u\n", (unsigned int)pid));
- messaging_send_buf(smbd_messaging_context(), procid_self(),
- MSG_SMB_BRL_VALIDATE, NULL, 0);
- message_send_all(smbd_messaging_context(),
- MSG_SMB_UNLOCK, NULL, 0, NULL);
+ /* a child terminated uncleanly so tickle all
+ processes to see if they can grab any of the
+ pending locks
+ */
+ DEBUG(3,(__location__ " Unclean shutdown of pid %u\n",
+ (unsigned int)pid));
+ if (!cleanup_te) {
+ /* call the cleanup timer, but not too often */
+ int cleanup_time = lp_parm_int(-1, "smbd", "cleanuptime", 20);
+ cleanup_te = event_add_timed(smbd_event_context(), NULL,
+ timeval_current_ofs(cleanup_time, 0),
+ cleanup_timeout_fn,
+ &cleanup_te);
+ DEBUG(1,("Scheduled cleanup of brl and lock database after unclean shutdown\n"));
+ }
}
for (child = children; child != NULL; child = child->next) {
}
}
- DEBUG(0, ("Could not find child %d -- ignoring\n", (int)pid));
+ /* not all forked child processes are added to the children list */
+ DEBUG(1, ("Could not find child %d -- ignoring\n", (int)pid));
}
/****************************************************************************
return true;
}
+static bool parent_housekeeping_fn(const struct timeval *now, void *private_data)
+{
+ DEBUG(5, ("houskeeping\n"));
+ /* check if we need to reload services */
+ check_reload(time(NULL));
+ return true;
+}
+
/****************************************************************************
Open the socket communication.
****************************************************************************/
continue;
}
+ /* Keep the first port for mDNS service
+ * registration.
+ */
+ if (dns_port == 0) {
+ dns_port = port;
+ }
+
if (!smbd_open_one_socket(parent, ifss, port)) {
return false;
}
claim_connection(NULL,"",
FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_DBWRAP);
+ if (!(event_add_idle(smbd_event_context(), NULL,
+ timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
+ "parent_housekeeping", parent_housekeeping_fn,
+ parent))) {
+ DEBUG(0, ("Could not add housekeeping event\n"));
+ exit(1);
+ }
+
/* Listen to messages */
messaging_register(smbd_messaging_context(), NULL,
/* NOTREACHED return True; */
}
-/****************************************************************************
- Reload printers
-**************************************************************************/
+/***************************************************************************
+ purge stale printers and reload from pre-populated pcap cache
+***************************************************************************/
void reload_printers(void)
{
int snum;
int pnum = lp_servicenumber(PRINTERS_NAME);
const char *pname;
- pcap_cache_reload();
-
- /* remove stale printers */
+ DEBUG(10, ("reloading printer services from pcap cache\n"));
for (snum = 0; snum < n_services; snum++) {
/* avoid removing PRINTERS_NAME or non-autoloaded printers */
if (snum == pnum || !(lp_snum_ok(snum) && lp_print_ok(snum) &&
set_dyn_CONFIGFILE(fname);
test = False;
}
+ TALLOC_FREE(fname);
}
reopen_logs();
ret = lp_load(get_dyn_CONFIGFILE(), False, False, True, True);
- reload_printers();
+ pcap_cache_reload(&reload_printers);
/* perhaps the config filename is now set */
if (!test)
file_init();
- init_dptrs();
-
if (!secrets_init())
return False;
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
exit_server("open_sockets_smbd() failed");
TALLOC_FREE(frame);
+ /* make sure we always have a valid stackframe */
+ frame = talloc_stackframe();
smbd_parent_loop(parent);
exit_server_cleanly(NULL);
+ TALLOC_FREE(frame);
return(0);
}