git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@151 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2003/12/13 02:48:47... | ... |
@@ -1,3 +1,12 @@ |
1 |
+Fri Dec 12 18:47:10 CET 2003 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * clamd: clamuko - fixed a segmentation fault after database update. Problem |
|
4 | ||
5 |
+ is always stopped before (and restarted after) db update to |
|
6 |
+ protect against a potential split with Dazuko. |
|
7 |
+ * libclamav: scanners: added missing braces in a logical block (thanks to |
|
8 |
+ Tomasz Klim <tomek*euroneto.pl>) |
|
9 |
+ |
|
1 | 10 |
Fri Dec 12 13:43:50 GMT 2003 (njh) |
2 | 11 |
---------------------------------- |
3 | 12 |
* clamav-milter: A couple of calls to clamfi_cleanup were missing before |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl> |
|
2 |
+ * Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -48,7 +48,7 @@ void clamuko_exit(int sig) |
48 | 48 |
|
49 | 49 |
dazukoUnregister(); |
50 | 50 |
clamuko_running = 0; |
51 |
- logg("Clamuko stopped (exit).\n"); |
|
51 |
+ logg("Clamuko stopped.\n"); |
|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
void *clamukoth(void *arg) |
... | ... |
@@ -66,6 +66,7 @@ void *clamukoth(void *arg) |
66 | 66 |
|
67 | 67 |
|
68 | 68 |
clamuko_running = 1; |
69 |
+ clamuko_scanning = 0; |
|
69 | 70 |
|
70 | 71 |
/* ignore all signals except SIGUSR1 */ |
71 | 72 |
sigfillset(&sigset); |
... | ... |
@@ -163,51 +164,7 @@ void *clamukoth(void *arg) |
163 | 163 |
|
164 | 164 |
while(1) { |
165 | 165 |
|
166 |
- /* wait while reloading the database */ |
|
167 |
- if(reload) { |
|
168 |
- logg("*Clamuko: Waiting (database reloading)\n"); |
|
169 |
- clamuko_reload = 1; |
|
170 |
- maxwait = CL_DEFAULT_MAXWHILEWAIT; |
|
171 |
- while(reload && maxwait--) |
|
172 |
- sleep(1); |
|
173 |
- |
|
174 |
- if(!maxwait && reload) { |
|
175 |
- logg("!Clamuko: Database reloading failed. Forcing quit...\n"); |
|
176 |
- logg("Clamuko stopped.\n"); |
|
177 |
- dazukoUnregister(); |
|
178 |
- kill(progpid, SIGTERM); |
|
179 |
- clamuko_running = 0; |
|
180 |
- clamuko_scanning = 0; |
|
181 |
- clamuko_reload = 0; |
|
182 |
- return NULL; |
|
183 |
- } |
|
184 |
- |
|
185 |
- clamuko_reload = 0; |
|
186 |
- } |
|
187 |
- |
|
188 | 166 |
if(dazukoGetAccess(&acc) == 0) { |
189 |
- /* wait while reloading the database */ |
|
190 |
- if(reload) { |
|
191 |
- logg("*Clamuko: Waiting (database reloading, after dazukoGetAccess())\n"); |
|
192 |
- clamuko_reload = 1; |
|
193 |
- maxwait = CL_DEFAULT_MAXWHILEWAIT; |
|
194 |
- while(reload && maxwait--) |
|
195 |
- sleep(1); |
|
196 |
- |
|
197 |
- if(!maxwait && reload) { |
|
198 |
- logg("!Clamuko: Database reloading failed. Forcing quit...\n"); |
|
199 |
- kill(progpid, SIGTERM); |
|
200 |
- acc.deny = 0; |
|
201 |
- dazukoReturnAccess(&acc); |
|
202 |
- logg("Clamuko stopped.\n"); |
|
203 |
- dazukoUnregister(); |
|
204 |
- clamuko_running = 0; |
|
205 |
- clamuko_scanning = 0; |
|
206 |
- clamuko_reload = 0; |
|
207 |
- return NULL; |
|
208 |
- } |
|
209 |
- } |
|
210 |
- |
|
211 | 167 |
clamuko_scanning = 1; |
212 | 168 |
scan = 1; |
213 | 169 |
|
... | ... |
@@ -119,6 +119,8 @@ void *threadscanner(void *arg) |
119 | 119 |
void *threadwatcher(void *arg) |
120 | 120 |
{ |
121 | 121 |
struct thrwarg *thwarg = (struct thrwarg *) arg; |
122 |
+ struct thrarg *tharg; |
|
123 |
+ pthread_attr_t thattr; |
|
122 | 124 |
struct cfgstruct *cpt; |
123 | 125 |
sigset_t sigset; |
124 | 126 |
int i, j, ret, maxwait, virnum; |
... | ... |
@@ -192,7 +194,7 @@ void *threadwatcher(void *arg) |
192 | 192 |
#ifdef CLAMUKO |
193 | 193 |
/* stop clamuko */ |
194 | 194 |
if(clamuko_running) { |
195 |
- logg("Stopping Clamuko... (id %d)\n", clamukoid); |
|
195 |
+ logg("Stopping Clamuko...\n"); |
|
196 | 196 |
pthread_kill(clamukoid, SIGUSR1); |
197 | 197 |
/* we must wait for Dazuko unregistration */ |
198 | 198 |
maxwait = CL_DEFAULT_MAXWHILEWAIT * 5; |
... | ... |
@@ -295,10 +297,19 @@ void *threadwatcher(void *arg) |
295 | 295 |
} |
296 | 296 |
|
297 | 297 |
#ifdef CLAMUKO |
298 |
- if(clamuko_scanning && !clamuko_reload) |
|
299 |
- need_wait = 1; |
|
298 |
+ if(clamuko_running) { |
|
299 |
+ logg("Stopping Clamuko...\n"); |
|
300 |
+ pthread_kill(clamukoid, SIGUSR1); |
|
301 |
+ /* we must wait for Dazuko unregistration */ |
|
302 |
+ maxwait = CL_DEFAULT_MAXWHILEWAIT * 5; |
|
303 |
+ while(clamuko_running && maxwait--) |
|
304 |
+ usleep(200000); |
|
305 |
+ |
|
306 |
+ if(!maxwait && clamuko_running) |
|
307 |
+ logg("!Critical error: Can't stop Clamuko.\n"); |
|
308 |
+ /* should we stop here ? */ |
|
309 |
+ } |
|
300 | 310 |
#endif |
301 |
- |
|
302 | 311 |
if(need_wait) |
303 | 312 |
usleep(200000); |
304 | 313 |
|
... | ... |
@@ -356,6 +367,24 @@ void *threadwatcher(void *arg) |
356 | 356 |
logg("Database correctly reloaded (%d viruses)\n", virnum); |
357 | 357 |
} |
358 | 358 |
|
359 |
+ /* start clamuko */ |
|
360 |
+#ifdef CLAMUKO |
|
361 |
+ |
|
362 |
+ if(cfgopt(thwarg->copt, "ClamukoScanOnLine")) { |
|
363 |
+ logg("Starting Clamuko...\n"); |
|
364 |
+ tharg = (struct thrarg *) mcalloc(1, sizeof(struct thrarg)); |
|
365 |
+ tharg->copt = thwarg->copt; |
|
366 |
+ tharg->root = *thwarg->root; |
|
367 |
+ tharg->limits = thwarg->limits; |
|
368 |
+ tharg->options = thwarg->options; |
|
369 |
+ |
|
370 |
+ pthread_attr_init(&thattr); |
|
371 |
+ pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_DETACHED); |
|
372 |
+ pthread_create(&clamukoid, &thattr, clamukoth, tharg); |
|
373 |
+ pthread_attr_destroy(&thattr); |
|
374 |
+ } |
|
375 |
+#endif |
|
376 |
+ |
|
359 | 377 |
reload = 0; |
360 | 378 |
} |
361 | 379 |
|
... | ... |
@@ -492,7 +521,6 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop |
492 | 492 |
progpid = 0; |
493 | 493 |
reload = 0; |
494 | 494 |
#ifdef CLAMUKO |
495 |
- clamuko_scanning = 0; |
|
496 | 495 |
clamuko_running = 0; |
497 | 496 |
#endif |
498 | 497 |
|
... | ... |
@@ -508,7 +536,6 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop |
508 | 508 |
tharg->root = root; |
509 | 509 |
tharg->limits = &limits; |
510 | 510 |
tharg->options = options; |
511 |
- clamuko_reload = 0; |
|
512 | 511 |
|
513 | 512 |
pthread_create(&clamukoid, &thattr, clamukoth, tharg); |
514 | 513 |
} |
... | ... |
@@ -520,6 +547,8 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop |
520 | 520 |
thwarg.socketd = socketd; |
521 | 521 |
thwarg.copt = copt; |
522 | 522 |
thwarg.root = &root; |
523 |
+ thwarg.limits = &limits; |
|
524 |
+ thwarg.options = options; |
|
523 | 525 |
pthread_create(&watcherid, &thattr, threadwatcher, &thwarg); |
524 | 526 |
|
525 | 527 |
/* set up signal handling */ |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
/* |
2 |
- * Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl> |
|
2 |
+ * Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl> |
|
3 | 3 |
* |
4 | 4 |
* This program is free software; you can redistribute it and/or modify |
5 | 5 |
* it under the terms of the GNU General Public License as published by |
... | ... |
@@ -25,7 +25,7 @@ |
25 | 25 |
|
26 | 26 |
struct thrarg { |
27 | 27 |
int sid; |
28 |
- int options; /* archive support 0/1 */ |
|
28 |
+ int options; |
|
29 | 29 |
const struct cfgstruct *copt; |
30 | 30 |
const struct cl_node *root; |
31 | 31 |
const struct cl_limits *limits; |
... | ... |
@@ -44,11 +44,13 @@ struct thrwarg { |
44 | 44 |
int socketd; |
45 | 45 |
struct cl_node **root; |
46 | 46 |
const struct cfgstruct *copt; |
47 |
+ const struct cl_limits *limits; |
|
48 |
+ int options; |
|
47 | 49 |
}; |
48 | 50 |
|
49 | 51 |
short int progexit; /* exit steering variable */ |
50 | 52 |
int progpid; /* clamd pid */ |
51 |
-short int reload, clamuko_reload, main_accept, main_reload; |
|
53 |
+short int reload, main_accept, main_reload; |
|
52 | 54 |
|
53 | 55 |
int acceptloop_proc(int socketd, struct cl_node *root, const struct cfgstruct *copt); |
54 | 56 |
int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *copt); |
... | ... |
@@ -713,12 +713,13 @@ int cli_magic_scandesc(int desc, char **virname, long int *scanned, const struct |
713 | 713 |
(*reclev)--; |
714 | 714 |
} |
715 | 715 |
|
716 |
- if(ret != CL_VIRUS) /* scan the raw file */ |
|
716 |
+ if(ret != CL_VIRUS) { /* scan the raw file */ |
|
717 | 717 |
lseek(desc, 0, SEEK_SET); /* If archive scan didn't rewind desc */ |
718 | 718 |
if(cli_scandesc(desc, virname, scanned, root) == CL_VIRUS) { |
719 | 719 |
cli_dbgmsg("%s virus found in descriptor %d.\n", *virname, desc); |
720 | 720 |
return CL_VIRUS; |
721 | 721 |
} |
722 |
+ } |
|
722 | 723 |
|
723 | 724 |
return ret; |
724 | 725 |
} |