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

@ -45,6 +45,7 @@ struct cyrus_container_handle_s {
typedef struct cyrus_container_handle_s cyrus_container_handle_t; typedef struct cyrus_container_handle_s cyrus_container_handle_t;
struct cyrus_work_handle_s { struct cyrus_work_handle_s {
int id; int id;
cyrus_container_handle_t *cch; cyrus_container_handle_t *cch;
@ -56,18 +57,18 @@ typedef struct cyrus_work_handle_s cyrus_work_handle_t;
int cyrus_init(cfgl_t *cfg, void **handle); int cyrus_init(cfgl_t *cfg, void **handle);
int cyrus_destroy(void *handle); int cyrus_destroy(void *handle);
/* int cyrus_work_setup(void *handle, void **work_handle); */ /* int cyrus_work_setup(void *handle, void **work_handle); */
int cyrus_work(void *handle, void *work_handle, char *input, char *output); int cyrus_work(void *handle, void *work_handle, char *input, char *output);
/* int cyrus_work_destroy(void *handle, void *work_handle); */ /* int cyrus_work_destroy(void *handle, void *work_handle); */
class_descriptor_t cyruscheck = { class_descriptor_t cyruscheck = {
"cyruscheck", "cyruscheck",
&cyrus_init, &cyrus_init,
&cyrus_destroy, &cyrus_destroy,
NULL, /* &verify_work_setup, */ NULL, /* &cyrus_work_setup, */
&cyrus_work, &cyrus_work,
NULL /* &cyrus_work_destroy */ NULL /* &cyrus_work_destroy */
}; };
@ -94,6 +95,8 @@ int cyrus_destroy(void *handle) {
} }
int cyrus_work(void *handle, void *work_handle, char *input, char *output) { int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
static const char *DEFAULT_ANSWER = "default answer"; static const char *DEFAULT_ANSWER = "default answer";
static const char *ILLEGAL_INPUT = "illegal input (must be 'depot_uid depot_host')"; static const char *ILLEGAL_INPUT = "illegal input (must be 'depot_uid depot_host')";
@ -102,6 +105,8 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
static const char *GO_AHEAD = "go ahead"; static const char *GO_AHEAD = "go ahead";
static const char *DEPOT_DNS_ERROR = "depot could not be found in dns"; static const char *DEPOT_DNS_ERROR = "depot could not be found in dns";
static int log_id = 0;
cyrus_container_handle_t *cch = (cyrus_container_handle_t*) handle; cyrus_container_handle_t *cch = (cyrus_container_handle_t*) handle;
int result = SMM_TEMP_NOK; int result = SMM_TEMP_NOK;
char *depot_uid, *depot_host, *response_text, *tmp_arg; char *depot_uid, *depot_host, *response_text, *tmp_arg;
@ -115,8 +120,9 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
} state = CONNECT; } state = CONNECT;
log_id++;
syslog(LOG_DEBUG, "cyrus_work: (%p) going to check %s", work_handle, input); syslog(LOG_DEBUG, "cyrus_work: (%04x) going to check %s", log_id, input);
depot_uid = input; depot_uid = input;
if (NULL == (depot_host = strchr(depot_uid, ' '))) { if (NULL == (depot_host = strchr(depot_uid, ' '))) {
@ -130,8 +136,8 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
a_rdata = get_a_rrs(depot_host); a_rdata = get_a_rrs(depot_host);
if (NULL == a_rdata) { if (NULL == a_rdata) {
syslog(LOG_DEBUG, "cyrus_work: (%p) depot_host %s could not be found in dns", syslog(LOG_DEBUG, "cyrus_work: (%04x) depot_host %s could not be found in dns",
work_handle, depot_host); log_id, depot_host);
snprintf(output, ANSWER_BUFSIZE, DEPOT_DNS_ERROR); snprintf(output, ANSWER_BUFSIZE, DEPOT_DNS_ERROR);
return SMM_TEMP_NOK; return SMM_TEMP_NOK;
} }
@ -140,14 +146,14 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
free_rrs((void**)a_rdata); free_rrs((void**)a_rdata);
syslog(LOG_DEBUG, "cyrus_work: (%p) depot_uid %s, depot_host %s", work_handle, syslog(LOG_DEBUG, "cyrus_work: (%04x) depot_uid %s, depot_host %s", log_id,
depot_uid, depot_host); depot_uid, depot_host);
lmtp = smtp_init(ip_address, cch->lmtp_port, cch->timeout); lmtp = smtp_init(ip_address, cch->lmtp_port, cch->timeout);
while ((END != state) && (0 == done)) { while ((END != state) && (0 == done)) {
syslog(LOG_DEBUG, "cyrus_work: (%p) lmtp dialog state %d", work_handle, state); syslog(LOG_DEBUG, "cyrus_work: (%04x) lmtp dialog state %d", log_id, state);
switch(state) { switch(state) {
case CONNECT: case CONNECT:
err = smtp_connect(lmtp); err = smtp_connect(lmtp);
@ -179,7 +185,7 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
switch(err) { switch(err) {
case SMTP_TIMEOUT: case SMTP_TIMEOUT:
syslog(LOG_DEBUG, "cyrus_work: (%p) timeout in lmtp dialog", work_handle); syslog(LOG_DEBUG, "cyrus_work: (%04x) timeout in lmtp dialog", log_id);
result = SMM_LOCAL_TEMP_NOK; result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)TIMEOUT_ERROR; response_text = (char*)TIMEOUT_ERROR;
done = 1; done = 1;
@ -188,13 +194,13 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
/* evaluate smtp_response, return or continue */ /* evaluate smtp_response, return or continue */
err = smtp_response(lmtp, &response_text); err = smtp_response(lmtp, &response_text);
if (-1 == err) { if (-1 == err) {
syslog(LOG_DEBUG, "cyrus_work: (%p) response could not be parsed", work_handle); syslog(LOG_DEBUG, "cyrus_work: (%04x) response could not be parsed", log_id);
result = SMM_LOCAL_TEMP_NOK; result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)UNEXPECTED_ERROR; response_text = (char*)UNEXPECTED_ERROR;
done = 1; done = 1;
break; break;
} }
syslog(LOG_DEBUG, "cyrus_work: (%p) response: %d, %s", work_handle, syslog(LOG_DEBUG, "cyrus_work: (%04x) response: %d, %s", log_id,
err, response_text); err, response_text);
switch(err/100) { switch(err/100) {
case 4: case 4:
@ -215,7 +221,7 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
} }
break; break;
default: default:
syslog(LOG_DEBUG, "cyrus_work: (%p) unexpected error in lmtp dialog", work_handle); syslog(LOG_DEBUG, "cyrus_work: (%04x) unexpected error in lmtp dialog", log_id);
result = SMM_LOCAL_TEMP_NOK; result = SMM_LOCAL_TEMP_NOK;
response_text = (char*)UNEXPECTED_ERROR; response_text = (char*)UNEXPECTED_ERROR;
done = 1; done = 1;
@ -246,7 +252,7 @@ int cyrus_work(void *handle, void *work_handle, char *input, char *output) {
smtp_destroy(lmtp); smtp_destroy(lmtp);
syslog(LOG_DEBUG, "cyrus_work: (%p) result %d, %s", work_handle, syslog(LOG_DEBUG, "cyrus_work: (%04x) result %d, %s", log_id,
result, output); result, output);
return result; return result;

325
smmapdfw/doc/Makefile.in Normal file
View File

@ -0,0 +1,325 @@
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
AR = @AR@
AS = @AS@
BDB_LIBS = @BDB_LIBS@
CC = @CC@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
GCJ = @GCJ@
GCJFLAGS = @GCJFLAGS@
HAVE_LIB = @HAVE_LIB@
LIB = @LIB@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIB = @LTLIB@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
RC = @RC@
STRIP = @STRIP@
VERSION = @VERSION@
info_TEXINFOS = smmapdfw.texi
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
CONFIG_CLEAN_FILES =
TEXI2DVI = texi2dvi
INFO_DEPS = smmapdfw.info
DVIS = smmapdfw.dvi
TEXINFOS = smmapdfw.texi
DIST_COMMON = README Makefile.am Makefile.in texinfo.tex
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
.SUFFIXES: .dvi .info .ps .texi .texinfo .txi
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
smmapdfw.info: smmapdfw.texi
smmapdfw.dvi: smmapdfw.texi
DVIPS = dvips
.texi.info:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texi.dvi:
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.texi:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texinfo.info:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texinfo:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.texinfo.dvi:
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.txi.info:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.txi.dvi:
TEXINPUTS=.:$$TEXINPUTS \
MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
.txi:
@cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
cd $(srcdir) \
&& $(MAKEINFO) `echo $< | sed 's,.*/,,'`
.dvi.ps:
$(DVIPS) $< -o $@
install-info-am: $(INFO_DEPS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(infodir)
@list='$(INFO_DEPS)'; \
for file in $$list; do \
d=$(srcdir); \
for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9]`; do \
if test -f $$d/$$ifile; then \
echo " $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile"; \
$(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile; \
else : ; fi; \
done; \
done
@$(POST_INSTALL)
@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
list='$(INFO_DEPS)'; \
for file in $$list; do \
echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";\
install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;\
done; \
else : ; fi
uninstall-info:
$(PRE_UNINSTALL)
@if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
ii=yes; \
else ii=; fi; \
list='$(INFO_DEPS)'; \
for file in $$list; do \
test -z "$$ii" \
|| install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file; \
done
@$(NORMAL_UNINSTALL)
list='$(INFO_DEPS)'; \
for file in $$list; do \
(cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9]); \
done
dist-info: $(INFO_DEPS)
list='$(INFO_DEPS)'; \
for base in $$list; do \
d=$(srcdir); \
for file in `cd $$d && eval echo $$base*`; do \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file; \
done; \
done
mostlyclean-aminfo:
-rm -f smmapdfw.aux smmapdfw.cp smmapdfw.cps smmapdfw.dvi smmapdfw.fn \
smmapdfw.fns smmapdfw.ky smmapdfw.kys smmapdfw.ps \
smmapdfw.log smmapdfw.pg smmapdfw.toc smmapdfw.tp \
smmapdfw.tps smmapdfw.vr smmapdfw.vrs smmapdfw.op smmapdfw.tr \
smmapdfw.cv smmapdfw.cn
clean-aminfo:
distclean-aminfo:
maintainer-clean-aminfo:
cd $(srcdir) && for i in $(INFO_DEPS); do \
rm -f $$i; \
if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then \
rm -f $$i-[0-9]*; \
fi; \
done
tags: TAGS
TAGS:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = doc
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu doc/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
$(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info
info-am: $(INFO_DEPS)
info: info-am
dvi-am: $(DVIS)
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am: install-info-am
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-info
uninstall: uninstall-am
all-am: Makefile $(INFO_DEPS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(infodir)
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-aminfo mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-aminfo clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-aminfo distclean-generic clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-aminfo maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: install-info-am uninstall-info mostlyclean-aminfo \
distclean-aminfo clean-aminfo maintainer-clean-aminfo tags distdir \
info-am info dvi-am dvi check check-am installcheck-am installcheck \
install-exec-am install-exec install-data-am install-data install-am \
install uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@ -28,6 +28,7 @@
#include <syslog.h> #include <syslog.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h> #include <strings.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
@ -166,7 +167,8 @@ static void** get_rrs(char *domain, int qtype) {
res = res_search(domain, C_IN, qtype, (u_char*) &answer, sizeof(answer_t)); res = res_search(domain, C_IN, qtype, (u_char*) &answer, sizeof(answer_t));
if (-1 == res) { if (-1 == res) {
syslog(LOG_ERR, "get_rrs: error in res_search: h_errno=%d, errno=%d", h_errno, errno); syslog(LOG_ERR, "get_rrs: error in res_search: h_errno=%d, errno=%d, (%s)",
h_errno, errno, strerror(errno));
return NULL; return NULL;
} }

View File

@ -273,15 +273,16 @@ int server() {
syslog(LOG_DEBUG, "server: Got a connection %d", clientSock); syslog(LOG_DEBUG, "server: Got a connection %d", clientSock);
if (-1 == clientSock) { if (-1 == clientSock) {
syslog(LOG_ERR, "server: failure when accepting connection"); syslog(LOG_ERR, "server: failure when accepting connection: %d, %s",
return -1; errno, strerror(errno));
continue;
} }
thread = (networkerThread_t *) malloc(sizeof(networkerThread_t)+10); thread = (networkerThread_t *) malloc(sizeof(networkerThread_t)+10);
if (NULL == thread) { if (NULL == thread) {
syslog(LOG_ERR, "server: unable to alloc memory for networker"); syslog(LOG_ERR, "server: unable to alloc memory for networker");
break; continue;
} }
@ -296,7 +297,7 @@ int server() {
syslog(LOG_ERR, "server: unable to start networker thread"); syslog(LOG_ERR, "server: unable to start networker thread");
free(thread); free(thread);
count_dec(&thread_counter); count_dec(&thread_counter);
break; continue;
} }
} }

View File

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