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
This commit is contained in:
Török Edvin
2009-02-08 21:07:10 +00:00
parent e066e3cb47
commit fdbaba8d49
4 changed files with 13 additions and 9 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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,