mirror of https://github.com/jrbrtsn/ban2fail
Fixed thread cleanup bug, improved README
This commit is contained in:
parent
57553e4a3c
commit
f99812a97b
12
README.md
12
README.md
|
@ -191,13 +191,19 @@ forward match) info *-a-*. In the list, DNS issues are presented like so:
|
||||||
# DNS is good
|
# DNS is good
|
||||||
0 Dec 04 11:04 185.31.204.22 1/0 offenses GB [BLK] mail.damianbasel.audise.com
|
0 Dec 04 11:04 185.31.204.22 1/0 offenses GB [BLK] mail.damianbasel.audise.com
|
||||||
|
|
||||||
# Reverse lookup does not match forward lookup
|
# Reverse lookup failed with DNS server
|
||||||
|
0 Dec 05 14:14 120.230.127.69 1/0 offenses CN [BLK] SERVFAIL
|
||||||
|
|
||||||
|
# Reverse lookup is a non-existent domain
|
||||||
|
0 Dec 05 13:14 103.95.9.208 1/0 offenses ID [BLK] NXDOMAIN
|
||||||
|
|
||||||
|
# Forward lookup does not match reverse lookup
|
||||||
0 Dec 04 08:47 103.238.80.23 2/0 offenses VN [BLK] example.com !
|
0 Dec 04 08:47 103.238.80.23 2/0 offenses VN [BLK] example.com !
|
||||||
|
|
||||||
# Forward DNS is unavailable
|
# Forward DNS record does not exist
|
||||||
4 Dec 04 10:54 106.51.230.190 2/0 offenses IN [BLK] broadband.actcorp.in !!
|
4 Dec 04 10:54 106.51.230.190 2/0 offenses IN [BLK] broadband.actcorp.in !!
|
||||||
|
|
||||||
# DNS is inconclusive due to lack of response from DNS servers
|
# DNS is inconclusive due to lack of response from a DNS server
|
||||||
0 Dec 04 04:13 87.120.246.53 1/0 offenses BG [BLK] client.playtime.bg ~
|
0 Dec 04 04:13 87.120.246.53 1/0 offenses BG [BLK] client.playtime.bg ~
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
68
es.c
68
es.c
|
@ -7,9 +7,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "map.h"
|
|
||||||
#include "msgqueue.h"
|
#include "msgqueue.h"
|
||||||
#include "ez_es.h"
|
#include "ez_es.h"
|
||||||
|
#include "map.h"
|
||||||
#include "ez_libpthread.h"
|
#include "ez_libpthread.h"
|
||||||
|
|
||||||
/* Types of registered callbacks */
|
/* Types of registered callbacks */
|
||||||
|
@ -95,7 +95,7 @@ static _Thread_local struct _TS {
|
||||||
struct {
|
struct {
|
||||||
/* virtual signal message queue */
|
/* virtual signal message queue */
|
||||||
MSGQUEUE mq;
|
MSGQUEUE mq;
|
||||||
MAP map;
|
MAP cb_map;
|
||||||
} vsig;
|
} vsig;
|
||||||
|
|
||||||
} TS;
|
} TS;
|
||||||
|
@ -294,22 +294,34 @@ sigusr2_h(void *ctxt, int unused)
|
||||||
* Handle any vsignals.
|
* Handle any vsignals.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int vsigno;
|
int rtn= 0,
|
||||||
|
vsigno;
|
||||||
|
|
||||||
Cb *cb_arr[VSIG_QUEUE_MAX];
|
Cb *cb_arr[VSIG_QUEUE_MAX];
|
||||||
|
|
||||||
|
/* Protected operation */
|
||||||
|
// ez_pthread_mutex_lock(&S.vsig.mtx);
|
||||||
|
|
||||||
while(EOF != MSGQUEUE_extractMsg(&TS.vsig.mq, &vsigno)) {
|
while(EOF != MSGQUEUE_extractMsg(&TS.vsig.mq, &vsigno)) {
|
||||||
|
|
||||||
int rc= MAP_findItems(&TS.vsig.map, (void**)cb_arr, VSIG_QUEUE_MAX, &vsigno, sizeof(int));
|
int rc= MAP_findItems(&TS.vsig.cb_map, (void**)cb_arr, VSIG_QUEUE_MAX, &vsigno, sizeof(int));
|
||||||
assert(-1 != rc);
|
if(-1 == rc) {
|
||||||
if(!rc) continue;
|
eprintf("FATAL: MAP_findItems() failed");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rc) goto abort;
|
||||||
|
|
||||||
for(int i= 0; i < rc; ++i) {
|
for(int i= 0; i < rc; ++i) {
|
||||||
Cb *cb= cb_arr[i];
|
Cb *cb= cb_arr[i];
|
||||||
int error= (* cb->un.sig.callback_f)(cb->ctxt, vsigno);
|
rtn= (* cb->un.sig.callback_f)(cb->ctxt, vsigno);
|
||||||
if(error) return error;
|
if(rtn) goto abort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
abort:
|
||||||
|
// ez_pthread_mutex_unlock(&S.vsig.mtx);
|
||||||
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -350,7 +362,7 @@ initialize()
|
||||||
|
|
||||||
/*--- virtual signal infrastructure ---*/
|
/*--- virtual signal infrastructure ---*/
|
||||||
MSGQUEUE_constructor(&TS.vsig.mq, sizeof(int), VSIG_QUEUE_MAX);
|
MSGQUEUE_constructor(&TS.vsig.mq, sizeof(int), VSIG_QUEUE_MAX);
|
||||||
MAP_constructor(&TS.vsig.map, 10, 10);
|
MAP_constructor(&TS.vsig.cb_map, 10, 10);
|
||||||
/* Register a signal handler for SIGUSR2 so we can have virtual signals. */
|
/* Register a signal handler for SIGUSR2 so we can have virtual signals. */
|
||||||
ez_ES_registerSignal(SIGUSR2, sigusr2_h, NULL);
|
ez_ES_registerSignal(SIGUSR2, sigusr2_h, NULL);
|
||||||
ez_pthread_mutex_unlock(&S.vsig.mtx);
|
ez_pthread_mutex_unlock(&S.vsig.mtx);
|
||||||
|
@ -446,7 +458,7 @@ ES_registerVSignal (
|
||||||
if(!Cb_VSignalCreate(cb, signum, callback_f, ctxt)) assert(0);
|
if(!Cb_VSignalCreate(cb, signum, callback_f, ctxt)) assert(0);
|
||||||
|
|
||||||
/* Place in the virtual signal map indexed on signum */
|
/* Place in the virtual signal map indexed on signum */
|
||||||
MAP_addTypedKey(&TS.vsig.map, cb->un.sig.signum, cb);
|
MAP_addTypedKey(&TS.vsig.cb_map, cb->un.sig.signum, cb);
|
||||||
|
|
||||||
/* All callbacks are put in the key table */
|
/* All callbacks are put in the key table */
|
||||||
MAP_addTypedKey(&TS.key_map, cb->key, cb);
|
MAP_addTypedKey(&TS.key_map, cb->key, cb);
|
||||||
|
@ -512,7 +524,6 @@ ES_unregister (int key)
|
||||||
{
|
{
|
||||||
if(TS.tid != pthread_self()) initialize();
|
if(TS.tid != pthread_self()) initialize();
|
||||||
|
|
||||||
// unsigned i;
|
|
||||||
Cb *cb = MAP_findTypedItem(&TS.key_map, key);
|
Cb *cb = MAP_findTypedItem(&TS.key_map, key);
|
||||||
if(!cb) return -1;
|
if(!cb) return -1;
|
||||||
|
|
||||||
|
@ -545,7 +556,7 @@ ES_unregister (int key)
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ES_VSIG_TYPE:
|
case ES_VSIG_TYPE:
|
||||||
if(!MAP_removeSpecificTypedItem(&TS.vsig.map, cb->un.sig.signum, cb)) assert(0);
|
if(!MAP_removeSpecificTypedItem(&TS.vsig.cb_map, cb->un.sig.signum, cb)) assert(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ES_TIMER_TYPE:
|
case ES_TIMER_TYPE:
|
||||||
|
@ -908,30 +919,18 @@ ES_cleanup(void)
|
||||||
/* Remove ourself from the vsig thread to TS map */
|
/* Remove ourself from the vsig thread to TS map */
|
||||||
ez_pthread_mutex_lock(&S.vsig.mtx);
|
ez_pthread_mutex_lock(&S.vsig.mtx);
|
||||||
MAP_removeTypedItem(&S.vsig.thrd_ts_map, TS.tid);
|
MAP_removeTypedItem(&S.vsig.thrd_ts_map, TS.tid);
|
||||||
|
ez_pthread_mutex_unlock(&S.vsig.mtx);
|
||||||
|
|
||||||
{ /* Destroy key map */
|
/* Destroy all callbacks, which are indexed in key map,
|
||||||
unsigned len= MAP_numItems(&TS.key_map);
|
* and the key map itself.
|
||||||
Cb *cbArr[len];
|
*/
|
||||||
MAP_fetchAllItems(&TS.key_map, (void**)cbArr);
|
MAP_clearAndDestroy(&TS.key_map, (void*(*)(void*))Cb_destructor);
|
||||||
for(unsigned i= 0; i < len; ++i) {
|
|
||||||
Cb_destroy(cbArr[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
MAP_destructor(&TS.key_map);
|
/* Destroy vsignal infrastructure */
|
||||||
}
|
MAP_destructor(&TS.vsig.cb_map);
|
||||||
|
|
||||||
{ /* Destroy vsignal infrastructure */
|
/* Tear down the message queue */
|
||||||
unsigned len= MAP_numItems(&TS.vsig.map);
|
MSGQUEUE_destructor(&TS.vsig.mq);
|
||||||
Cb *cbArr[len];
|
|
||||||
MAP_fetchAllItems(&TS.vsig.map, (void**)cbArr);
|
|
||||||
for(unsigned i= 0; i < len; ++i) {
|
|
||||||
Cb_destroy(cbArr[i]);
|
|
||||||
}
|
|
||||||
MAP_destructor(&TS.vsig.map);
|
|
||||||
|
|
||||||
/* Tear down the message queue */
|
|
||||||
MSGQUEUE_destructor(&TS.vsig.mq);
|
|
||||||
}
|
|
||||||
|
|
||||||
PTRVEC_destructor(&TS.fd_vec);
|
PTRVEC_destructor(&TS.fd_vec);
|
||||||
PTRVEC_destructor(&TS.timer_vec);
|
PTRVEC_destructor(&TS.timer_vec);
|
||||||
|
@ -939,7 +938,6 @@ ES_cleanup(void)
|
||||||
for(unsigned i= 0; i < NUMSIGS; ++i) {
|
for(unsigned i= 0; i < NUMSIGS; ++i) {
|
||||||
PTRVEC_destructor(TS.sig_vec_arr+i);
|
PTRVEC_destructor(TS.sig_vec_arr+i);
|
||||||
}
|
}
|
||||||
ez_pthread_mutex_unlock(&S.vsig.mtx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
2
pdns.c
2
pdns.c
|
@ -371,7 +371,7 @@ eprintf("thread %u exiting at %f seconds", ndx, (double)ms/1000.);
|
||||||
/* Free resources for this thread */
|
/* Free resources for this thread */
|
||||||
// JDR Wed 04 Dec 2019 11:52:15 AM EST
|
// JDR Wed 04 Dec 2019 11:52:15 AM EST
|
||||||
// This causes a double free() error, so let it leak for now.
|
// This causes a double free() error, so let it leak for now.
|
||||||
// ES_cleanup();
|
ES_cleanup();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue