changes, more debugging

This commit is contained in:
whottgen
2004-10-12 14:51:51 +00:00
parent d56117cbb3
commit 9403e7c8ac
5 changed files with 401 additions and 49 deletions

View File

@ -226,12 +226,13 @@ int verify_work_destroy(void *handle, void *work_handle) {
checker_thread_t *ct;
int cnt, cnt2, err;
syslog(LOG_DEBUG, "verify_work_destroy: was %d times used", vwh->id);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy: was %d times used", work_handle, vwh->id);
/* The terminator_queue must be drained until id_counter is zero again */
cnt = vwh->id;
while (cnt != 0) {
syslog(LOG_DEBUG, "verify_work_destroy, %d thread in queue, waiting for it", cnt);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy, %d thread in queue, waiting for it",
work_handle, cnt);
wt = (worker_thread_t*) queue_get_wait(vwh->terminator_queue);
cnt2 = wt->checker_cnt;
@ -240,7 +241,8 @@ int verify_work_destroy(void *handle, void *work_handle) {
/* clean up the checker stuff */
pthread_join(ct->thread, NULL);
syslog(LOG_DEBUG, "verify_work_destroy, checker_thread (id=%d) joined", ct->id);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy, checker_thread (id=%d) joined",
work_handle, ct->id);
free(ct->output);
free(ct);
@ -249,7 +251,8 @@ int verify_work_destroy(void *handle, void *work_handle) {
}
err = pthread_join(wt->thread, NULL);
syslog(LOG_DEBUG, "verify_work_destroy, worker_thread (id=%d) joined", wt->id);
syslog(LOG_DEBUG, "verify (%p) verify_work_destroy, worker_thread (id=%d) joined",
work_handle, wt->id);
free(wt->input);
/* this will always be a pointer to something const or allocated, which
@ -401,11 +404,11 @@ int cache_lookup(verify_container_handle_t *vch, const char* address, int *resul
*/
#define PERM_NOK_RETURN(msg) \
syslog(LOG_ERR, "verify_work: %s", msg); \
syslog(LOG_ERR, "verify (%p) verify_work: %s", vwh, msg); \
snprintf(output, ANSWER_BUFSIZE, "verify_work: %s", msg); \
return SMM_PERM_NOK;
#define TEMP_NOK_RETURN(msg) \
syslog(LOG_ERR, "verify_work: %s", msg); \
syslog(LOG_ERR, "verify (%p) verify_work: %s", vwh, msg); \
snprintf(output, ANSWER_BUFSIZE, "verify_work: %s", msg); \
return SMM_TEMP_NOK;
@ -418,7 +421,7 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
struct timespec ts;
syslog(LOG_DEBUG, "verify_work: going to verify %s\n", input);
syslog(LOG_DEBUG, "verify (%p) verify_work: going to verify %s\n", vwh, input);
vwh->id += 1;
@ -438,7 +441,8 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
wt->checker_cnt = 0;
wt->vwh = work_handle;
syslog(LOG_DEBUG, "verify_work: going to start worker thread, id=%d", vwh->id);
syslog(LOG_DEBUG, "verify (%p) verify_work: going to start worker thread, id=%d",
vwh, vwh->id);
err = pthread_create(&tid, NULL, &worker_thread, wt);
if (-1 == err) {
free(wt->input);
@ -446,7 +450,7 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
PERM_NOK_RETURN("unable to create worker thread");
}
syslog(LOG_DEBUG, "verify_work: waiting for result");
syslog(LOG_DEBUG, "verify (%p) verify_work: waiting for result", vwh);
pthread_mutex_lock(vwh->result_mutex);
ts.tv_sec = time(0) + vch->timeout_result;
ts.tv_nsec = 0;
@ -522,7 +526,8 @@ static void *checker_thread(void *arg) {
syslog(LOG_DEBUG, "checker_thread (id=%d) started, %08x %s", ct->id, ct->ip_address, ct->email_address);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d) started, %08x %s",
ct->vwh, ct->id, ct->ip_address, ct->email_address);
ct->thread = pthread_self();
@ -535,7 +540,8 @@ static void *checker_thread(void *arg) {
while ((END != state) && (0 == done)) {
syslog(LOG_DEBUG, "checker_thread (id=%d), smtp dialog state %d", ct->id, state);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d), smtp dialog state %d",
ct->vwh, ct->id, state);
switch(state) {
case CONNECT:
err = smtp_connect(smtp);
@ -567,7 +573,8 @@ static void *checker_thread(void *arg) {
switch(err) {
case SMTP_TIMEOUT:
syslog(LOG_DEBUG, "checker_thread (id=%d), timeout in smtp dialog", ct->id);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d), timeout in smtp dialog",
ct->vwh, ct->id);
ct->result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)TIMEOUT_ERROR;
done = 1;
@ -576,13 +583,15 @@ static void *checker_thread(void *arg) {
/* evaluate smtp_response, return or continue */
err = smtp_response(smtp, &response_text);
if (-1 == err) {
syslog(LOG_DEBUG, "checker_thread (id=%d), response could not be parsed", ct->id);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d), response could not be parsed",
ct->vwh, ct->id);
ct->result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)UNEXPECTED_ERROR;
done = 1;
break;
}
syslog(LOG_DEBUG, "checker_thread (id=%d), response: %d, %s (%d)", ct->id, err, response_text, strlen(response_text));
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d), response: %d, %s (%d)",
ct->vwh, ct->id, err, response_text, strlen(response_text));
switch(err/100) {
case 4:
ct->result = SMM_LOCAL_TEMP_NOK;
@ -602,7 +611,8 @@ static void *checker_thread(void *arg) {
}
break;
default:
syslog(LOG_DEBUG, "checker_thread (id=%d), unexpected error in smtp dialog", ct->id);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d), unexpected error in smtp dialog",
ct->vwh, ct->id);
ct->result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)UNEXPECTED_ERROR;
done = 1;
@ -617,7 +627,8 @@ static void *checker_thread(void *arg) {
smtp_destroy(smtp);
syslog(LOG_DEBUG, "checker_thread (id=%d) goes to terminator queue", ct->id);
syslog(LOG_DEBUG, "verify (%p) checker_thread (id=%d) goes to terminator queue",
ct->vwh, ct->id);
queue_put(ct->checker_terminator_queue, ct);
}
@ -638,7 +649,8 @@ static void *worker_thread(void *arg) {
static const char *NO_MX_AVAILABLE = "no MX available";
static const char *NO_PERM_RESULT = "no checker returned permanent result";
syslog(LOG_DEBUG, "worker_thread %d started, %s", wt->id, wt->input);
syslog(LOG_DEBUG, "verify (%p) worker_thread %d started, %s",
wt->vwh, wt->id, wt->input);
wt->thread = pthread_self();
@ -652,13 +664,14 @@ static void *worker_thread(void *arg) {
result = SMM_LOCAL_PERM_NOK;
} else {
if (0 == cache_lookup(wt->vwh->vch, wt->input, &result, &cached_output)) {
syslog(LOG_DEBUG, "worker_thread: got a cached result for %s -> %d, %s",
wt->input, result, cached_output);
syslog(LOG_DEBUG, "verify (%p) worker_thread: got a cached result for %s -> %d, %s",
wt->vwh, wt->input, result, cached_output);
wt->output = cached_output;
} else {
domain_part += 1;
syslog(LOG_DEBUG, "worker_thread: looking up %s", domain_part);
syslog(LOG_DEBUG, "verify (%p) worker_thread: looking up %s",
wt->vwh, domain_part);
mx_ip_addresses = get_mx_ip_addresses(domain_part);
if (NULL == mx_ip_addresses) {
@ -667,7 +680,8 @@ static void *worker_thread(void *arg) {
} else {
for (i = 0; (*(mx_ip_addresses+i) != 0) && (i < wt->vwh->vch->max_checker_threads); i++) {
unsigned int address = *(mx_ip_addresses+i);
syslog(LOG_DEBUG, "worker_thread: starting checker thread to %d.%d.%d.%d, for email-address %s",
syslog(LOG_DEBUG, "verify (%p) worker_thread: starting checker thread to %d.%d.%d.%d, for email-address %s",
wt->vwh,
(address&0xff000000)>>24, (address&0x00ff0000)>>16,
(address&0x0000ff00)>>8, (address&0x000000ff),
wt->input);
@ -683,7 +697,7 @@ static void *worker_thread(void *arg) {
err = pthread_create(&tid, NULL, &checker_thread, ct);
if (-1 == err) {
syslog(LOG_ERR, "worker_thread: unable to create checker thread");
syslog(LOG_ERR, "verify (%p) worker_thread: unable to create checker thread", wt->vwh);
free(ct);
} else {
wt->checker_cnt += 1;
@ -695,17 +709,18 @@ static void *worker_thread(void *arg) {
while (wt->checker_cnt > 0) {
ct = (checker_thread_t*) queue_get_wait(wt->checker_terminator_queue);
wt->checker_cnt -= 1;
syslog(LOG_DEBUG, "worker_thread: got checker result for %d.%d.%d.%d: %s -> %d, %s",
syslog(LOG_DEBUG, "verify (%p) worker_thread: got checker result for %d.%d.%d.%d: %s -> %d, %s",
wt->vwh,
((ct->ip_address)&0xff000000)>>24, ((ct->ip_address)&0x00ff0000)>>16,
((ct->ip_address)&0x0000ff00)>>8, ((ct->ip_address)&0x000000ff),
wt->input, ct->result, ct->output);
pthread_join(ct->thread, NULL);
syslog(LOG_DEBUG, "worker_thread: checker thread joined");
syslog(LOG_DEBUG, "verify (%p) worker_thread: checker thread joined", wt->vwh);
if ((SMM_LOCAL_TEMP_NOK != ct->result) &&
(SMM_TEMP_NOK != ct->result)) {
syslog(LOG_DEBUG, "worker_thread: this is a permanent result, returning");
syslog(LOG_DEBUG, "verify (%p) worker_thread: this is a permanent result, returning", wt->vwh);
wt->output = ct->output;
result = ct->result;
cache_insert(wt->vwh->vch, wt->input, ct->result, ct->output);
@ -713,7 +728,8 @@ static void *worker_thread(void *arg) {
break; /* exit from the ct-collecting while loop, leave the rest of the ct's
for the cleanup */
} else {
syslog(LOG_DEBUG, "worker_thread: this is a temporary result, continue to wait");
syslog(LOG_DEBUG, "verify (%p) worker_thread: this is a temporary result, continue to wait",
wt->vwh);
wt->output = (char*) NO_PERM_RESULT;
result = SMM_LOCAL_TEMP_NOK;
/* we've collected the ct but its output is not longer need, so free it here */
@ -728,10 +744,11 @@ static void *worker_thread(void *arg) {
/* -------------------------------------------------------------------- */
syslog(LOG_DEBUG, "worker_thread %d waiting for mutex", wt->id);
syslog(LOG_DEBUG, "verify (%p) worker_thread %d waiting for mutex",
wt->vwh, wt->id);
pthread_mutex_lock(wt->mutex);
if (wt->result->id == wt->id) {
syslog(LOG_DEBUG, "worker_thread %d returned result", wt->id);
syslog(LOG_DEBUG, "verify (%p) worker_thread %d returned result", wt->vwh, wt->id);
/* we can write the result */
wt->result->output = (char*) malloc(sizeof(char) * (strlen(wt->output)+15)); /* enough for the output
plus <><> and prefix */
@ -756,7 +773,7 @@ static void *worker_thread(void *arg) {
wt->result->result = result;
pthread_cond_signal(wt->cond);
} else {
syslog(LOG_DEBUG, "worker_thread %d drops result", wt->id);
syslog(LOG_DEBUG, "verify (%p) worker_thread %d drops result", wt->vwh, wt->id);
/* result not longer interested */
}
pthread_mutex_unlock(wt->mutex);
@ -775,7 +792,8 @@ static void *worker_thread(void *arg) {
free(cached_output);
}
syslog(LOG_DEBUG, "worker_thread %d goes to terminator queue", wt->id);
syslog(LOG_DEBUG, "verify (%p) worker_thread %d goes to terminator queue",
wt->vwh, wt->id);
queue_put(wt->terminator_queue, wt);
}