some fixes
This commit is contained in:
@ -36,6 +36,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include "htcache.h"
|
||||
|
||||
@ -88,6 +89,7 @@ void verify_setupCounterList() {
|
||||
|
||||
|
||||
|
||||
|
||||
struct verify_container_handle_s {
|
||||
cfgl_t *cfg;
|
||||
statCounter_t *statCounter;
|
||||
@ -121,10 +123,30 @@ struct verify_work_handle_s {
|
||||
verify_result_t *result;
|
||||
ht_queue_t *terminator_queue;
|
||||
verify_container_handle_t *vch;
|
||||
|
||||
int whereAreWe1;
|
||||
int whereAreWe2;
|
||||
};
|
||||
|
||||
typedef struct verify_work_handle_s verify_work_handle_t;
|
||||
|
||||
/* --- debugging ------------------------------------- */
|
||||
verify_work_handle_t *lastVerifyWorkHandle = NULL;
|
||||
void showLastVerifyWorkHandleDetails(int signum) {
|
||||
printf("showLastVerifyWorkHandleDetails:\n");
|
||||
printf(" address: %p\n, lastVerifyWorkHandle");
|
||||
if (lastVerifyWorkHandle != NULL) {
|
||||
printf(" debug step: %d\n", lastVerifyWorkHandle->whereAreWe1);
|
||||
printf(" debug sub step: %d\n", lastVerifyWorkHandle->whereAreWe2);
|
||||
}
|
||||
}
|
||||
#define DEBUG_INSTALL do { signal(SIGUSR2, showLastVerifyWorkHandleDetails); } while(0)
|
||||
#define DEBUG_INIT do { lastVerifyWorkHandle->whereAreWe1 = 0; lastVerifyWorkHandle->whereAreWe2 = 0; } while(0)
|
||||
#define DEBUG_SUB_STEP_RESET do {lastVerifyWorkHandle->whereAreWe2 = 0; } while(0)
|
||||
#define DEBUG_STEP do { lastVerifyWorkHandle->whereAreWe1++; } while(0)
|
||||
#define DEBUG_SUB_STEP do { lastVerifyWorkHandle->whereAreWe2++; } while(0)
|
||||
/* --------------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
struct checker_thread_s {
|
||||
@ -257,6 +279,8 @@ int verify_work_setup(void *handle, void **work_handle) {
|
||||
vwh->vch = (verify_container_handle_t*)handle;
|
||||
|
||||
*work_handle = vwh;
|
||||
|
||||
DEBUG_INSTALL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -408,6 +432,8 @@ int verify_work(void *handle, void *work_handle, char *input, htbuffer_t *output
|
||||
verify_work_handle_t *vwh = (verify_work_handle_t*) work_handle;
|
||||
struct timespec ts;
|
||||
|
||||
lastVerifyWorkHandle = vwh;
|
||||
DEBUG_INIT;
|
||||
|
||||
syslog(LOG_DEBUG, "verify (%p) verify_work: going to verify %s\n", vwh, input);
|
||||
|
||||
@ -429,30 +455,48 @@ int verify_work(void *handle, void *work_handle, char *input, htbuffer_t *output
|
||||
wt->checker_cnt = 0;
|
||||
wt->vwh = work_handle;
|
||||
|
||||
DEBUG_STEP; // 1
|
||||
|
||||
syslog(LOG_DEBUG, "verify (%p) verify_work: going to start worker thread, id=%d",
|
||||
vwh, vwh->id);
|
||||
DEBUG_STEP; // 2
|
||||
|
||||
pthread_mutex_lock(vwh->result_mutex);
|
||||
DEBUG_STEP; // 3
|
||||
err = pthread_create(&tid, NULL, &worker_thread, wt);
|
||||
DEBUG_STEP; // 4
|
||||
if (-1 == err) {
|
||||
incStatCounter(vwh->vch->statCounter, STAT_CNT_VERIFIER_WORKER_THREADS_FAILED);
|
||||
free(wt->input);
|
||||
free(wt);
|
||||
PERM_NOK_RETURN("unable to create worker thread");
|
||||
}
|
||||
DEBUG_STEP; // 5
|
||||
|
||||
|
||||
syslog(LOG_DEBUG, "verify (%p) verify_work: waiting for result", vwh);
|
||||
ts.tv_sec = time(0) + vch->timeout_result;
|
||||
ts.tv_nsec = 0;
|
||||
DEBUG_STEP; // 6
|
||||
|
||||
err = pthread_cond_timedwait(vwh->result_cond, vwh->result_mutex, &ts);
|
||||
DEBUG_STEP; // 7
|
||||
pthread_mutex_unlock(vwh->result_mutex);
|
||||
DEBUG_STEP; // 8
|
||||
if (ETIMEDOUT == err) {
|
||||
incStatCounter(vwh->vch->statCounter, STAT_CNT_VERIFIER_WORKER_THREADS_TIMEOUT);
|
||||
TEMP_NOK_RETURN("worker thread timed out");
|
||||
}
|
||||
DEBUG_STEP; // 9
|
||||
|
||||
|
||||
// snprintf(output, ANSWER_BUFSIZE, vwh->result->output);
|
||||
htbuffer_strcpy(output, vwh->result->output);
|
||||
DEBUG_STEP; // 10
|
||||
|
||||
free(vwh->result->output);
|
||||
DEBUG_STEP; // 11
|
||||
|
||||
return vwh->result->result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user