s3: Make nmbd_messaging_context static
[garming/samba-autobuild/.git] / source3 / nmbd / nmbd.c
index 2ed421246f92bd00d1a0eb6e5c02e94adef46a00..63a5681e9d3db9a24f0e6a7457d5144102e3a0f9 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "popt_common.h"
-#include "librpc/gen_ndr/messaging.h"
 #include "nmbd/nmbd.h"
+#include "serverid.h"
+#include "messages.h"
 
 int ClientNMB       = -1;
 int ClientDGRAM     = -1;
@@ -45,7 +47,7 @@ struct event_context *nmbd_event_context(void)
        return server_event_context();
 }
 
-struct messaging_context *nmbd_messaging_context(void)
+static struct messaging_context *nmbd_messaging_context(void)
 {
        struct messaging_context *msg_ctx = server_messaging_context();
        if (likely(msg_ctx != NULL)) {
@@ -62,13 +64,13 @@ struct messaging_context *nmbd_messaging_context(void)
 static void terminate(void)
 {
        DEBUG(0,("Got SIGTERM: going down...\n"));
-  
+
        /* Write out wins.dat file if samba is a WINS server */
        wins_write_database(0,False);
-  
+
        /* Remove all SELF registered names from WINS */
        release_wins_names();
-  
+
        /* Announce all server entries as 0 time-to-live, 0 type. */
        announce_my_servers_removed();
 
@@ -159,15 +161,6 @@ static void nmbd_terminate(struct messaging_context *msg,
        terminate();
 }
 
-/**************************************************************************** **
- Possibly continue after a fault.
- **************************************************************************** */
-
-static void fault_continue(void)
-{
-       dump_core();
-}
-
 /**************************************************************************** **
  Expire old names from the namelist and server list.
  **************************************************************************** */
@@ -175,7 +168,7 @@ static void fault_continue(void)
 static void expire_names_and_servers(time_t t)
 {
        static time_t lastrun = 0;
-  
+
        if ( !lastrun )
                lastrun = t;
        if ( t < (lastrun + 5) )
@@ -247,8 +240,8 @@ static void reload_interfaces(time_t t)
                        continue;
                }
 
-               ip = ((struct sockaddr_in *)(void *)&iface->ip)->sin_addr;
-               nmask = ((struct sockaddr_in *)(void *)
+               ip = ((const struct sockaddr_in *)(const void *)&iface->ip)->sin_addr;
+               nmask = ((const struct sockaddr_in *)(const void *)
                         &iface->netmask)->sin_addr;
 
                /*
@@ -257,7 +250,7 @@ static void reload_interfaces(time_t t)
                 * ignore it here. JRA.
                 */
 
-               if (is_loopback_addr((struct sockaddr *)(void *)&iface->ip)) {
+               if (is_loopback_addr((const struct sockaddr *)(const void *)&iface->ip)) {
                        DEBUG(2,("reload_interfaces: Ignoring loopback "
                                "interface %s\n",
                                print_sockaddr(str, sizeof(str), &iface->ip) ));
@@ -373,7 +366,7 @@ static bool reload_nmbd_services(bool test)
        if ( test && !lp_file_list_changed() )
                return(True);
 
-       ret = lp_load(get_dyn_CONFIGFILE(), True , False, False, True);
+       ret = lp_load_global(get_dyn_CONFIGFILE());
 
        /* perhaps the config filename is now set */
        if ( !test ) {
@@ -487,7 +480,8 @@ static void process(void)
                 * (nmbd_packets.c)
                 */
 
-               if(listen_for_packets(run_election)) {
+               if (listen_for_packets(nmbd_messaging_context(),
+                                      run_election)) {
                        TALLOC_FREE(frame);
                        return;
                }
@@ -773,6 +767,8 @@ static bool open_sockets(bool isdaemon, int port)
        talloc_enable_null_tracking();
        frame = talloc_stackframe();
 
+       setup_logging(argv[0], DEBUG_DEFAULT_STDOUT);
+
        load_case_tables();
 
        global_nmb_port = NMB_PORT;
@@ -805,11 +801,11 @@ static bool open_sockets(bool isdaemon, int port)
        poptFreeContext(pc);
 
        global_in_nmbd = true;
-       
+
        StartupTime = time(NULL);
-       
+
        sys_srandom(time(NULL) ^ sys_getpid());
-       
+
        if (!override_logfile) {
                char *lfile = NULL;
                if (asprintf(&lfile, "%s/log.nmbd", get_dyn_LOGFILEBASE()) < 0) {
@@ -818,10 +814,10 @@ static bool open_sockets(bool isdaemon, int port)
                lp_set_logfile(lfile);
                SAFE_FREE(lfile);
        }
-       
-       fault_setup((void (*)(void *))fault_continue );
-       dump_core_setup("nmbd");
-       
+
+       fault_setup();
+       dump_core_setup("nmbd", lp_logfile());
+
        /* POSIX demands that signals are inherited. If the invoking process has
         * these signals masked, we will have problems, as we won't receive them. */
        BlockSignals(False, SIGHUP);
@@ -847,8 +843,9 @@ static bool open_sockets(bool isdaemon, int port)
                DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n"));
                exit(1);
        }
+
        if (log_stdout) {
-               setup_logging( argv[0], DEBUG_STDOUT);
+               setup_logging(argv[0], DEBUG_STDOUT);
        } else {
                setup_logging( argv[0], DEBUG_FILE);
        }
@@ -859,7 +856,7 @@ static bool open_sockets(bool isdaemon, int port)
        DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE));
 
        if (!lp_load_initial_only(get_dyn_CONFIGFILE())) {
-               DEBUG(0, ("error opening config file\n"));
+               DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE()));
                exit(1);
        }
 
@@ -886,7 +883,7 @@ static bool open_sockets(bool isdaemon, int port)
                DEBUG(0,("standard input is not a socket, assuming -D option\n"));
                is_daemon = True;
        }
-  
+
        if (is_daemon && !opt_interactive) {
                DEBUG( 2, ( "Becoming a daemon.\n" ) );
                become_daemon(Fork, no_process_group, log_stdout);
@@ -909,7 +906,7 @@ static bool open_sockets(bool isdaemon, int port)
        /* Setup the async dns. We do it here so it doesn't have all the other
                stuff initialised and thus chewing memory and sockets */
        if(lp_we_are_a_wins_server() && lp_dns_proxy()) {
-               start_async_dns();
+               start_async_dns(nmbd_messaging_context());
        }
 #endif
 
@@ -921,7 +918,7 @@ static bool open_sockets(bool isdaemon, int port)
 
        status = reinit_after_fork(nmbd_messaging_context(),
                                   nmbd_event_context(),
-                                  procid_self(), false);
+                                  false);
 
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
@@ -936,7 +933,9 @@ static bool open_sockets(bool isdaemon, int port)
        /* get broadcast messages */
 
        if (!serverid_register(procid_self(),
-                              FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP)) {
+                               FLAG_MSG_GENERAL |
+                               FLAG_MSG_NMBD |
+                               FLAG_MSG_DBWRAP)) {
                DEBUG(1, ("Could not register myself in serverid.tdb\n"));
                exit(1);
        }