Hi, Mark! * Mark Pizzolato - ClamAV-devel <[email protected]> [2014-04-10 18:45]: > One more question (as I originally said, I haven't looked closely at > either the current code or your suggested patch)... What happens if > multiple reload requests come in right after each other while > scanning thread(s) are still scanning some file(s)?
Then the threads would override each other's work and you'd have unreferenced engines flying around. Good catch. Pasted below is a patch to address that problem. Julius -- >From a178a359970d65a0c439c8e3a84e861cbc9fd944 Mon Sep 17 00:00:00 2001 From: Julius Plenz <[email protected]> Date: Mon, 14 Apr 2014 11:05:06 +0200 Subject: [PATCH] Introduce a reload_in_progress flag --- clamd/server-th.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clamd/server-th.c b/clamd/server-th.c index 9afa2b7..2167475 100644 --- a/clamd/server-th.c +++ b/clamd/server-th.c @@ -64,6 +64,7 @@ int progexit = 0; pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER; int reload = 0; +volatile int reload_in_progress = 0; struct cl_engine *reload_engine = NULL; time_t reloaded_time = 0; pthread_mutex_t reload_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -226,6 +227,7 @@ static void *reload_db(void *argp) pthread_mutex_lock(&reload_mutex); time(&reloaded_time); reload_engine = engine; + reload_in_progress = 0; pthread_mutex_unlock(&reload_mutex); } @@ -1355,7 +1357,11 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi /* DB reload */ pthread_mutex_lock(&reload_mutex); - if(reload) { + if(reload && reload_in_progress) { + logg("Database reload already in progress; ignoring reload request.\n"); + reload = 0; + pthread_mutex_unlock(&reload_mutex); + } else if(reload) { pthread_mutex_unlock(&reload_mutex); struct reload_db_args reload_db_args = { .engine = engine, @@ -1364,6 +1370,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi }; pthread_mutex_lock(&reload_mutex); reload = 0; + reload_in_progress = 1; pthread_create(&reload_th, NULL, reload_db, &reload_db_args); pthread_mutex_unlock(&reload_mutex); } else { -- 1.9.0-zedat _______________________________________________ http://lurker.clamav.net/list/clamav-devel.html Please submit your patches to our Bugzilla: http://bugs.clamav.net
