[dovecot-cvs]
dovecot/src/auth auth-cache.c, 1.11, 1.12 main.c, 1.46, 1.47
cras at dovecot.org
cras at dovecot.org
Sun Sep 25 14:07:34 EEST 2005
Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv8918/auth
Modified Files:
auth-cache.c main.c
Log Message:
Implemented new signal handling framework, which makes handling signals much
easier.
Index: auth-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- auth-cache.c 8 Jun 2005 15:45:41 -0000 1.11
+++ auth-cache.c 25 Sep 2005 11:07:32 -0000 1.12
@@ -24,7 +24,6 @@
size_t size_left;
unsigned int ttl_secs;
- unsigned int hup_count, usr2_count;
unsigned int hit_count, miss_count;
};
@@ -97,22 +96,49 @@
i_free(node);
}
+static void sig_auth_cache_clear(int signo __attr_unused__, void *context)
+{
+ struct auth_cache *cache = context;
+
+ i_info("SIGHUP received, clearing cache");
+ auth_cache_clear(cache);
+}
+
+static void sig_auth_cache_stats(int signo __attr_unused__, void *context)
+{
+ struct auth_cache *cache = context;
+ unsigned int total_count;
+
+ total_count = cache->hit_count + cache->miss_count;
+ i_info("Authentication cache hits %u/%u (%u%%)",
+ cache->hit_count, total_count,
+ cache->hit_count * 100 / total_count);
+
+ /* reset hit counter */
+ cache->hit_count = cache->miss_count = 0;
+}
+
struct auth_cache *auth_cache_new(size_t max_size, unsigned int ttl_secs)
{
struct auth_cache *cache;
cache = i_new(struct auth_cache, 1);
- cache->hup_count = lib_signal_hup_count;
cache->hash = hash_create(default_pool, default_pool, 0, str_hash,
(hash_cmp_callback_t *)strcmp);
cache->size_left = max_size;
cache->ttl_secs = ttl_secs;
+
+ lib_signals_set_handler(SIGHUP, TRUE, sig_auth_cache_clear, cache);
+ lib_signals_set_handler(SIGUSR2, TRUE, sig_auth_cache_stats, cache);
return cache;
}
void auth_cache_free(struct auth_cache *cache)
{
- auth_cache_clear(cache);
+ lib_signals_unset_handler(SIGHUP, sig_auth_cache_clear, cache);
+ lib_signals_unset_handler(SIGUSR2, sig_auth_cache_stats, cache);
+
+ auth_cache_clear(cache);
hash_destroy(cache->hash);
i_free(cache);
}
@@ -122,8 +148,6 @@
while (cache->tail != NULL)
auth_cache_node_destroy(cache, cache->tail);
hash_clear(cache->hash, FALSE);
-
- cache->hup_count = lib_signal_hup_count;
}
const char *auth_cache_lookup(struct auth_cache *cache,
@@ -132,29 +156,9 @@
{
string_t *str;
struct cache_node *node;
- unsigned int total_count;
*expired_r = FALSE;
- if (cache->hup_count != lib_signal_hup_count) {
- /* SIGHUP received - clear cache */
- i_info("SIGHUP received, clearing cache");
- auth_cache_clear(cache);
- return NULL;
- }
-
- if (cache->usr2_count != lib_signal_usr2_count) {
- cache->usr2_count = lib_signal_usr2_count;
-
- total_count = cache->hit_count + cache->miss_count;
- i_info("Authentication cache hits %u/%u (%u%%)",
- cache->hit_count, total_count,
- cache->hit_count * 100 / total_count);
-
- /* reset hit counter */
- cache->hit_count = cache->miss_count = 0;
- }
-
str = t_str_new(256);
var_expand(str, key,
auth_request_get_var_expand_table(request, str_escape));
Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/main.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- main.c 23 Sep 2005 12:53:17 -0000 1.46
+++ main.c 25 Sep 2005 11:07:32 -0000 1.47
@@ -34,8 +34,12 @@
static struct auth *auth;
static struct auth_worker_client *worker_client;
-static void sig_quit(int signo __attr_unused__)
+static void sig_die(int signo, void *context __attr_unused__)
{
+ /* warn about being killed because of some signal, except SIGINT (^C)
+ which is too common at least while testing :) */
+ if (signo != SIGINT)
+ i_warning("Killed with signal %d", signo);
io_loop_stop(ioloop);
}
@@ -195,7 +199,11 @@
struct auth_master_listener *listener;
process_start_time = ioloop_time;
- lib_init_signals(sig_quit);
+
+ lib_signals_init();
+ lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
+ lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
+ lib_signals_set_handler(SIGPIPE, FALSE, NULL, NULL);
mech_init();
auth_init(auth);
@@ -246,9 +254,6 @@
static void main_deinit(void)
{
- if (lib_signal_kill != 0)
- i_warning("Killed with signal %d", lib_signal_kill);
-
if (worker_client != NULL)
auth_worker_client_unref(worker_client);
else
@@ -263,6 +268,7 @@
password_schemes_deinit();
random_deinit();
+ lib_signals_deinit();
closelog();
}
More information about the dovecot-cvs
mailing list