git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@32 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2003/09/05 22:10:21... | ... |
@@ -38,7 +38,7 @@ |
38 | 38 |
close(ths[tharg->sid].desc); \ |
39 | 39 |
ths[tharg->sid].active = 0; \ |
40 | 40 |
/* this mutex is rather useless */ \ |
41 |
- pthread_mutex_unlock(&ths[tharg->sid].mutex); \ |
|
41 |
+ /* pthread_mutex_unlock(&ths[tharg->sid].mutex); */ \ |
|
42 | 42 |
free(tharg); \ |
43 | 43 |
return NULL |
44 | 44 |
|
... | ... |
@@ -184,14 +184,14 @@ void *threadwatcher(void *arg) |
184 | 184 |
i = 0; |
185 | 185 |
|
186 | 186 |
/* check time */ |
187 |
- if(ths[i].active) /* races are harmless here (timeout is reset) */ |
|
187 |
+ if(ths[i].active) /* races are harmless here (timeout is re-set) */ |
|
188 | 188 |
if(time(NULL) - ths[i].start > timeout) { |
189 | 189 |
pthread_cancel(ths[i].id); |
190 | 190 |
mdprintf(ths[i].desc, "Session(%d): Time out ERROR\n", i); |
191 | 191 |
close(ths[i].desc); |
192 | 192 |
logg("Session %d stopped due to timeout.\n", i); |
193 | 193 |
ths[i].active = 0; |
194 |
- pthread_mutex_unlock(&ths[i].mutex); |
|
194 |
+// pthread_mutex_unlock(&ths[i].mutex); |
|
195 | 195 |
} |
196 | 196 |
|
197 | 197 |
/* cancel all threads in case of quit */ |
... | ... |
@@ -217,26 +217,26 @@ void *threadwatcher(void *arg) |
217 | 217 |
mdprintf(ths[j].desc, "Session(%d): Stopped (exiting)\n", j); |
218 | 218 |
close(ths[j].desc); |
219 | 219 |
logg("Session %d stopped (exiting).\n", j); |
220 |
- pthread_mutex_unlock(&ths[j].mutex); |
|
220 |
+// pthread_mutex_unlock(&ths[j].mutex); |
|
221 | 221 |
} |
222 | 222 |
#ifndef C_BSD |
223 | 223 |
logg("*Freeing trie structure.\n"); |
224 | 224 |
cl_freetrie(*thwarg->root); |
225 | 225 |
#endif |
226 |
- logg("*Shutting down main socket.\n"); |
|
226 |
+ logg("*Shutting down the main socket.\n"); |
|
227 | 227 |
shutdown(thwarg->socketd, 2); |
228 |
- logg("*Closing main socket.\n"); |
|
228 |
+ logg("*Closing the main socket.\n"); |
|
229 | 229 |
close(thwarg->socketd); |
230 | 230 |
if((cpt = cfgopt(thwarg->copt, "LocalSocket"))) { |
231 | 231 |
if(unlink(cpt->strarg) == -1) |
232 |
- logg("!Can't unlink socket file %s\n", cpt->strarg); |
|
232 |
+ logg("!Can't unlink the socket file %s\n", cpt->strarg); |
|
233 | 233 |
else |
234 | 234 |
logg("Socket file removed.\n"); |
235 | 235 |
} |
236 | 236 |
|
237 | 237 |
if((cpt = cfgopt(thwarg->copt, "PidFile"))) { |
238 | 238 |
if(unlink(cpt->strarg) == -1) |
239 |
- logg("!Can't unlink pid file %s\n", cpt->strarg); |
|
239 |
+ logg("!Can't unlink the pid file %s\n", cpt->strarg); |
|
240 | 240 |
else |
241 | 241 |
logg("Pid file removed.\n"); |
242 | 242 |
} |
... | ... |
@@ -352,16 +352,18 @@ void *threadwatcher(void *arg) |
352 | 352 |
return NULL; |
353 | 353 |
} |
354 | 354 |
|
355 |
+int threads; |
|
356 |
+pthread_t watcherid; |
|
357 |
+ |
|
355 | 358 |
int acceptloop(int socketd, struct cl_node *root, const struct cfgstruct *copt) |
356 | 359 |
{ |
357 |
- int acceptd, threads, i, options = 0, maxwait; |
|
360 |
+ int acceptd, i, options = 0, maxwait; |
|
358 | 361 |
struct cfgstruct *cpt; |
359 | 362 |
struct thrarg *tharg; |
360 | 363 |
struct thrwarg thwarg; |
361 | 364 |
struct cl_limits limits; |
362 | 365 |
pthread_attr_t thattr; |
363 |
- pthread_t watcherid; |
|
364 |
- struct sigaction sigact; |
|
366 |
+ struct sigaction sigact, sigsegvact; |
|
365 | 367 |
sigset_t sigset; |
366 | 368 |
mode_t old_umask; |
367 | 369 |
|
... | ... |
@@ -493,15 +495,20 @@ int acceptloop(int socketd, struct cl_node *root, const struct cfgstruct *copt) |
493 | 493 |
sigfillset(&sigset); |
494 | 494 |
sigdelset(&sigset, SIGINT); |
495 | 495 |
sigdelset(&sigset, SIGTERM); |
496 |
+ sigdelset(&sigset, SIGSEGV); |
|
496 | 497 |
sigprocmask(SIG_SETMASK, &sigset, NULL); |
497 | 498 |
|
498 |
- /* SIGINT, SIGTERM */ |
|
499 |
+ /* SIGINT, SIGTERM, SIGSEGV */ |
|
499 | 500 |
sigact.sa_handler = sigexit; |
501 |
+ sigsegvact.sa_handler = sigsegv; |
|
500 | 502 |
sigemptyset(&sigact.sa_mask); |
503 |
+ sigemptyset(&sigsegvact.sa_mask); |
|
501 | 504 |
sigaddset(&sigact.sa_mask, SIGINT); |
502 | 505 |
sigaddset(&sigact.sa_mask, SIGTERM); |
506 |
+ sigaddset(&sigsegvact.sa_mask, SIGSEGV); |
|
503 | 507 |
sigaction(SIGINT, &sigact, NULL); |
504 | 508 |
sigaction(SIGTERM, &sigact, NULL); |
509 |
+ sigaction(SIGSEGV, &sigsegvact, NULL); |
|
505 | 510 |
|
506 | 511 |
/* we need to save program's PID, because under Linux each thread |
507 | 512 |
* has another PID, it works with other OSes as well |
... | ... |
@@ -516,7 +523,7 @@ int acceptloop(int socketd, struct cl_node *root, const struct cfgstruct *copt) |
516 | 516 |
* We need to allow for that. |
517 | 517 |
*/ |
518 | 518 |
pthread_attr_getstacksize(&thattr, &stacksize); |
519 |
- cli_dbgmsg("set stacksize to %u\n", stacksize + BUFFSIZE + 256 * 1024); |
|
519 |
+ cli_dbgmsg("set stacksize to %u\n", stacksize + BUFFSIZE + 64 * 1024); |
|
520 | 520 |
pthread_attr_setstacksize(&thattr, stacksize + BUFFSIZE + 64 * 1024); |
521 | 521 |
#endif |
522 | 522 |
|
... | ... |
@@ -564,12 +571,12 @@ int acceptloop(int socketd, struct cl_node *root, const struct cfgstruct *copt) |
564 | 564 |
tharg->limits = &limits; |
565 | 565 |
tharg->options = options; |
566 | 566 |
|
567 |
- pthread_mutex_lock(&ths[i].mutex); |
|
567 |
+ //pthread_mutex_lock(&ths[i].mutex); |
|
568 | 568 |
ths[i].desc = acceptd; |
569 | 569 |
ths[i].reload = 0; |
570 |
- ths[i].active = 1; |
|
571 | 570 |
pthread_create(&ths[i].id, &thattr, threadscanner, tharg); |
572 | 571 |
ths[i].start = time(NULL); |
572 |
+ ths[i].active = 1; |
|
573 | 573 |
} |
574 | 574 |
} |
575 | 575 |
|
... | ... |
@@ -591,3 +598,17 @@ void sigexit(int sig) |
591 | 591 |
logg("--- Stopped at %s", ctime(&currtime)); |
592 | 592 |
exit(0); |
593 | 593 |
} |
594 |
+ |
|
595 |
+void sigsegv(int sig) |
|
596 |
+{ |
|
597 |
+ int i; |
|
598 |
+ |
|
599 |
+ logg("Segmentation fault :-( Bye..\n"); |
|
600 |
+ |
|
601 |
+ for(i = 0; i < threads; i++) |
|
602 |
+ if(ths[i].active) |
|
603 |
+ pthread_kill(ths[i].id, 9); |
|
604 |
+ |
|
605 |
+ pthread_kill(watcherid, 9); |
|
606 |
+ exit(11); /* probably not reached at all */ |
|
607 |
+} |