{
DEBUG(10,("smb_conf_updated: Got message saying smb.conf was "
"updated. Reloading.\n"));
+ change_to_root_user();
reload_services(False);
}
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) {
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.
****************************************************************************/
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,
#endif
if (dns_port != 0) {
+#ifdef WITH_DNSSD_SUPPORT
smbd_setup_mdns_registration(smbd_event_context(),
parent, dns_port);
+#endif
+#ifdef WITH_AVAHI_SUPPORT
+ void *avahi_conn;
+
+ avahi_conn = avahi_start_register(
+ smbd_event_context(), smbd_event_context(), dns_port);
+ if (avahi_conn == NULL) {
+ DEBUG(10, ("avahi_start_register failed\n"));
+ }
+#endif
}
return true;
{
/* now accept incoming connections - forking a new process
for each incoming connection */
- DEBUG(2,("waiting for a connection\n"));
+ DEBUG(2,("waiting for connections\n"));
while (1) {
- struct timeval now, idle_timeout;
- fd_set r_fds, w_fds;
- int maxfd = 0;
- int num;
+ int ret;
TALLOC_CTX *frame = talloc_stackframe();
- if (run_events(smbd_event_context(), 0, NULL, NULL)) {
- TALLOC_FREE(frame);
- continue;
+ ret = tevent_loop_once(smbd_event_context());
+ if (ret != 0) {
+ exit_server_cleanly("tevent_loop_once() error");
}
- idle_timeout = timeval_zero();
-
- FD_ZERO(&w_fds);
- FD_ZERO(&r_fds);
- GetTimeOfDay(&now);
-
- event_add_to_select_args(smbd_event_context(), &now,
- &r_fds, &w_fds, &idle_timeout,
- &maxfd);
-
- num = sys_select(maxfd+1,&r_fds,&w_fds,NULL,
- timeval_is_zero(&idle_timeout) ?
- NULL : &idle_timeout);
-
- /* check if we need to reload services */
- check_reload(time(NULL));
-
- if (run_events(smbd_event_context(), num, &r_fds, &w_fds)) {
- TALLOC_FREE(frame);
- continue;
- }
-
- /* socket error */
- if (num < 0)
- exit_server_cleanly("socket error");
-
- /* If the idle timeout fired and we don't have any connected
- * users, exit gracefully. We should be running under a process
- * controller that will restart us if necessry.
- */
- if (num == 0 && count_all_current_connections() == 0) {
- exit_server_cleanly("idle timeout");
- }
TALLOC_FREE(frame);
} /* end while 1 */
/* 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) &&
DEBUG(3, ("removing stale printer %s\n", pname));
if (is_printer_published(NULL, snum, NULL))
- nt_printer_publish(NULL, snum, SPOOL_DS_UNPUBLISH);
+ nt_printer_publish(NULL, snum, DSPRINT_UNPUBLISH);
del_a_printer(pname);
lp_killservice(snum);
}
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)
} else {
DEBUG(3,("Server exit (%s)\n",
(reason ? reason : "normal exit")));
+ if (am_parent) {
+ pidfile_unlink();
+ }
}
/* if we had any open SMB connections when we exited then we
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);
}
/* 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);