r21869: Move sending keepalives out of the main processing loop into idle event.
authorVolker Lendecke <vlendec@samba.org>
Sun, 18 Mar 2007 10:57:46 +0000 (10:57 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:18:41 +0000 (12:18 -0500)
On the way, make lp_keepalive() a proper parameter.

Volker

source/param/loadparm.c
source/smbd/process.c
source/smbd/server.c

index 13455101d865429f918d716407335c4758586b77..6d2ba9377de5bbbf63896a1c09c5c8eeb5ad7a37 100644 (file)
@@ -79,7 +79,6 @@ extern userdom_struct current_user_info;
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-int keepalive = DEFAULT_KEEPALIVE;
 BOOL use_getwd_cache = True;
 
 extern int extra_time_offset;
@@ -315,6 +314,7 @@ typedef struct {
        int iIdmapNegativeTime;
 
        BOOL bResetOnZeroVC;
+       int iKeepalive;
        param_opt_struct *param_opt;
 } global;
 
@@ -1008,7 +1008,7 @@ static struct parm_struct parm_table[] = {
        {"block size", P_INTEGER, P_LOCAL, &sDefault.iBlock_size, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
        {"deadtime", P_INTEGER, P_GLOBAL, &Globals.deadtime, NULL, NULL, FLAG_ADVANCED}, 
        {"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, 
-       {"keepalive", P_INTEGER, P_GLOBAL, &keepalive, NULL, NULL, FLAG_ADVANCED}, 
+       {"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED}, 
        {"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
        {"kernel change notify", P_BOOL, P_LOCAL, &sDefault.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
 
@@ -1666,6 +1666,8 @@ static void init_globals(BOOL first_time_only)
        /* By default disallow guest access to usershares. */
        Globals.bUsershareAllowGuests = False;
 
+       Globals.iKeepalive = DEFAULT_KEEPALIVE;
+
        /* By default no shares out of the registry */
        Globals.bRegistryShares = False;
 }
@@ -1903,6 +1905,7 @@ FN_GLOBAL_LIST(lp_idmap_backend, &Globals.szIdmapBackend) /* deprecated */
 FN_GLOBAL_STRING(lp_idmap_alloc_backend, &Globals.szIdmapAllocBackend)
 FN_GLOBAL_INTEGER(lp_idmap_expire_time, &Globals.iIdmapExpireTime)
 FN_GLOBAL_INTEGER(lp_idmap_negative_time, &Globals.iIdmapNegativeTime)
+FN_GLOBAL_INTEGER(lp_keepalive, &Globals.iKeepalive)
 FN_GLOBAL_BOOL(lp_passdb_expand_explicit, &Globals.bPassdbExpandExplicit)
 
 FN_GLOBAL_STRING(lp_ldap_suffix, &Globals.szLdapSuffix)
index 83072817a381d3a973225ac428eb9c294f93b0c9..5edb2c100945cdc3a9ee824da5decde53e36b744 100644 (file)
@@ -22,7 +22,6 @@
 #include "includes.h"
 
 uint16 global_smbpid;
-extern int keepalive;
 extern struct auth_context *negprot_global_auth_context;
 extern int smb_echo_count;
 
@@ -221,6 +220,7 @@ BOOL push_deferred_smb_message(uint16 mid,
 struct idle_event {
        struct timed_event *te;
        struct timeval interval;
+       char *name;
        BOOL (*handler)(const struct timeval *now, void *private_data);
        void *private_data;
 };
@@ -241,17 +241,19 @@ static void idle_event_handler(struct event_context *ctx,
                return;
        }
 
-       event->te = event_add_timed(smbd_event_context(), event,
+       event->te = event_add_timed(ctx, event,
                                    timeval_sum(now, &event->interval),
-                                   "idle_event_handler",
+                                   event->name,
                                    idle_event_handler, event);
 
        /* We can't do much but fail here. */
        SMB_ASSERT(event->te != NULL);
 }
 
-struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx,
+struct idle_event *event_add_idle(struct event_context *event_ctx,
+                                 TALLOC_CTX *mem_ctx,
                                  struct timeval interval,
+                                 const char *name,
                                  BOOL (*handler)(const struct timeval *now,
                                                  void *private_data),
                                  void *private_data)
@@ -269,9 +271,15 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx,
        result->handler = handler;
        result->private_data = private_data;
 
-       result->te = event_add_timed(smbd_event_context(), result,
+       if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
+               DEBUG(0, ("talloc failed\n"));
+               TALLOC_FREE(result);
+               return NULL;
+       }
+
+       result->te = event_add_timed(event_ctx, result,
                                     timeval_sum(&now, &interval),
-                                    "idle_event_handler",
+                                    result->name,
                                     idle_event_handler, result);
        if (result->te == NULL) {
                DEBUG(0, ("event_add_timed failed\n"));
@@ -1363,12 +1371,7 @@ static BOOL timeout_processing(int *select_timeout,
                last_idle_closed_check = t;
        }
 
-       if (keepalive && (t - last_keepalive_sent_time)>keepalive) {
-               if (!send_keepalive(smbd_server_fd())) {
-                       DEBUG( 2, ( "Keepalive failed - exiting.\n" ) );
-                       return False;
-               }
-
+       if (lp_keepalive() && (t - last_keepalive_sent_time)> lp_keepalive()) {
                /* send a keepalive for a password server or the like.
                        This is attached to the auth_info created in the
                negprot */
index 0ae2f3e836f09bd087d14a59b9af533660f20537..0d4953e5b80a026e8d4b80e8aa0edcef33f5f766 100644 (file)
@@ -814,6 +814,18 @@ static BOOL init_structs(void )
        return True;
 }
 
+/*
+ * Send keepalive packets to our client
+ */
+static BOOL keepalive_fn(const struct timeval *now, void *private_data)
+{
+       if (!send_keepalive(smbd_server_fd())) {
+               DEBUG( 2, ( "Keepalive failed - exiting.\n" ) );
+               return False;
+       }
+       return True;
+}
+
 /****************************************************************************
  main program.
 ****************************************************************************/
@@ -1107,6 +1119,20 @@ extern void build_options(BOOL screen);
        /* register our message handlers */
        message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL);
 
+       if (lp_keepalive() != 0) {
+               struct timeval interval;
+
+               interval.tv_sec = lp_keepalive();
+               interval.tv_usec = 0;
+
+               if (!(event_add_idle(smbd_event_context(), NULL,
+                                    interval, "keepalive", keepalive_fn,
+                                    NULL))) {
+                       DEBUG(0, ("Could not add keepalive event\n"));
+                       exit(1);
+               }
+       }
+
        smbd_process();
 
        namecache_shutdown();