s3: nmbd: Fix strict overflow checking compiler warning.
[samba.git] / source3 / nmbd / nmbd.c
index fd222c25c16e5d61b64b9115bde15873bd7750a4..9be708a9c0293203f75e0f4199635ef0cee0ceeb 100644 (file)
@@ -70,7 +70,6 @@ static void terminate(struct messaging_context *msg)
        kill_async_dns_child();
 
        gencache_stabilize();
-       serverid_deregister(messaging_server_id(msg));
 
        pidfile_unlink(lp_pid_directory(), "nmbd");
 
@@ -396,7 +395,7 @@ static bool reload_nmbd_services(bool test)
        set_remote_machine_name("nmbd", False);
 
        if ( lp_loaded() ) {
-               char *fname = lp_configfile(talloc_tos());
+               char *fname = lp_next_configfile(talloc_tos());
                if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) {
                        set_dyn_CONFIGFILE(fname);
                        test = False;
@@ -415,6 +414,8 @@ static bool reload_nmbd_services(bool test)
                reload_nmbd_services( True );
        }
 
+       reopen_logs();
+
        return(ret);
 }
 
@@ -817,7 +818,7 @@ static bool open_sockets(bool isdaemon, int port)
 
        setup_logging(argv[0], DEBUG_DEFAULT_STDOUT);
 
-       load_case_tables();
+       smb_init_locale();
 
        global_nmb_port = NMB_PORT;
 
@@ -882,6 +883,9 @@ static bool open_sockets(bool isdaemon, int port)
        BlockSignals(True, SIGUSR2);
 #endif
 
+       /* Ignore children - no zombies. */
+       CatchChild();
+
        if ( opt_interactive ) {
                Fork = False;
                log_stdout = True;
@@ -908,6 +912,8 @@ static bool open_sockets(bool isdaemon, int port)
                exit(1);
        }
 
+       reopen_logs();
+
        if (lp_server_role() == ROLE_ACTIVE_DIRECTORY_DC
            && !lp_parm_bool(-1, "server role check", "inhibit", false)) {
                /* TODO: when we have a merged set of defaults for
@@ -943,12 +949,12 @@ static bool open_sockets(bool isdaemon, int port)
        set_samba_nb_type();
 
        if (!is_daemon && !is_a_socket(0)) {
-               DEBUG(0,("standard input is not a socket, assuming -D option\n"));
+               DEBUG(3, ("standard input is not a socket, assuming -D option\n"));
                is_daemon = True;
        }
 
        if (is_daemon && !opt_interactive) {
-               DEBUG( 2, ( "Becoming a daemon.\n" ) );
+               DEBUG(3, ("Becoming a daemon.\n"));
                become_daemon(Fork, no_process_group, log_stdout);
        }
 
@@ -969,28 +975,22 @@ static bool open_sockets(bool isdaemon, int port)
        }
 #endif
 
-       ok = directory_create_or_exist(lp_lock_directory(), geteuid(), 0755);
+       ok = directory_create_or_exist(lp_lock_directory(), 0755);
        if (!ok) {
-               DEBUG(0, ("Failed to create directory %s for lock files - %s\n",
-                         lp_lock_directory(), strerror(errno)));
-               exit(1);
+               exit_daemon("Failed to create directory for lock files, check 'lock directory'", errno);
        }
 
-       ok = directory_create_or_exist(lp_pid_directory(), geteuid(), 0755);
+       ok = directory_create_or_exist(lp_pid_directory(), 0755);
        if (!ok) {
-               DEBUG(0, ("Failed to create directory %s for pid files - %s\n",
-                         lp_pid_directory(), strerror(errno)));
-               exit(1);
+               exit_daemon("Failed to create directory for pid files, check 'pid directory'", errno);
        }
 
        pidfile_create(lp_pid_directory(), "nmbd");
 
-       status = reinit_after_fork(msg, nmbd_event_context(),
-                                  false);
+       status = reinit_after_fork(msg, nmbd_event_context(), false, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0,("reinit_after_fork() failed\n"));
-               exit(1);
+               exit_daemon("reinit_after_fork() failed", map_errno_from_nt_status(status));
        }
 
        /*
@@ -1000,24 +1000,17 @@ static bool open_sockets(bool isdaemon, int port)
         */
        status = init_before_fork();
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("init_before_fork failed: %s\n", nt_errstr(status)));
-               exit(1);
+               exit_daemon(nt_errstr(status), map_errno_from_nt_status(status));
        }
 
        if (!nmbd_setup_sig_term_handler(msg))
-               exit(1);
+               exit_daemon("NMBD failed to setup signal handler", EINVAL);
        if (!nmbd_setup_stdin_handler(msg, !Fork))
-               exit(1);
+               exit_daemon("NMBD failed to setup stdin handler", EINVAL);
        if (!nmbd_setup_sig_hup_handler(msg))
-               exit(1);
-
-       /* get broadcast messages */
+               exit_daemon("NMBD failed to setup SIGHUP handler", EINVAL);
 
-       if (!serverid_register(messaging_server_id(msg),
-                               FLAG_MSG_GENERAL |
-                               FLAG_MSG_NMBD |
-                               FLAG_MSG_DBWRAP)) {
-               DEBUG(1, ("Could not register myself in serverid.tdb\n"));
+       if (!messaging_parent_dgm_cleanup_init(msg)) {
                exit(1);
        }
 
@@ -1049,9 +1042,8 @@ static bool open_sockets(bool isdaemon, int port)
 
        /* Create an nmbd subnet record for each of the above. */
        if( False == create_subnets() ) {
-               DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n"));
                kill_async_dns_child();
-               exit(1);
+               exit_daemon("NMBD failed when creating subnet lists", EACCES);
        }
 
        /* Load in any static local names. */ 
@@ -1063,9 +1055,8 @@ static bool open_sockets(bool isdaemon, int port)
 
        /* If we are acting as a WINS server, initialise data structures. */
        if( !initialise_wins() ) {
-               DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) );
                kill_async_dns_child();
-               exit(1);
+               exit_daemon( "NMBD failed when initialising WINS server.", EACCES);
        }
 
        /* 
@@ -1077,21 +1068,23 @@ static bool open_sockets(bool isdaemon, int port)
         */
 
        if( False == register_my_workgroup_and_names() ) {
-               DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n"));
                kill_async_dns_child();
-               exit(1);
+               exit_daemon( "NMBD failed when creating my workgroup.", EACCES);
        }
 
        if (!initialize_nmbd_proxy_logon()) {
-               DEBUG(0,("ERROR: Failed setup nmbd_proxy_logon.\n"));
                kill_async_dns_child();
-               exit(1);
+               exit_daemon( "NMBD failed to setup nmbd_proxy_logon.", EACCES);
        }
 
        if (!nmbd_init_packet_server()) {
                kill_async_dns_child();
-                exit(1);
-        }
+               exit_daemon( "NMBD failed to setup packet server.", EACCES);
+       }
+
+       if (is_daemon && !opt_interactive) {
+               daemon_ready("nmbd");
+       }
 
        TALLOC_FREE(frame);
        process(msg);