diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-12-13 18:20:45 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-12-13 18:20:45 +0000 |
commit | cfb04309fb01de8797f85f2f945e375fd6091a99 (patch) | |
tree | c63a917781d2602db08b190b582115b56806eee4 /src | |
parent | 60fbc52f285b19ccbc9723cdae135cbb22acfe98 (diff) | |
download | mailfromd-cfb04309fb01de8797f85f2f945e375fd6091a99.tar.gz mailfromd-cfb04309fb01de8797f85f2f945e375fd6091a99.tar.bz2 |
Ported r1536 from branches/release_4_2_patches (= r1535 from tags/release_4_2):
git-svn-id: file:///svnroot/mailfromd/trunk@1538 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/bi_sieve.m4 | 21 | ||||
-rw-r--r-- | src/main.c | 26 | ||||
-rw-r--r-- | src/syslog_async.c | 43 |
4 files changed, 83 insertions, 20 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index eb7efed5..9609c5bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,19 +63,21 @@ mailfromd_SOURCES = \ noinst_LIBRARIES=libmf.a +SYSLOG_ASYNC_O=syslog_async.o + libmf_a_SOURCES=\ - syslog_async.c\ - syslog_async.h\ version.c -libmf_a_LIBADD=$(LIBOBJS) +libmf_a_LIBADD=$(LIBOBJS) $(BUILD_SYSLOG_ASYNC) mailfromd_LDADD = ./libmf.a $(LDADD) mtasim_SOURCES = mtasim.c openat-die.c mtasim_LDADD = ./libmf.a $(LDADD) $(READLINE_LIBS) -noinst_HEADERS = mailfromd.h mu_dbm.h builtin.h dns.h spf.h drivers.c debug.h +noinst_HEADERS = mailfromd.h mu_dbm.h builtin.h dns.h spf.h drivers.c debug.h \ + syslog_async.h + EXTRA_DIST = \ $(M4_FILES)\ builtin.def\ @@ -97,7 +99,8 @@ EXTRA_DIST = \ optab.oph\ snarf.m4\ status.mfh\ - status.mfi + status.mfi\ + syslog_async.c BUILT_SOURCES=\ $(M4_FILES:.m4=.c)\ diff --git a/src/bi_sieve.m4 b/src/bi_sieve.m4 index d018f9ce..f8551cb8 100644 --- a/src/bi_sieve.m4 +++ b/src/bi_sieve.m4 @@ -22,13 +22,23 @@ #define MF_SIEVE_DEBUG_MAILUTILS 0x08 #define MF_SIEVE_DEBUG_PROT 0x10 +#if MAILUTILS_VERSION_NUMBER < 1290 static int -_mu_debug_printer (mu_debug_t unused, size_t level, const char *fmt, - va_list ap) +_mu_debug_printer(mu_debug_t unused, size_t level, const char *fmt, + va_list ap) { vlogmsg((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, fmt, ap); return 0; } +typedef size_t mu_log_level_t; +#else +static int +_mu_debug_printer(void *unused, mu_log_level_t level, const char *msg) +{ + logmsg((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", msg); + return 0; +} +#endif static int _sieve_debug_printer (void *unused, const char *fmt, va_list ap) @@ -96,7 +106,7 @@ MF_DEFUN(sieve, NUMBER, STRING script, OPTIONAL, NUMBER dbg) { mu_sieve_machine_t mach; mu_debug_t mudebug = NULL; - int debug_flags = 0; /* FIXME: Init */ + mu_log_level_t debug_flags = 0; /* FIXME: Init */ int sieve_debug_flags = 0; int sieve_log = 0; int rc = mu_sieve_machine_init(&mach, NULL); @@ -131,7 +141,12 @@ MF_DEFUN(sieve, NUMBER, STRING script, OPTIONAL, NUMBER dbg) mu_debug_set_print(mudebug, _mu_debug_printer, NULL); } +#if MAILUTILS_VERSION_NUMBER < 1290 mu_sieve_set_debug_level(mach, mudebug, sieve_debug_flags); +#else + mu_sieve_set_debug_level(mach, sieve_debug_flags); + mu_sieve_set_debug_object(mach, mudebug); +#endif mu_sieve_set_parse_error(mach, _sieve_parse_error); if (sieve_log) mu_sieve_set_logger(mach, _sieve_action_log); @@ -42,8 +42,6 @@ #endif #include "mailfromd.h" -#include "syslog_async.h" - /* Configurable options */ @@ -81,8 +79,11 @@ int foreground; /* Stay in foreground */ int single_process_option; /* Run in single process mode. */ unsigned long source_address = INADDR_ANY; /* Source address for TCP connections */ +#ifdef USE_SYSLOG_ASYNC int use_syslog_async = DEFAULT_SYSLOG_ASYNC; - /* Use asynchronous syslog implementation */ + /* Use asynchronous syslog implementation */ +#endif + char *syslog_tag; /* Tag to mark syslog entries with. */ char *mailfromd_state_dir; /* see init_names() */ char *pidfile; /* see init_names() */ @@ -128,9 +129,12 @@ time_t response_timeout = 30; int syslog_printer (int prio, const char *fmt, va_list ap) { +#ifdef USE_SYSLOG_ASYNC if (use_syslog_async) { vsyslog_async (prio, fmt, ap); - } else { + } else +#endif + { #if HAVE_VSYSLOG vsyslog (prio, fmt, ap); #else @@ -142,6 +146,7 @@ syslog_printer (int prio, const char *fmt, va_list ap) return 0; } +#ifdef USE_SYSLOG_ASYNC void mf_gacopyz_syslog_async_log_printer(int level, char *fmt, va_list ap) { @@ -165,6 +170,7 @@ mf_gacopyz_syslog_async_log_printer(int level, char *fmt, va_list ap) } vsyslog_async(level, fmt, ap); } +#endif int syslog_error_printer (const char *fmt, va_list ap) @@ -1069,10 +1075,12 @@ static struct argp_option options[] = { N_("Log to stderr"), GRP+1 }, { "syslog", OPTION_SYSLOG, NULL, 0, N_("Log to syslog (default)"), GRP+1 }, +#ifdef USE_SYSLOG_ASYNC { "syslog-async", OPTION_SYSLOG_ASYNC, NULL, 0, N_("Use asynchronous syslog"), GRP+1 }, { "no-syslog-async", OPTION_NO_SYSLOG_ASYNC, NULL, 0, N_("Use system syslog"), GRP+1 }, +#endif { "log-tag", OPTION_LOG_TAG, N_("STRING"), 0, N_("Set the identifier used in syslog messages to STRING"), GRP+1 }, { "source-info", OPTION_SOURCE_INFO, NULL, 0, @@ -1392,6 +1400,7 @@ parse_opt (int key, char *arg, struct argp_state *state) log_to_stderr = 0; break; +#ifdef USE_SYSLOG_ASYNC case OPTION_SYSLOG_ASYNC: use_syslog_async = 1; break; @@ -1399,7 +1408,7 @@ parse_opt (int key, char *arg, struct argp_state *state) case OPTION_NO_SYSLOG_ASYNC: use_syslog_async = 0; break; - +#endif case OPTION_TIMEOUT: set_option("timeout", arg, 1); break; @@ -1976,11 +1985,13 @@ mailfromd_show_defaults() printf("statedir: %s\n", mailfromd_state_dir); printf("socket: %s\n", portspec); printf("pidfile: %s\n", pidfile); +#ifdef USE_SYSLOG_ASYNC #if DEFAULT_SYSLOG_ASYNC == 1 printf("default syslog: non-blocking\n"); #else printf("default syslog: blocking\n"); #endif +#endif printf("database format: "); #if defined WITH_GDBM printf("GDBM"); @@ -1997,10 +2008,13 @@ log_setup(int want_stderr) { /* Set up logging */ if (!want_stderr) { +#ifdef USE_SYSLOG_ASYNC if (use_syslog_async) { openlog_async(syslog_tag, LOG_PID, log_facility); gacopyz_set_logger(mf_gacopyz_syslog_async_log_printer); - } else { + } else +#endif + { openlog(syslog_tag, LOG_PID, log_facility); gacopyz_set_logger(gacopyz_syslog_log_printer); } diff --git a/src/syslog_async.c b/src/syslog_async.c index a168eac9..006cf16e 100644 --- a/src/syslog_async.c +++ b/src/syslog_async.c @@ -14,11 +14,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/file.h> #include <sys/syslog.h> +#include <netinet/in.h> +#include <signal.h> #include <sys/uio.h> #include <sys/wait.h> @@ -29,12 +34,29 @@ #include <errno.h> #include <stdarg.h> #include <stdlib.h> -#include <paths.h> +#ifdef HAVE_PATHS_H +# include <paths.h> +#else +# define _PATH_LOG "/dev/log" +# define _PATH_CONSOLE "/dev/console" +#endif #include <stdio.h> #include <ctype.h> #include "syslog_async.h" +#ifndef MSG_NOSIGNAL +# define MSG_NOSIGNAL 0 +#endif + +#ifndef LOG_PERROR +# define LOG_PERROR 0 +#endif + +#ifndef LOG_PRI +# define LOG_PRI(x) ((x) & LOG_PRIMASK) +#endif + /* From RFC 3164 */ #define MAX_MESSAGE 1024 @@ -166,6 +188,10 @@ void log_write_async(void) ssize_t rc; int fd, tried_stream = 0; struct log_entry *tmp; + +#if MSG_NOSIGNAL == 0 + RETSIGTYPE (*sigfun) (int sig) = signal (SIGPIPE, SIG_IGN); +#endif while (entries) { @@ -194,13 +220,13 @@ void log_write_async(void) continue; if (errno == EAGAIN) - return; + break; /* *BSD, returns this instead of blocking? */ if (errno == ENOBUFS) { connection_good = 0; - return; + break; } /* A stream socket closed at the other end goes into EPIPE @@ -221,11 +247,12 @@ void log_write_async(void) struct sockaddr_un logaddr; - logaddr.sun_family = AF_LOCAL; + logaddr.sun_family = AF_UNIX; strncpy(logaddr.sun_path, _PATH_LOG, sizeof(logaddr.sun_path)); /* Got connection back? try again. */ - if (connect(log_fd, (struct sockaddr *)&logaddr, sizeof(logaddr)) != -1) + if (connect(log_fd, (struct sockaddr *)&logaddr, + sizeof(logaddr)) != -1) continue; /* errors from connect which mean we should keep trying */ @@ -238,7 +265,7 @@ void log_write_async(void) { /* try again on next syslog() call */ connection_good = 0; - return; + break; } /* we start with a SOCK_DGRAM socket, but syslog may want SOCK_STREAM */ @@ -289,6 +316,10 @@ void log_write_async(void) } continue; } + +#if MSG_NOSIGNAL == 0 + signal (SIGPIPE, sigfun); +#endif } void syslog_async(int priority, const char *format, ...) |