- changed the default nmbd loop timout to 10 seconds (2 seconds was much
authorAndrew Tridgell <tridge@samba.org>
Mon, 7 Oct 1996 01:56:21 +0000 (01:56 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 7 Oct 1996 01:56:21 +0000 (01:56 +0000)
too short)

- got rid of many unnecessary calls to time(NULL) in nmbd. They were
causing it to chew too much CPU time when idle. Now we pass a time
value in from the top level.

source/include/local.h
source/include/proto.h
source/nameannounce.c
source/namebrowse.c
source/namedbsubnet.c
source/nameelect.c
source/nameresp.c
source/nameserv.c
source/nmbd/nmbd.c

index 115617094c4881bd26d84209db802c3925ab17d7..465e0029b6ae7dba89512f176a50a008bd3fb7c6 100644 (file)
 #define IDLE_CLOSED_TIMEOUT (60)
 #define DPTR_IDLE_TIMEOUT (120)
 #define SMBD_SELECT_LOOP (10)
-#define NMBD_SELECT_LOOP (2)
+#define NMBD_SELECT_LOOP (10)
 #define BROWSE_INTERVAL (60)
 #define REGISTRATION_INTERVAL (10*60)
 #define NMBD_INETD_TIMEOUT (120)
index 8c082a6140b69954eb2e3058591e2f4314aec21e..2c6047954ec55001d3d4032302601412b2a67ce0 100644 (file)
@@ -306,16 +306,16 @@ void do_announce_host(int command,
 void remove_my_servers(void);
 void announce_server(struct subnet_record *d, struct work_record *work,
                     char *name, char *comment, time_t ttl, int server_type);
-void announce_host(void);
-void announce_master(void);
-void announce_remote(void);
+void announce_host(time_t t);
+void announce_master(time_t t);
+void announce_remote(time_t t);
 
 /*The following definitions come from  namebrowse.c  */
 
 void expire_browse_cache(time_t t);
 struct browse_cache_record *add_browser_entry(char *name, int type, char *wg,
                                              time_t ttl, struct in_addr ip, BOOL local);
-void do_browser_lists(void);
+void do_browser_lists(time_t t);
 
 /*The following definitions come from  nameconf.c  */
 
@@ -354,7 +354,7 @@ struct name_record *add_netbios_entry(struct subnet_record *d,
                BOOL new_only,BOOL wins);
 void expire_names(time_t t);
 struct name_record *search_for_name(struct subnet_record **d,
-                                       struct nmb_name *question,
+                                   struct nmb_name *question,
                                    struct in_addr ip, int Time, int search);
 
 /*The following definitions come from  namedbresp.c  */
@@ -393,7 +393,7 @@ void add_my_subnets(char *group);
 struct subnet_record *add_subnet_entry(struct in_addr bcast_ip, 
                                       struct in_addr mask_ip,
                                       char *name, BOOL add, BOOL lmhosts);
-void write_browse_list(void);
+void write_browse_list(time_t t);
 
 /*The following definitions come from  namedbwork.c  */
 
@@ -406,7 +406,7 @@ void dump_workgroups(void);
 
 /*The following definitions come from  nameelect.c  */
 
-void check_master_browser(void);
+void check_master_browser(time_t t);
 void browser_gone(char *work_name, struct in_addr ip);
 void send_election(struct subnet_record *d, char *group,uint32 criterion,
                   int timeup,char *name);
@@ -416,7 +416,7 @@ void name_register_work(struct subnet_record *d, char *name, int name_type,
 void become_master(struct subnet_record *d, struct work_record *work);
 void become_nonmaster(struct subnet_record *d, struct work_record *work,
                                int remove_type);
-void run_elections(void);
+void run_elections(time_t t);
 void process_election(struct packet_struct *p,char *buf);
 BOOL check_elections(void);
 
@@ -453,7 +453,7 @@ BOOL name_query(int fd,char *name,int name_type,
 
 /*The following definitions come from  nameresp.c  */
 
-void expire_netbios_response_entries();
+void expire_netbios_response_entries(time_t t);
 struct response_record *queue_netbios_pkt_wins(struct subnet_record *d,
                                int fd,int quest_type,enum state_type state,
                            char *name,int name_type,int nb_flags, time_t ttl,
@@ -474,7 +474,7 @@ void add_my_name_entry(struct subnet_record *d,char *name,int type,int nb_flags)
 void add_my_names(void);
 void remove_my_names();
 void refresh_my_names(time_t t);
-void query_refresh_names(void);
+void query_refresh_names(time_t t);
 
 /*The following definitions come from  nameservreply.c  */
 
index fec88955108d47116b576ba2873f68c3494d7c0e..1dadc0132c193502d2603fe063c60781ae78480f 100644 (file)
@@ -292,9 +292,8 @@ void announce_server(struct subnet_record *d, struct work_record *work,
 /****************************************************************************
   construct a host announcement unicast
   **************************************************************************/
-void announce_host(void)
+void announce_host(time_t t)
 {
-  time_t t = time(NULL);
   struct subnet_record *d;
   pstring comment;
   char *my_name;
@@ -368,11 +367,10 @@ void announce_host(void)
   NAME_QUERY_DOM_SRV_CHK command, if there is a response from the
   name query initiated here.  see response_name_query()
   **************************************************************************/
-void announce_master(void)
+void announce_master(time_t t)
 {
   struct subnet_record *d;
   static time_t last=0;
-  time_t t = time(NULL);
   BOOL am_master = False; /* are we a master of some sort? :-) */
 
   if (!last) last = t;
@@ -477,11 +475,10 @@ void announce_master(void)
   on a remote browse list. They are done blind, no checking is done to
   see if there is actually a browse master at the other end.
   **************************************************************************/
-void announce_remote(void)
+void announce_remote(time_t t)
 {
   char *s,*ptr;
   static time_t last_time = 0;
-  time_t t = time(NULL);
   pstring s2;
   struct in_addr addr;
   char *comment,*workgroup;
index b426bc7a15005404137016c35ab6664a5b1e37d1..3bc4f9f82aa1f66b103c5f2a2bbc759fe09b28e4 100644 (file)
@@ -190,11 +190,10 @@ static void start_sync_browse_entry(struct browse_cache_record *b)
 /****************************************************************************
   search through browser list for an entry to sync with
   **************************************************************************/
-void do_browser_lists(void)
+void do_browser_lists(time_t t)
 {
   struct browse_cache_record *b;
   static time_t last = 0;
-  time_t t = time(NULL);
   
   if (t-last < 20) return; /* don't do too many of these at once! */
                            /* XXXX equally this period should not be too long
index 0bad79246ad7a968a590080c651f01e3a0492cff..16eeb6322ebc3001f9b2a4dc6683e3086f5725e0 100644 (file)
@@ -252,14 +252,13 @@ struct subnet_record *add_subnet_entry(struct in_addr bcast_ip,
 /*******************************************************************
   write out browse.dat
   ******************************************************************/
-void write_browse_list(void)
+void write_browse_list(time_t t)
 {
   struct subnet_record *d;
   pstring fname,fnamenew;
   FILE *f;
 
   static time_t lasttime = 0;
-  time_t t = time(NULL);
 
   if (!lasttime) lasttime = t;
   if (!updatedlists || t - lasttime < 5) return;
index be8a405daac1820cc09cdeb07c4e332ef147d6f8..1c4f8e63900728b2d80c248fa527338e5d7be65a 100644 (file)
@@ -54,10 +54,9 @@ extern uint16 nb_type; /* samba's NetBIOS name type */
 /*******************************************************************
   occasionally check to see if the master browser is around
   ******************************************************************/
-void check_master_browser(void)
+void check_master_browser(time_t t)
 {
   static time_t lastrun=0;
-  time_t t = time(NULL);
   struct subnet_record *d;
 
   if (!lastrun) lastrun = t;
@@ -474,9 +473,8 @@ void become_nonmaster(struct subnet_record *d, struct work_record *work,
 /*******************************************************************
   run the election
   ******************************************************************/
-void run_elections(void)
+void run_elections(time_t t)
 {
-  time_t t = time(NULL);
   static time_t lastime = 0;
   
   struct subnet_record *d;
index 7fcb41e79f0623738d80b0e65018315b764910e0..2a8c5e88b04ab770c230fbaaaaca73184ddb3955 100644 (file)
@@ -174,7 +174,7 @@ static void dead_netbios_entry(struct subnet_record *d,
        see name_query() and name_status() for suggested implementation.
 
   ******************************************************************/
-void expire_netbios_response_entries()
+void expire_netbios_response_entries(time_t t)
 {
   struct subnet_record *d;
 
@@ -186,7 +186,7 @@ void expire_netbios_response_entries()
     {
          nextn = n->next;
 
-      if (n->repeat_time <= time(NULL))
+      if (n->repeat_time <= t)
          {
                  if (n->repeat_count > 0)
                  {
index c8bbb52811636540adf78bde5eb0d82a9accda47..7353251940c11abddd88f76618a577c51b63ac46 100644 (file)
@@ -240,7 +240,7 @@ void refresh_my_names(time_t t)
        for (n = d->namelist; n; n = n->next)
     {
       /* each SELF name has an individual time to be refreshed */
-      if (n->source == SELF && n->refresh_time < time(NULL) && 
+      if (n->source == SELF && n->refresh_time < t && 
           n->death_time != 0)
       {
         add_my_name_entry(d,n->name.name,n->name.name_type,
@@ -263,13 +263,12 @@ void refresh_my_names(time_t t)
 
   XXXX which names to poll and which not can be refined at a later date.
   ******************************************************************/
-void query_refresh_names(void)
+void query_refresh_names(time_t t)
 {
        struct name_record *n;
        struct subnet_record *d = find_subnet(ipgrp);
 
        static time_t lasttime = 0;
-       time_t t = time(NULL);
 
        int count = 0;
        int name_refresh_time = NAME_POLL_REFRESH_TIME;
index 5b3fd19491de9a013fb639778ccdc2d2d1cdf6e8..d8865662c7286dcb68fe3bf4c4dfa17d9830d15a 100644 (file)
@@ -159,10 +159,9 @@ static void fault_continue(void)
 /*******************************************************************
   expire old names from the namelist and server list
   ******************************************************************/
-static void expire_names_and_servers(void)
+static void expire_names_and_servers(time_t t)
 {
   static time_t lastrun = 0;
-  time_t t = time(NULL);
   
   if (!lastrun) lastrun = t;
   if (t < lastrun + 5) return;
@@ -298,23 +297,23 @@ static void process(void)
       listen_for_packets(run_election);
 
       run_packet_queue();
-      run_elections();
+      run_elections(t);
 
-      announce_host();
+      announce_host(t);
 
-      announce_master();
+      announce_master(t);
 
-      announce_remote();
+      announce_remote(t);
 
-      query_refresh_names();
+      query_refresh_names(t);
 
-      expire_names_and_servers();
-      expire_netbios_response_entries();
+      expire_names_and_servers(t);
+      expire_netbios_response_entries(t);
       refresh_my_names(t);
 
-      write_browse_list();
-      do_browser_lists();
-      check_master_browser();
+      write_browse_list(t);
+      do_browser_lists(t);
+      check_master_browser(t);
     }
 }
 
@@ -528,7 +527,7 @@ static void usage(char *pname)
 
   DEBUG(3,("Loaded names\n"));
 
-  write_browse_list();
+  write_browse_list(time(NULL));
 
   DEBUG(3,("Dumped names\n"));