some fixes

This commit is contained in:
whottgen 2006-09-18 20:51:31 +00:00
parent 3690534459
commit 5a26ac47f4
11 changed files with 3689 additions and 3926 deletions

1681
smmapdfw/aclocal.m4 vendored

File diff suppressed because it is too large Load Diff

592
smmapdfw/config.guess vendored

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,6 @@
/* enable Net-SNMP */
#undef ENABLE_NETSNMP
/* enable stats */
#undef ENABLE_STATS
/* Define to 1 if you have the <arpa/inet.h> header file. */
#undef HAVE_ARPA_INET_H
@ -174,10 +171,8 @@
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
/* Define to `unsigned' if <sys/types.h> does not define. */
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define as `fork' if `vfork' does not work. */
#undef vfork

5205
smmapdfw/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -170,15 +170,6 @@ dnl (default=no)])],
dnl cyrus_BUILD=libcyrus_worker.la
dnl )
ENABLE_STATS=0
AC_ARG_ENABLE(stats,
[AC_HELP_STRING(--enable-stats, [
Enables statistics collection.
(default=no)])],
if test "x$enableval" = xyes; then ENABLE_STATS=1; fi
if test "x$enableval" = xno; then ENABLE_STATS=0; fi
)
# Checks for programs.
AC_PROG_CC
@ -266,7 +257,6 @@ if test "x$BDB_NOT_FOUND" = "x1"; then
fi
AC_DEFINE_UNQUOTED(ENABLE_CACHE, ${ENABLE_CACHE}, [enable cache])
AC_DEFINE_UNQUOTED(ENABLE_STATS, ${ENABLE_STATS}, [enable stats])
AC_DEFINE_UNQUOTED(ENABLE_NETSNMP, ${ENABLE_NETSNMP}, [enable Net-SNMP])

View File

@ -1,4 +1,4 @@
include_HEADERS=containers_public.h queue.h smtp.h cfg.h count.h safe_write.h sunos_comp.h htdns.h smmapd.h htmalloc.h stats.h htcache.h htbuffer.h
include_HEADERS=containers_public.h queue.h smtp.h cfg.h count.h safe_write.h sunos_comp.h htdns.h smmapd.h htmalloc.h stats.h htcache.h htbuffer.h dvl.h
lib_LTLIBRARIES = libsmmapdfw.la
libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c htbuffer.c
libsmmapdfw_la_LIBADD = @BDB_LIBS@

View File

@ -87,7 +87,7 @@ RC = @RC@
STRIP = @STRIP@
VERSION = @VERSION@
include_HEADERS = containers_public.h queue.h smtp.h cfg.h count.h safe_write.h sunos_comp.h htdns.h smmapd.h htmalloc.h stats.h htcache.h htbuffer.h
include_HEADERS = containers_public.h queue.h smtp.h cfg.h count.h safe_write.h sunos_comp.h htdns.h smmapd.h htmalloc.h stats.h htcache.h htbuffer.h dvl.h
lib_LTLIBRARIES = libsmmapdfw.la
libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c htbuffer.c
libsmmapdfw_la_LIBADD = @BDB_LIBS@

View File

@ -102,18 +102,21 @@ int containers_dispatcher(container_handle_t *ch, char *input, htbuffer_t *outpu
int result, err;
worker_handle_t *wh, *wh_last, *wh2;
if (input == NULL) {
syslog(LOG_ERR, "dispatcher: no input at all");
return SMM_ILLEGAL_INPUT;
}
syslog(LOG_DEBUG, "dispatcher: input: %s", input);
data = strchr(input, ' ');
if (NULL == data) {
if (NULL == data || (strlen(data) < 1)) {
syslog(LOG_ERR, "dispatcher: illegal input (%s)", input);
return SMM_ILLEGAL_INPUT;
}
data++; /* skip the blank */
*data = '\0'; /* terminate class */
data++; /* skip the former blank, now null */
class = input;
class[strlen(class)-strlen(data)-1] = '\0';
syslog(LOG_DEBUG, "dispatcher: class: %s, data: %s", class, data);

View File

@ -73,6 +73,7 @@
#include "sunos_comp.h"
#include "dvl.h"
#define CFG_SECTION_GLOBAL "global"
#define CFG_NAME_ADDRESS "address"
@ -129,20 +130,20 @@ typedef struct networkerThread_s networkerThread_t;
ht_queue_t terminated_networker_queue;
pthread_t cleanerThread;
#if ENABLE_STATS==1
pthread_t statsThread;
#endif
#if ENABLE_NETSNMP==1
pthread_t snmpThread;
#endif
count_t thread_counter;
cfg_t *cfg;
int netstring_disabled = 0;
#if ENABLE_STATS==1
void * statser(void * arg) {
int stdout_nice = atoi(findcfgx(cfg, "stats", "stdout_nice", "0"));
int syslog_nice = atoi(findcfgx(cfg, "stats", "syslog_nice", "0"));
@ -153,7 +154,6 @@ void * statser(void * arg) {
sleep(period);
}
}
#endif
#if ENABLE_NETSNMP==1
void * snmper(void * arg) {
@ -191,6 +191,10 @@ void * cleaner(void * arg) {
#define OUTPUT_BUFSIZE ANSWER_BUFSIZE+25 /* a bit more than answer for the result text */
void * networker(void * arg) {
if (arg == NULL) {
syslog(LOG_CRIT, "networker thread started with argument NULL, thread dies");
return NULL;
}
char buffer[BUFSIZE+1];
char *input;
@ -206,6 +210,7 @@ void * networker(void * arg) {
networkerThread_t * thread = (networkerThread_t *) arg;
thread->pthread = pthread_self();
incStatCounter(globalStatCounter, STAT_CNT_NETWORKER_THREADS);
@ -232,17 +237,23 @@ void * networker(void * arg) {
input = buffer;
} else {
len = strtol(buffer, &input, 10);
if ((0 == len) && (buffer == input)) {
syslog(LOG_DEBUG, "networker: netstring unparsable, no length found: %s", buffer);
if (input == NULL) {
syslog(LOG_ERR, "networker:netstring unparsable, nothing remains after length");
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else if ((0 == len) && (buffer == input)) {
syslog(LOG_ERR, "networker: netstring unparsable, no length found: %s", dvls(buffer));
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else if (*input++ != ':') {
syslog(LOG_DEBUG, "networker: netstring unparsable, no colon found: %s", buffer);
syslog(LOG_ERR, "networker: netstring unparsable, no colon found: %s", dvls(buffer));
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else if (input == NULL) {
syslog(LOG_ERR, "networker:netstring unparsable, nothing remains after colon");
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else if (strlen(input)-1 != len) {
syslog(LOG_DEBUG, "networker: netstring unparsable, length does not match: %s", buffer);
syslog(LOG_ERR, "networker: netstring unparsable, length does not match: %s", dvls(buffer));
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else if (input[strlen(input)-1] != ',') {
syslog(LOG_DEBUG, "networker: netstring unparsable, no terminating comma: %s", buffer);
syslog(LOG_ERR, "networker: netstring unparsable, no terminating comma: %s", dvls(buffer));
dispatcher_result = SMM_NETSTRING_UNPARSABLE;
} else {
input[strlen(input)-1] = '\0'; /* strip off the comma */
@ -250,10 +261,9 @@ void * networker(void * arg) {
}
if (!dispatcher_result) {
// answer[0] = '\0';
htbuffer_clear(answer);
dispatcher_result = containers_dispatcher(container_handle, input, answer);
syslog(LOG_DEBUG, "networker: dispatcher result: %d, answer: %s", dispatcher_result, answer->buf);
syslog(LOG_DEBUG, "networker: dispatcher result: %d, answer: %s", dispatcher_result, dvls(answer->buf));
}
incStatCounter(globalStatCounter, dispatcher_result + STAT_CNT_OFFSET);
@ -289,7 +299,6 @@ void * networker(void * arg) {
htbuffer_free(answer);
thread->result = 1;
queue_put(&terminated_networker_queue, thread);
}
@ -353,21 +362,34 @@ int server() {
count_init(&thread_counter);
queue_init(&terminated_networker_queue);
pthread_create(&cleanerThread, NULL, &cleaner, NULL);
int cleanerStartRc = pthread_create(&cleanerThread, NULL, &cleaner, NULL);
if (0 != cleanerStartRc) {
syslog(LOG_ERR, "server: failure when starting cleaner thread: %d",
cleanerStartRc);
return -1;
}
#if ENABLE_STATS==1
enableStats = atoi(findcfgx(cfg, "global", "enable_stats", "0"));
if (enableStats) {
syslog(LOG_INFO, "server: starting stats thread");
pthread_create(&statsThread, NULL, &statser, NULL);
int staterStartRc = pthread_create(&statsThread, NULL, &statser, NULL);
if (0 != cleanerStartRc) {
syslog(LOG_ERR, "server: failure when starting stater thread: %d",
staterStartRc);
return -1;
}
}
#endif /* ENABLE_STATS */
#if ENABLE_NETSNMP==1
enableSnmp = atoi(findcfgx(cfg, "global", "enable_snmp", "0"));
if (enableSnmp) {
syslog(LOG_INFO, "server: starting snmp subagent thread");
pthread_create(&snmpThread, NULL, &snmper, NULL);
int snmperStartRc = pthread_create(&snmpThread, NULL, &snmper, NULL);
if (0 != snmperStartRc) {
syslog(LOG_ERR, "server: failure when starting snmper thread: %d",
snmperStartRc);
return -1;
}
}
#endif /* ENABLE_NETSNMP */
@ -486,6 +508,7 @@ int main(int argc, char **argv) {
server_setupCounterList();
globalStatCounter = initStatCounter("global", server_counterDefs);
if (0 != (err = server())) {
syslog(LOG_ERR, "main: server fails: %d", err);
exit(1);

View File

@ -14,10 +14,10 @@ enable_snmp = 1
; netstring_disabled = 1
[snmp]
agentx_socket = /var/agentx/master
agentx_socket = 127.0.0.1:9161
[stats]
stdout_nice = 2
stdout_nice = 0
syslog_nice = 1
period = 1

View File

@ -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;
}