git-svn: trunk@4398
Tomasz Kojm authored on 2008/11/14 00:55:35... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Thu Nov 13 15:55:20 CET 2008 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav: drop options parameter in cl_engine_new(); replace cl_engine_dup() |
|
4 |
+ with cl_engine_addref() |
|
5 |
+ |
|
1 | 6 |
Thu Nov 13 14:59:39 CET 2008 (tk) |
2 | 7 |
--------------------------------- |
3 | 8 |
* libclamav/readdb.c: phishing_done() no longer needs to be called outside |
... | ... |
@@ -3449,17 +3449,17 @@ clamfi_eom(SMFICTX *ctx) |
3449 | 3449 |
|
3450 | 3450 |
if(!external) { |
3451 | 3451 |
const char *virname; |
3452 |
- struct cl_engine *tmp_engine; |
|
3452 |
+ int ret; |
|
3453 | 3453 |
|
3454 | 3454 |
pthread_mutex_lock(&engine_mutex); |
3455 |
- tmp_engine = cl_engine_dup(engine); |
|
3455 |
+ ret = cl_engine_addref(engine); |
|
3456 | 3456 |
pthread_mutex_unlock(&engine_mutex); |
3457 |
- if(!tmp_engine) { |
|
3458 |
- logg("!cl_engine_dup failed\n"); |
|
3457 |
+ if(ret != CL_SUCCESS) { |
|
3458 |
+ logg("!cl_engine_addref failed\n"); |
|
3459 | 3459 |
clamfi_cleanup(ctx); |
3460 | 3460 |
return cl_error; |
3461 | 3461 |
} |
3462 |
- switch(cl_scanfile(privdata->filename, &virname, NULL, tmp_engine, options)) { |
|
3462 |
+ switch(cl_scanfile(privdata->filename, &virname, NULL, engine, options)) { |
|
3463 | 3463 |
case CL_CLEAN: |
3464 | 3464 |
if(logok) |
3465 | 3465 |
logg("#%s: OK\n", privdata->filename); |
... | ... |
@@ -3474,7 +3474,7 @@ clamfi_eom(SMFICTX *ctx) |
3474 | 3474 |
logg("!%s\n", mess); |
3475 | 3475 |
break; |
3476 | 3476 |
} |
3477 |
- cl_engine_free(tmp_engine); |
|
3477 |
+ cl_engine_free(engine); /* drop reference or free */ |
|
3478 | 3478 |
|
3479 | 3479 |
#ifdef SESSION |
3480 | 3480 |
session = NULL; |
... | ... |
@@ -5916,7 +5916,7 @@ loadDatabase(void) |
5916 | 5916 |
signatures = 0; |
5917 | 5917 |
pthread_mutex_lock(&engine_mutex); |
5918 | 5918 |
if(engine) cl_engine_free(engine); |
5919 |
- engine = cl_engine_new(CL_ENGINE_DEFAULT); |
|
5919 |
+ engine = cl_engine_new(); |
|
5920 | 5920 |
if (!engine) { |
5921 | 5921 |
logg("!Can't initialize antivirus engine\n"); |
5922 | 5922 |
pthread_mutex_unlock(&engine_mutex); |
... | ... |
@@ -309,7 +309,7 @@ int main(int argc, char **argv) |
309 | 309 |
else |
310 | 310 |
logg("#Log file size limit disabled.\n"); |
311 | 311 |
|
312 |
- if(!(engine = cl_engine_new(CL_ENGINE_DEFAULT))) { |
|
312 |
+ if(!(engine = cl_engine_new())) { |
|
313 | 313 |
logg("!Can't initialize antivirus engine\n"); |
314 | 314 |
logg_close(); |
315 | 315 |
freecfg(copt); |
... | ... |
@@ -246,7 +246,7 @@ static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dbopti |
246 | 246 |
return NULL; |
247 | 247 |
} |
248 | 248 |
|
249 |
- if(!(engine = cl_engine_new(CL_ENGINE_DEFAULT))) { |
|
249 |
+ if(!(engine = cl_engine_new())) { |
|
250 | 250 |
logg("!Can't initialize antivirus engine\n"); |
251 | 251 |
*ret = 1; |
252 | 252 |
return NULL; |
... | ... |
@@ -663,14 +663,23 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_engine *engine, unsigne |
663 | 663 |
client_conn->sd = new_sd; |
664 | 664 |
client_conn->options = options; |
665 | 665 |
client_conn->copt = copt; |
666 |
- client_conn->engine = cl_engine_dup(engine); |
|
667 |
- client_conn->engine_timestamp = reloaded_time; |
|
668 |
- client_conn->socketds = socketds; |
|
669 |
- client_conn->nsockets = nsockets; |
|
670 |
- if(!thrmgr_dispatch(thr_pool, client_conn)) { |
|
666 |
+ if(cl_engine_addref(engine)) { |
|
671 | 667 |
closesocket(client_conn->sd); |
672 | 668 |
free(client_conn); |
673 |
- logg("!thread dispatch failed\n"); |
|
669 |
+ logg("!cl_engine_addref() failed\n"); |
|
670 |
+ pthread_mutex_lock(&exit_mutex); |
|
671 |
+ progexit = 1; |
|
672 |
+ pthread_mutex_unlock(&exit_mutex); |
|
673 |
+ } else { |
|
674 |
+ client_conn->engine = engine; |
|
675 |
+ client_conn->engine_timestamp = reloaded_time; |
|
676 |
+ client_conn->socketds = socketds; |
|
677 |
+ client_conn->nsockets = nsockets; |
|
678 |
+ if(!thrmgr_dispatch(thr_pool, client_conn)) { |
|
679 |
+ closesocket(client_conn->sd); |
|
680 |
+ free(client_conn); |
|
681 |
+ logg("!thread dispatch failed\n"); |
|
682 |
+ } |
|
674 | 683 |
} |
675 | 684 |
} else { |
676 | 685 |
logg("!Can't allocate memory for client_conn\n"); |
... | ... |
@@ -109,8 +109,7 @@ struct cl_engine; |
109 | 109 |
#define CL_INIT_DEFAULT 0x0 |
110 | 110 |
extern int cl_init(unsigned int options); |
111 | 111 |
|
112 |
-#define CL_ENGINE_DEFAULT 0x0 |
|
113 |
-extern struct cl_engine *cl_engine_new(unsigned int options); |
|
112 |
+extern struct cl_engine *cl_engine_new(void); |
|
114 | 113 |
|
115 | 114 |
enum cl_engine_field { |
116 | 115 |
CL_ENGINE_MAX_SCANSIZE, /* uint64_t */ |
... | ... |
@@ -130,7 +129,7 @@ extern int cl_engine_get(const struct cl_engine *engine, enum cl_engine_field fi |
130 | 130 |
|
131 | 131 |
extern int cl_engine_compile(struct cl_engine *engine); |
132 | 132 |
|
133 |
-extern struct cl_engine *cl_engine_dup(struct cl_engine *engine); |
|
133 |
+extern int cl_engine_addref(struct cl_engine *engine); |
|
134 | 134 |
|
135 | 135 |
extern int cl_engine_free(struct cl_engine *engine); |
136 | 136 |
|
... | ... |
@@ -2049,11 +2049,11 @@ int cl_engine_compile(struct cl_engine *engine) |
2049 | 2049 |
return CL_SUCCESS; |
2050 | 2050 |
} |
2051 | 2051 |
|
2052 |
-struct cl_engine *cl_engine_dup(struct cl_engine *engine) |
|
2052 |
+int cl_engine_addref(struct cl_engine *engine) |
|
2053 | 2053 |
{ |
2054 | 2054 |
if(!engine) { |
2055 |
- cli_errmsg("cl_engine_dup: engine == NULL\n"); |
|
2056 |
- return NULL; |
|
2055 |
+ cli_errmsg("cl_engine_addref: engine == NULL\n"); |
|
2056 |
+ return CL_ENULLARG; |
|
2057 | 2057 |
} |
2058 | 2058 |
|
2059 | 2059 |
#ifdef CL_THREAD_SAFE |
... | ... |
@@ -2066,5 +2066,5 @@ struct cl_engine *cl_engine_dup(struct cl_engine *engine) |
2066 | 2066 |
pthread_mutex_unlock(&cli_ref_mutex); |
2067 | 2067 |
#endif |
2068 | 2068 |
|
2069 |
- return engine; |
|
2069 |
+ return CL_SUCCESS; |
|
2070 | 2070 |
} |
... | ... |
@@ -560,7 +560,7 @@ static int build(struct optstruct *opt) |
560 | 560 |
|
561 | 561 |
dbname = strstr(opt_arg(opt, "build"), "main") ? "main" : "daily"; |
562 | 562 |
|
563 |
- if(!(engine = cl_engine_new(CL_ENGINE_DEFAULT))) { |
|
563 |
+ if(!(engine = cl_engine_new())) { |
|
564 | 564 |
mprintf("!build: Can't initialize antivirus engine\n"); |
565 | 565 |
return 50; |
566 | 566 |
} |