diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-01-24 09:59:39 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-01-24 09:59:39 +0000 |
commit | ebe95af1103dd2552a55fcc5fca58fe1498febbf (patch) | |
tree | 63d148ea5ea1510ba0732665511e37a509f5a191 | |
parent | a55e3ee41c4404d8fbf077c5f4ccfcf673b152a0 (diff) | |
download | mailfromd-ebe95af1103dd2552a55fcc5fca58fe1498febbf.tar.gz mailfromd-ebe95af1103dd2552a55fcc5fca58fe1498febbf.tar.bz2 |
* pmult/pdbg.hm4, pmult/debugdef.m4: New files. Provide serialized
versions of MU_DEBUG macros.
* pmult/pmult.c: Use debugging macros from pdbg.h
Do not protect accesses to p->srvlist by mutexes, they should not
be concurrent anyway.
(pmult_abort): Do not shutdown priv_data.
git-svn-id: file:///svnroot/mailfromd/branches/gmach@1590 7a8a7f39-df28-0410-adc6-e0d955640f24
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | pmult/Makefile.am | 11 | ||||
-rw-r--r-- | pmult/debugdef.m4 | 54 | ||||
-rw-r--r-- | pmult/pdbg.hm4 | 3 | ||||
-rw-r--r-- | pmult/pmult.c | 123 |
5 files changed, 132 insertions, 69 deletions
@@ -1,3 +1,13 @@ +2008-01-24 Sergey Poznyakoff <gray@gnu.org.ua> + + * pmult/pdbg.hm4, pmult/debugdef.m4: New files. Provide serialized + versions of MU_DEBUG macros. + + * pmult/pmult.c: Use debugging macros from pdbg.h + Do not protect accesses to p->srvlist by mutexes, they should not + be concurrent anyway. + (pmult_abort): Do not shutdown priv_data. + 2008-01-22 Sergey Poznyakoff <gray@gnu.org.ua> * mtasim/mtasim.c: Do not use gacopyz_srv_define_macro0. diff --git a/pmult/Makefile.am b/pmult/Makefile.am index 1aaff256..b32888b7 100644 --- a/pmult/Makefile.am +++ b/pmult/Makefile.am @@ -17,6 +17,8 @@ PMULT_PROG = pmult sbin_PROGRAMS = @ENABLE_PMULT@ EXTRA_PROGRAMS = pmult +EXTRA_DIST = pdbg.hm4 debugdef.m4 +BUILT_SOURCES = pdbg.h INCLUDES = \ $(MAILUTILS_INCLUDES)\ @@ -27,10 +29,17 @@ INCLUDES = \ -I../gacopyz\ @META1_INCLUDES@ -pmult_SOURCES = pmult.c +pmult_SOURCES = pmult.c pdbg.h LDADD = \ ../lib/libmf.a\ $(MAILUTILS_LIBS)\ ../gnu/libgnu.a\ $(MILTER)\ @META1_LIBS@ @PTHREAD_LIBRARIES@ + +pdbg.h: $(top_srcdir)/pmult/debugdef.m4 pdbg.hm4 + m4 $(top_srcdir)/pmult/debugdef.m4 pdbg.hm4 > pdbg.h + + + + diff --git a/pmult/debugdef.m4 b/pmult/debugdef.m4 new file mode 100644 index 00000000..7e4a0b6f --- /dev/null +++ b/pmult/debugdef.m4 @@ -0,0 +1,54 @@ +divert(-1) +# This file is part of Mailutils. +# Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. +# +# Initially written by Sergey Poznyakoff for Mailfromd project. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +changecom(/*,*/) + +define(`__arglist',`dnl +ifelse($1,$2,x$1, +`x$1, __arglist(incr($1), $2)')') + +define(`MKDEBUG',` +`#define __PMU_DEBUG'$1`(dbg, lev, fmt, '__arglist(1,$1)) \` + do \ + { \ + pthread_mutex_lock (&pmult_debug_mutex); \ + __MU_DEBUG'$1`(dbg, lev, fmt, '__arglist(1,$1)); `\ + pthread_mutex_unlock (&pmult_debug_mutex); \ + } \ + while (0) + +#define PMU_DEBUG'$1`(dbg, lev, fmt, '__arglist(1,$1)`) \ + do \ + { \ + if (mu_debug_check_level (dbg, lev)) \ + __PMU_DEBUG'$1`(dbg, lev, fmt, '__arglist(1,$1)`); \ + } \ + while(0) +'') + +define(`forloop', + `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')') +define(`_forloop', + `$4`'ifelse($1, `$3', , + `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')') + +divert(0)dnl +/* -*- buffer-read-only: t -*- vi: set ro: + THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. +*/ diff --git a/pmult/pdbg.hm4 b/pmult/pdbg.hm4 new file mode 100644 index 00000000..a19506d4 --- /dev/null +++ b/pmult/pdbg.hm4 @@ -0,0 +1,3 @@ +#include <mailutils/debug.h> +#define PMU_DEBUG(d,l,s) PMU_DEBUG1(d,l,"%s",s) +forloop(`i',1,11,`MKDEBUG(i)') diff --git a/pmult/pmult.c b/pmult/pmult.c index 7fca5f8e..9f922ecb 100644 --- a/pmult/pmult.c +++ b/pmult/pmult.c @@ -49,9 +49,7 @@ const char *mu_umaxtostr (unsigned slot, uintmax_t val); 1 and 2 - Special handling in configure.ac, which requires Meta1 sources to be present; 3 - Using the necessary symbols ASAP and undefining them before - including the pmilter headers; - - Po kiego licha to robie? Bo mam, kurna, popyt! + including the sm/ *.h madness; */ const char *program_version = "pmult (" PACKAGE_STRING ")"; @@ -70,10 +68,13 @@ const char *package_bugreport = "<" PACKAGE_BUGREPORT ">"; #include "sm/pmfdef.h" #include "sm/pmfapi.h" +#include "pdbg.h" + char *portspec; /* Communication socket */ int log_to_stderr; /* Use stderr for logging */ mu_log_level_t debug_level; /* Debug verbosity level */ mu_debug_t pmult_debug; /* Debugging object */ +static pthread_mutex_t pmult_debug_mutex = PTHREAD_MUTEX_INITIALIZER; char *pidfile; /* pidfile name */ int sigthread; /* Handle SIGTERM and SIGHUP in the main thread */ @@ -625,9 +626,9 @@ cb_reply (gacopyz_srv_t gsrv, int cmd, int rcmd, void *data) break; } cp++; - MU_DEBUG4 (p->debug, MU_DEBUG_TRACE2, - "%s=%u '%s','%s'\n", - hdrcommname (rcmd), idx, buf, cp); + PMU_DEBUG4 (p->debug, MU_DEBUG_TRACE2, + "%s=%u '%s','%s'\n", + hdrcommname (rcmd), idx, buf, cp); header = malloc (size + 5); if (!header) @@ -679,52 +680,52 @@ pmult_std_reply (struct pmult_priv_data *p, pmse_ctx_P pmse_ctx, case SMFIR_REPLYCODE: gacopyz_srv_reply (gsrv, &buf, &size); - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, reply=%s", - ident, arg, buf); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, reply=%s", + ident, arg, buf); SM_VERBOSE (sm_pmfi_setreply (pmse_ctx, buf)); return (buf[0] == '4') ? SMTP_R_TEMP : SMTP_R_PERM; case SMFIR_REJECT: - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, reply=%s", - ident, arg, MSG_REJECT); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, reply=%s", + ident, arg, MSG_REJECT); SM_VERBOSE (sm_pmfi_setreply (pmse_ctx, MSG_REJECT)); return SMTP_R_PERM; case SMFIR_DISCARD: - MU_DEBUG2 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, discard", - ident, arg); + PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, discard", + ident, arg); return SMTP_R_DISCARD; case SMFIR_TEMPFAIL: - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, reply=%s", - ident, arg, MSG_TEMPFAIL); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, reply=%s", + ident, arg, MSG_TEMPFAIL); SM_VERBOSE (sm_pmfi_setreply (pmse_ctx, MSG_TEMPFAIL)); return SMTP_R_TEMP; case SMFIR_SHUTDOWN: - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, reply=%s", - ident, arg, MSG_SHUTDOWN); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, reply=%s", + ident, arg, MSG_SHUTDOWN); SM_VERBOSE (sm_pmfi_setreply (pmse_ctx, MSG_SHUTDOWN)); return SMTP_R_SSD; case SMFIR_ADDRCPT: gacopyz_srv_reply (gsrv, &buf, &size); - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, addrcpt=%s", - ident, arg, buf); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, addrcpt=%s", + ident, arg, buf); SM_VERBOSE (sm_pmfi_rcpt_add (pmse_ctx, buf, NULL)); break; case SMFIR_DELRCPT: gacopyz_srv_reply (gsrv, &buf, &size); - MU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, - "%s=%s, delrcpt=%s", - ident, arg, buf); + PMU_DEBUG3 (p->debug, MU_DEBUG_TRACE2, + "%s=%s, delrcpt=%s", + ident, arg, buf); /* FIXME: Index is always 0. Should it be 1? */ SM_VERBOSE (sm_pmfi_rcpt_del (pmse_ctx, buf, 0)); break; @@ -757,9 +758,7 @@ pmult_runlist (struct pmult_priv_data *p, pmult_runfun_t runfun, sfsistat_T rc; mu_iterator_t itr = NULL; - protect (); mu_list_get_iterator (p->srvlist, &itr); - unprotect (); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) @@ -774,16 +773,12 @@ pmult_runlist (struct pmult_priv_data *p, pmult_runfun_t runfun, for (i = 0; macros[i]; i += 2) gacopyz_srv_define_macro (gsrv, macros[i], macros[i+1]); - protect (); rc = runfun (pmse_ctx, gsrv, data); - unprotect (); if (rc != SMTP_R_CONT && rc != SMTP_R_OK) break; } - protect (); mu_iterator_destroy (&itr); - unprotect (); return rc; } @@ -793,9 +788,7 @@ pmult_free (struct pmult_priv_data *p) if (!p) return; - protect (); mu_list_destroy (&p->srvlist); - unprotect (); free (p->taid); free (p->seid); @@ -814,9 +807,7 @@ pmult_shutdown (pmse_ctx_P pmse_ctx, struct pmult_priv_data *p) if (!p) return; - protect (); mu_list_get_iterator (p->srvlist, &itr); - unprotect (); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) @@ -828,9 +819,7 @@ pmult_shutdown (pmse_ctx_P pmse_ctx, struct pmult_priv_data *p) gacopyz_srv_close (gsrv); gacopyz_srv_destroy (&gsrv); } - protect (); mu_iterator_destroy (&itr); - unprotect (); pmult_free (p); sm_pmfi_set_ctx_se (pmse_ctx, NULL); } @@ -877,8 +866,8 @@ pmult_connect (pmse_ctx_P pmse_ctx, const char *hostname, if (mu_debug_check_level (dbg, MU_DEBUG_TRACE1)) { char *p = mu_sockaddr_to_astr (&hostaddr->sa, sizeof *hostaddr); - __MU_DEBUG2 (dbg, MU_DEBUG_TRACE1, - "Connect from: %s, address %s\n", hostname, p); + __PMU_DEBUG2 (dbg, MU_DEBUG_TRACE1, + "Connect from: %s, address %s\n", hostname, p); free (p); } @@ -905,10 +894,10 @@ pmult_connect (pmse_ctx_P pmse_ctx, const char *hostname, protect (); mu_list_get_iterator (client_list, &itr); - unprotect (); client_addr = strdup (inet_ntoa (hostaddr->sin.sin_addr)); client_port = strdup (mu_umaxtostr (0, ntohs (hostaddr->sin.sin_port))); + unprotect (); for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) @@ -939,9 +928,7 @@ pmult_connect (pmse_ctx_P pmse_ctx, const char *hostname, gacopyz_srv_define_macro (gsrv, "client_port", client_port); /* FIXME: client_ptr, client_resolve */ - protect (); rc = gacopyz_srv_conn (gsrv, hostname, &hostaddr->sa); - unprotect (); status = pmult_std_reply (p, pmse_ctx, gsrv, rc, "connect", hostname); if (status != SMTP_R_CONT) break; @@ -954,6 +941,7 @@ pmult_connect (pmse_ctx_P pmse_ctx, const char *hostname, protect (); mu_iterator_destroy (&itr); unprotect (); + if (status == SMTP_R_CONT) sm_pmfi_set_ctx_se (pmse_ctx, p); else @@ -967,8 +955,8 @@ pmult_close (pmse_ctx_P pmse_ctx) struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); if (p) { - MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sClosing connection\n", - PMULT_SEID_C (p)); + PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sClosing connection\n", + PMULT_SEID_C (p)); pmult_shutdown (pmse_ctx, p); } return SM_SUCCESS; @@ -988,8 +976,8 @@ pmult_helo (pmse_ctx_P pmse_ctx, const char *helohost, bool ehlo) { struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); char *kv[3]; - MU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sHELO %s\n", - PMULT_SEID_C (p), helohost); + PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sHELO %s\n", + PMULT_SEID_C (p), helohost); kv[0] = "s"; kv[1] = (char*) helohost; kv[2] = NULL; @@ -1027,14 +1015,14 @@ pmult_mail (pmse_ctx_P pmse_ctx, const char *mail, char **argv) if (mu_debug_check_level (p->debug, MU_DEBUG_TRACE1)) { int i; - __MU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sMAIL FROM: %s", - PMULT_SEID_C (p), mail); + __PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sMAIL FROM: %s", + PMULT_SEID_C (p), mail); if (argv) { for (i = 0; argv[i]; i++) - __MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, " %s", argv[i]); + __PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, " %s", argv[i]); } - MU_DEBUG (p->debug, MU_DEBUG_TRACE1, "\n"); + PMU_DEBUG (p->debug, MU_DEBUG_TRACE1, "\n"); } /* Fill in the macro array */ @@ -1148,21 +1136,21 @@ pmult_rcpt (pmse_ctx_P pmse_ctx, const char *rcpt, char **argv) if (mu_debug_check_level (p->debug, MU_DEBUG_TRACE1)) { int i; - __MU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sRCPT TO: %s", - PMULT_SEID_C (p), rcpt); + __PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sRCPT TO: %s", + PMULT_SEID_C (p), rcpt); if (argv) { for (i = 0; argv[i]; i++) - __MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, " %s", argv[i]); + __PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, " %s", argv[i]); } - MU_DEBUG (p->debug, MU_DEBUG_TRACE1, "\n"); + PMU_DEBUG (p->debug, MU_DEBUG_TRACE1, "\n"); } p->nrcpt++; if (parse_email_addr (rcpt, &sender, &addr, &host)) { - MU_DEBUG2 (p->debug, MU_DEBUG_ERROR, "%sbad recipient address %s", - PMULT_SEID_C (p), rcpt); + PMU_DEBUG2 (p->debug, MU_DEBUG_ERROR, "%sbad recipient address %s", + PMULT_SEID_C (p), rcpt); p->nbadrcpts++; return SMTP_R_CONT; /* eh? */ } @@ -1227,7 +1215,7 @@ static sfsistat_T pmult_data (pmse_ctx_P pmse_ctx) { struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); - MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sDATA\n", PMULT_SEID_C (p)); + PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sDATA\n", PMULT_SEID_C (p)); return pmult_runlist (p, rf_data, pmse_ctx, NULL, NULL); } @@ -1236,8 +1224,8 @@ static sfsistat_T pmult_unknown (pmse_ctx_P pmse_ctx, const char *cmd) { struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); - MU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sUnknown command %s\n", - PMULT_SEID_C (p), cmd); + PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sUnknown command %s\n", + PMULT_SEID_C (p), cmd); return SMTP_R_CONT; } @@ -1255,9 +1243,8 @@ pmult_abort (pmse_ctx_P pmse_ctx) struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); if (p) { - MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sABORT\n", PMULT_SEID_C (p)); + PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sABORT\n", PMULT_SEID_C (p)); pmult_runlist (p, rf_abort, pmse_ctx, NULL, NULL); - pmult_shutdown (pmse_ctx, p); } return SM_SUCCESS; } @@ -1436,11 +1423,11 @@ pmult_msg (pmse_ctx_P pmse_ctx, unsigned char *buf, size_t len) if (p) { if (mu_debug_check_level (p->debug, MU_DEBUG_TRACE1)) - __MU_DEBUG4 (p->debug, MU_DEBUG_TRACE1, "%sBODY %lu %.*s\n", - PMULT_SEID_C (p), (unsigned long) len, (int) len, buf); + __PMU_DEBUG4 (p->debug, MU_DEBUG_TRACE1, "%sBODY %lu %.*s\n", + PMULT_SEID_C (p), (unsigned long) len, (int) len, buf); else - MU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sBODY %lu\n", - PMULT_SEID_C (p), (unsigned long) len); + PMU_DEBUG2 (p->debug, MU_DEBUG_TRACE1, "%sBODY %lu\n", + PMULT_SEID_C (p), (unsigned long) len); } if (p->state != pmult_msg_state_body) @@ -1476,7 +1463,7 @@ pmult_eom (pmse_ctx_P pmse_ctx) struct pmult_priv_data *p = sm_pmfi_get_ctx_se (pmse_ctx); struct body_chunk bc; - MU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sEOM\n", PMULT_SEID_C (p)); + PMU_DEBUG1 (p->debug, MU_DEBUG_TRACE1, "%sEOM\n", PMULT_SEID_C (p)); bc.ident = "eom"; bc.srvfun = gacopyz_srv_eom; bc.size = 0; |