From fdbaba8d49017e2ecbfcf05a6663a314615ce03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Sun, 8 Feb 2009 21:07:10 +0000 Subject: [PATCH] always allocate a jobgroup, that way on shutdown we are sure that it doesn't dissappear. git-svn-id: file:///var/lib/svn/clamav-devel/branches/clamd-proto@4712 77e5149b-7576-45b1-b177-96237e5ba77b --- ChangeLog | 6 ++++++ clamd/session.c | 6 +++--- clamd/thrmgr.c | 7 ++++--- clamd/thrmgr.h | 3 --- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea5896eda..19af2c24f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Feb 8 23:34:15 EET 2009 (edwin) +------------------------------------ + * clamd/session.c, clamd/thrmgr.c, clamd/thrmgr.h: always allocate a + jobgroup, that way on shutdown we are sure that it doesn't + dissappear. + Sun Feb 8 23:14:28 EET 2009 (edwin) ------------------------------------ * clamd/thrmgr.c: unify thresholds diff --git a/clamd/session.c b/clamd/session.c index ef4bb9c02..cf57ca1fd 100644 --- a/clamd/session.c +++ b/clamd/session.c @@ -183,7 +183,7 @@ int command(client_conn_t *conn, int *virus) struct scan_cb_data scandata; struct cli_ftw_cbdata data; unsigned ok, error, total; - jobgroup_t group = JOBGROUP_INITIALIZER; + jobgroup_t *group = NULL; if (thrmgr_group_need_terminate(conn->group)) { logg("^Client disconnected while command was active\n"); @@ -218,7 +218,7 @@ int command(client_conn_t *conn, int *virus) flags &= ~CLI_FTW_NEED_STAT; thrmgr_setactivetask(NULL, "MULTISCAN"); type = TYPE_MULTISCAN; - scandata.group = &group; + scandata.group = group = thrmgr_group_new(); break; case COMMAND_MULTISCANFILE: thrmgr_setactivetask(NULL, "MULTISCANFILE"); @@ -292,7 +292,7 @@ int command(client_conn_t *conn, int *virus) if(optget(opts, "ExitOnOOM")->enabled) return -1; if (scandata.group && conn->cmdtype == COMMAND_MULTISCAN) { - thrmgr_group_waitforall(&group, &ok, &error, &total); + thrmgr_group_waitforall(group, &ok, &error, &total); } else { error = scandata.errors; total = scandata.total; diff --git a/clamd/thrmgr.c b/clamd/thrmgr.c index 90aae9edf..601140361 100644 --- a/clamd/thrmgr.c +++ b/clamd/thrmgr.c @@ -762,7 +762,7 @@ int thrmgr_group_finished(jobgroup_t *group, enum thrmgr_exit exitc) pthread_cond_signal(&group->only); } pthread_mutex_unlock(&group->mutex); - if (ret && group->allocated) { + if (ret) { free(group); } return ret; @@ -787,10 +787,12 @@ void thrmgr_group_waitforall(jobgroup_t *group, unsigned *ok, unsigned *error, u *ok = group->exit_ok; *error = group->exit_error + needexit; *total = group->exit_total; - group->jobs--; + if(!--group->jobs) + free(group); pthread_mutex_unlock(&group->mutex); } +#define JOBGROUP_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 1, 0, 0, 0, 0 }; jobgroup_t *thrmgr_group_new(void) { jobgroup_t dummy = JOBGROUP_INITIALIZER; @@ -798,7 +800,6 @@ jobgroup_t *thrmgr_group_new(void) if (!group) return NULL; memcpy(group, &dummy, sizeof(dummy)); - group->allocated = 1; return group; } diff --git a/clamd/thrmgr.h b/clamd/thrmgr.h index 3180c4f19..ac10b0031 100644 --- a/clamd/thrmgr.h +++ b/clamd/thrmgr.h @@ -84,11 +84,8 @@ typedef struct jobgroup { unsigned exit_error; unsigned exit_total; int force_exit; - int allocated; } jobgroup_t; -#define JOBGROUP_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 1, 0, 0, 0, 0, 0 }; - enum thrmgr_exit { EXIT_OK, EXIT_ERROR,