#include "includes.h"
-int am_parent = 1;
+static int am_parent = 1;
/* the last message the was processed */
int last_message = -1;
Have we reached the process limit ?
****************************************************************************/
-BOOL allowable_number_of_smbd_processes(void)
+static BOOL allowable_number_of_smbd_processes(void)
{
int max_processes = lp_max_smbd_processes();
/* ready to listen */
set_socket_options(s,"SO_KEEPALIVE");
set_socket_options(s,user_socket_options);
-
- if (listen(s, 5) == -1) {
+
+ /* Set server socket to non-blocking for the accept. */
+ set_blocking(s,False);
+
+ if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
DEBUG(0,("listen: %s\n",strerror(errno)));
close(s);
return False;
set_socket_options(s,"SO_KEEPALIVE");
set_socket_options(s,user_socket_options);
- if (listen(s, 5) == -1) {
+ /* Set server socket to non-blocking for the accept. */
+ set_blocking(s,False);
+
+ if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
DEBUG(0,("open_sockets_smbd: listen: %s\n",
strerror(errno)));
close(s);
continue;
}
+ /* Ensure child is set to blocking mode */
+ set_blocking(smbd_server_fd(),True);
+
if (smbd_server_fd() != -1 && interactive)
return True;
/* this is needed so that we get decent entries
in smbstatus for port 445 connects */
- set_remote_machine_name(get_socket_addr(smbd_server_fd()), False);
+ set_remote_machine_name(get_peer_addr(smbd_server_fd()), False);
- /* Reset global variables in util.c so
- that client substitutions will be
- done correctly in the process. */
- reset_globals_after_fork();
+ /* Reset the state of the random
+ * number generation system, so
+ * children do not get the same random
+ * numbers as each other */
- /* tdb needs special fork handling */
+ set_need_random_reseed();
+ /* tdb needs special fork handling - remove CLEAR_IF_FIRST flags */
if (tdb_reopen_all() == -1) {
DEBUG(0,("tdb_reopen_all failed.\n"));
- return False;
+ smb_panic("tdb_reopen_all failed.");
}
return True;
return(True);
lp_killunused(conn_snum_used);
-
+
ret = lp_load(dyn_CONFIGFILE, False, False, True);
+ remove_stale_printers();
load_printers();
/* perhaps the config filename is now set */
load_interfaces();
- {
- if (smbd_server_fd() != -1) {
- set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
- set_socket_options(smbd_server_fd(), user_socket_options);
- }
+ if (smbd_server_fd() != -1) {
+ set_socket_options(smbd_server_fd(),"SO_KEEPALIVE");
+ set_socket_options(smbd_server_fd(), user_socket_options);
}
mangle_reset_cache();
reset_stat_cache();
/* this forces service parameters to be flushed */
- set_current_service(NULL,True);
+ set_current_service(NULL,0,True);
return(ret);
}
-/*******************************************************************
- Print out all talloc memory info.
-********************************************************************/
-
-void return_all_talloc_info(int msg_type, pid_t src_pid, void *buf, size_t len)
-{
- TALLOC_CTX *ctx = talloc_init("info context");
- char *info = NULL;
-
- if (!ctx)
- return;
-
- info = talloc_describe_all(ctx);
- if (info)
- DEBUG(10,(info));
- message_send_pid(src_pid, MSG_TALLOC_USAGE, info, info ? strlen(info) + 1 : 0, True);
- talloc_destroy(ctx);
-}
#if DUMP_CORE
/*******************************************************************
DEBUG(0,("Dumping core in %s\n", dname));
+ /* Ensure we don't have a signal handler for abort. */
+#ifdef SIGABRT
+ CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
+#endif
abort();
return(True);
}
print_notify_send_messages(3); /* 3 second timeout. */
+ /* run all registered exit events */
+ smb_run_exit_events();
+
/* delete our entry in the connections database. */
yield_connection(NULL,"");
main program.
****************************************************************************/
+/* Declare prototype for build_options() to avoid having to run it through
+ mkproto.h. Mixing $(builddir) and $(srcdir) source files in the current
+ prototype generation system is too complicated. */
+
+void build_options(BOOL screen);
+
int main(int argc,const char *argv[])
{
/* shall I run as a daemon */
/* we want to re-seed early to prevent time delays causing
client problems at a later date. (tridge) */
- generate_random_buffer(NULL, 0, False);
+ generate_random_buffer(NULL, 0);
/* make absolutely sure we run as root - to handle cases where people
are crazy enough to have it setuid */
reopen_logs();
- DEBUG(0,( "smbd version %s started.\n", VERSION));
- DEBUGADD(0,( "Copyright Andrew Tridgell and the Samba Team 1992-2003\n"));
+ DEBUG(0,( "smbd version %s started.\n", SAMBA_VERSION_STRING));
+ DEBUGADD(0,( "Copyright Andrew Tridgell and the Samba Team 1992-2004\n"));
DEBUG(2,("uid=%d gid=%d euid=%d egid=%d\n",
(int)getuid(),(int)getgid(),(int)geteuid(),(int)getegid()));
init_structs();
+ if (!init_guest_info())
+ return -1;
+
#ifdef WITH_PROFILE
if (!profile_setup(False)) {
DEBUG(0,("ERROR: failed to setup profiling\n"));
if (is_daemon)
pidfile_create("smbd");
+ /* Setup all the TDB's - including CLEAR_IF_FIRST tdb's. */
if (!message_init())
exit(1);
- register_msg_pool_usage();
- register_dmalloc_msgs();
- message_register(MSG_REQ_TALLOC_USAGE, return_all_talloc_info);
+ if (!session_init())
+ exit(1);
+
+ if (conn_tdb_ctx() == NULL)
+ exit(1);
+
+ if (!locking_init(0))
+ exit(1);
+
+ if (!share_info_db_init())
+ exit(1);
+
+ namecache_enable();
+
+ if (!init_registry())
+ exit(1);
if (!print_backend_init())
exit(1);
/* Setup the main smbd so that we can get messages. */
+ /* don't worry about general printing messages here */
+
claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
- /*
- DO NOT ENABLE THIS TILL YOU COPE WITH KILLING THESE TASKS AND INETD
- THIS *killed* LOTS OF BUILD FARM MACHINES. IT CREATED HUNDREDS OF
- smbd PROCESSES THAT NEVER DIE
- start_background_queue();
- */
+ /* 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
+ ourselves here */
+
+ if ( is_daemon )
+ start_background_queue();
if (!open_sockets_smbd(is_daemon, interactive, ports))
exit(1);
* everything after this point is run after the fork()
*/
- namecache_enable();
-
- if (!locking_init(0))
- exit(1);
-
- if (!share_info_db_init())
- exit(1);
+ /* Initialise the password backed before the global_sam_sid
+ to ensure that we fetch from ldap before we make a domain sid up */
- if (!init_registry())
+ if(!initialize_password_db(False))
exit(1);
- if(!initialize_password_db(False))
+ if(!get_global_sam_sid()) {
+ DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
exit(1);
+ }
static_init_rpc;
init_modules();
- uni_group_cache_init(); /* Non-critical */
-
/* possibly reload the services file. */
reload_services(True);
- if(!get_global_sam_sid()) {
- DEBUG(0,("ERROR: Samba cannot create a SAM SID.\n"));
- exit(1);
- }
-
if (!init_account_policy()) {
DEBUG(0,("Could not open account policy tdb.\n"));
exit(1);
if (!init_change_notify())
exit(1);
- /* Setup privileges database */
- if (!privilege_init())
- exit(1);
-
/* re-initialise the timezone */
TimeInit();
smbd_process();
- uni_group_cache_shutdown();
namecache_shutdown();
+
+ if (interactive) {
+ TALLOC_CTX *mem_ctx = talloc_init("end_description");
+ char *description = talloc_describe_all(mem_ctx);
+
+ DEBUG(3, ("tallocs left:\n%s\n", description));
+ talloc_destroy(mem_ctx);
+ }
+
exit_server("normal exit");
return(0);
}