diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/param/loadparm.c | 7 | ||||
-rw-r--r-- | source3/smbd/process.c | 27 | ||||
-rw-r--r-- | source3/smbd/server.c | 26 |
3 files changed, 46 insertions, 14 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 13455101d8..6d2ba9377d 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -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) diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 83072817a3..5edb2c1009 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -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 */ diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 0ae2f3e836..0d4953e5b8 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -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(); |