summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2007-10-23 13:02:08 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2007-10-23 13:02:08 (GMT)
commit9e569139583178c7e1c35147cef3fd17493a11da (patch) (side-by-side diff)
tree36defb2a0547176e1ad91b8fc653f5dc687c9da9 /src/main.c
parent80c8065d88f8c0621d6b690976dc675092db6509 (diff)
downloadmailfromd-9e569139583178c7e1c35147cef3fd17493a11da.tar.gz
mailfromd-9e569139583178c7e1c35147cef3fd17493a11da.tar.bz2
Reimplement syslog-async. Thanks Simon Kelley for relicensing it under GPLv3.
git-svn-id: file:///svnroot/mailfromd/trunk@1520 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c69
1 files changed, 60 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index c277645..938a82b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,6 +39,8 @@
#include "mailfromd.h"
+#include "syslog_async.h"
+
/* Configurable options */
@@ -76,6 +78,8 @@ 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 */
+int use_syslog_async = DEFAULT_SYSLOG_ASYNC;
+ /* Use asynchronous syslog implementation */
char *syslog_tag; /* Tag to mark syslog entries with. */
char *mailfromd_state_dir; /* see init_names() */
char *pidfile; /* see init_names() */
@@ -121,16 +125,44 @@ time_t response_timeout = 30;
int
syslog_printer (int prio, const char *fmt, va_list ap)
{
+ if (use_syslog_async) {
+ vsyslog_async (prio, fmt, ap);
+ } else {
#if HAVE_VSYSLOG
- vsyslog (prio, fmt, ap);
+ vsyslog (prio, fmt, ap);
#else
- char buf[128];
- vsnprintf (buf, sizeof buf, fmt, ap);
- syslog (prio, "%s", buf);
+ char buf[128];
+ vsnprintf (buf, sizeof buf, fmt, ap);
+ syslog (prio, "%s", buf);
#endif
+ }
return 0;
}
+void
+mf_gacopyz_syslog_async_log_printer(int level, char *fmt, va_list ap)
+{
+ switch (level) {
+ case SMI_LOG_DEBUG:
+ level = LOG_DEBUG;
+ break;
+ case SMI_LOG_INFO:
+ level = LOG_INFO;
+ break;
+ case SMI_LOG_WARN:
+ level = LOG_WARNING;
+ break;
+ case SMI_LOG_ERR:
+ level = LOG_ERR;
+ break;
+
+ case SMI_LOG_FATAL:
+ default:
+ level = LOG_EMERG;
+ }
+ vsyslog_async(level, fmt, ap);
+}
+
int
syslog_error_printer (const char *fmt, va_list ap)
{
@@ -785,6 +817,7 @@ enum mailfromd_option {
OPTION_MILTER_TIMEOUT,
OPTION_MTASIM,
OPTION_NO_PREPROCESSOR,
+ OPTION_NO_SYSLOG_ASYNC,
OPTION_PIDFILE,
OPTION_POSTMASTER_EMAIL,
OPTION_PREDICT_NEXT,
@@ -795,6 +828,7 @@ enum mailfromd_option {
OPTION_STATE_DIRECTORY,
OPTION_SOURCE_INFO,
OPTION_SYSLOG,
+ OPTION_SYSLOG_ASYNC,
OPTION_TIME_FORMAT,
OPTION_TIMEOUT,
OPTION_TRACE,
@@ -944,6 +978,10 @@ static struct argp_option options[] = {
N_("Log to stderr"), GRP+1 },
{ "syslog", OPTION_SYSLOG, NULL, 0,
N_("Log to syslog (default)"), GRP+1 },
+ { "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 },
{ "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,
@@ -1263,6 +1301,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
log_to_stderr = 0;
break;
+ case OPTION_SYSLOG_ASYNC:
+ use_syslog_async = 1;
+ break;
+
+ case OPTION_NO_SYSLOG_ASYNC:
+ use_syslog_async = 0;
+ break;
+
case OPTION_TIMEOUT:
set_option("timeout", arg, 1);
break;
@@ -1656,10 +1702,10 @@ mailfromd_show_defaults()
printf("statedir: %s\n", mailfromd_state_dir);
printf("socket: %s\n", portspec);
printf("pidfile: %s\n", pidfile);
-#ifdef USE_SYSLOG_ASYNC
- printf("syslog: non-blocking\n");
+#if DEFAULT_SYSLOG_ASYNC == 1
+ printf("default syslog: non-blocking\n");
#else
- printf("syslog: blocking\n");
+ printf("default syslog: blocking\n");
#endif
printf("database format: ");
#if defined WITH_GDBM
@@ -1677,8 +1723,13 @@ log_setup(int want_stderr)
{
/* Set up logging */
if (!want_stderr) {
- openlog(syslog_tag, LOG_PID, log_facility);
- gacopyz_set_logger(gacopyz_syslog_log_printer);
+ if (use_syslog_async) {
+ openlog_async(syslog_tag, LOG_PID, log_facility);
+ gacopyz_set_logger(mf_gacopyz_syslog_async_log_printer);
+ } else {
+ openlog(syslog_tag, LOG_PID, log_facility);
+ gacopyz_set_logger(gacopyz_syslog_log_printer);
+ }
mu_error_set_print(syslog_error_printer);
} else {
gacopyz_set_logger(gacopyz_stderr_log_printer);

Return to:

Send suggestions and report system problems to the System administrator.