diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-10-23 13:02:08 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-10-23 13:02:08 +0000 |
commit | 9e569139583178c7e1c35147cef3fd17493a11da (patch) | |
tree | 36defb2a0547176e1ad91b8fc653f5dc687c9da9 /src/main.c | |
parent | 80c8065d88f8c0621d6b690976dc675092db6509 (diff) | |
download | mailfromd-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')
-rw-r--r-- | src/main.c | 69 |
1 files changed, 60 insertions, 9 deletions
@@ -39,6 +39,8 @@ | |||
39 | 39 | ||
40 | #include "mailfromd.h" | 40 | #include "mailfromd.h" |
41 | 41 | ||
42 | #include "syslog_async.h" | ||
43 | |||
42 | 44 | ||
43 | /* Configurable options */ | 45 | /* Configurable options */ |
44 | 46 | ||
@@ -76,6 +78,8 @@ int foreground; /* Stay in foreground */ | |||
76 | int single_process_option; /* Run in single process mode. */ | 78 | int single_process_option; /* Run in single process mode. */ |
77 | unsigned long source_address = INADDR_ANY; /* Source address for TCP | 79 | unsigned long source_address = INADDR_ANY; /* Source address for TCP |
78 | connections */ | 80 | connections */ |
81 | int use_syslog_async = DEFAULT_SYSLOG_ASYNC; | ||
82 | /* Use asynchronous syslog implementation */ | ||
79 | char *syslog_tag; /* Tag to mark syslog entries with. */ | 83 | char *syslog_tag; /* Tag to mark syslog entries with. */ |
80 | char *mailfromd_state_dir; /* see init_names() */ | 84 | char *mailfromd_state_dir; /* see init_names() */ |
81 | char *pidfile; /* see init_names() */ | 85 | char *pidfile; /* see init_names() */ |
@@ -121,16 +125,44 @@ time_t response_timeout = 30; | |||
121 | int | 125 | int |
122 | syslog_printer (int prio, const char *fmt, va_list ap) | 126 | syslog_printer (int prio, const char *fmt, va_list ap) |
123 | { | 127 | { |
128 | if (use_syslog_async) { | ||
129 | vsyslog_async (prio, fmt, ap); | ||
130 | } else { | ||
124 | #if HAVE_VSYSLOG | 131 | #if HAVE_VSYSLOG |
125 | vsyslog (prio, fmt, ap); | 132 | vsyslog (prio, fmt, ap); |
126 | #else | 133 | #else |
127 | char buf[128]; | 134 | char buf[128]; |
128 | vsnprintf (buf, sizeof buf, fmt, ap); | 135 | vsnprintf (buf, sizeof buf, fmt, ap); |
129 | syslog (prio, "%s", buf); | 136 | syslog (prio, "%s", buf); |
130 | #endif | 137 | #endif |
138 | } | ||
131 | return 0; | 139 | return 0; |
132 | } | 140 | } |
133 | 141 | ||
142 | void | ||
143 | mf_gacopyz_syslog_async_log_printer(int level, char *fmt, va_list ap) | ||
144 | { | ||
145 | switch (level) { | ||
146 | case SMI_LOG_DEBUG: | ||
147 | level = LOG_DEBUG; | ||
148 | break; | ||
149 | case SMI_LOG_INFO: | ||
150 | level = LOG_INFO; | ||
151 | break; | ||
152 | case SMI_LOG_WARN: | ||
153 | level = LOG_WARNING; | ||
154 | break; | ||
155 | case SMI_LOG_ERR: | ||
156 | level = LOG_ERR; | ||
157 | break; | ||
158 | |||
159 | case SMI_LOG_FATAL: | ||
160 | default: | ||
161 | level = LOG_EMERG; | ||
162 | } | ||
163 | vsyslog_async(level, fmt, ap); | ||
164 | } | ||
165 | |||
134 | int | 166 | int |
135 | syslog_error_printer (const char *fmt, va_list ap) | 167 | syslog_error_printer (const char *fmt, va_list ap) |
136 | { | 168 | { |
@@ -785,6 +817,7 @@ enum mailfromd_option { | |||
785 | OPTION_MILTER_TIMEOUT, | 817 | OPTION_MILTER_TIMEOUT, |
786 | OPTION_MTASIM, | 818 | OPTION_MTASIM, |
787 | OPTION_NO_PREPROCESSOR, | 819 | OPTION_NO_PREPROCESSOR, |
820 | OPTION_NO_SYSLOG_ASYNC, | ||
788 | OPTION_PIDFILE, | 821 | OPTION_PIDFILE, |
789 | OPTION_POSTMASTER_EMAIL, | 822 | OPTION_POSTMASTER_EMAIL, |
790 | OPTION_PREDICT_NEXT, | 823 | OPTION_PREDICT_NEXT, |
@@ -795,6 +828,7 @@ enum mailfromd_option { | |||
795 | OPTION_STATE_DIRECTORY, | 828 | OPTION_STATE_DIRECTORY, |
796 | OPTION_SOURCE_INFO, | 829 | OPTION_SOURCE_INFO, |
797 | OPTION_SYSLOG, | 830 | OPTION_SYSLOG, |
831 | OPTION_SYSLOG_ASYNC, | ||
798 | OPTION_TIME_FORMAT, | 832 | OPTION_TIME_FORMAT, |
799 | OPTION_TIMEOUT, | 833 | OPTION_TIMEOUT, |
800 | OPTION_TRACE, | 834 | OPTION_TRACE, |
@@ -944,6 +978,10 @@ static struct argp_option options[] = { | |||
944 | N_("Log to stderr"), GRP+1 }, | 978 | N_("Log to stderr"), GRP+1 }, |
945 | { "syslog", OPTION_SYSLOG, NULL, 0, | 979 | { "syslog", OPTION_SYSLOG, NULL, 0, |
946 | N_("Log to syslog (default)"), GRP+1 }, | 980 | N_("Log to syslog (default)"), GRP+1 }, |
981 | { "syslog-async", OPTION_SYSLOG_ASYNC, NULL, 0, | ||
982 | N_("Use asynchronous syslog"), GRP+1 }, | ||
983 | { "no-syslog-async", OPTION_NO_SYSLOG_ASYNC, NULL, 0, | ||
984 | N_("Use system syslog"), GRP+1 }, | ||
947 | { "log-tag", OPTION_LOG_TAG, N_("STRING"), 0, | 985 | { "log-tag", OPTION_LOG_TAG, N_("STRING"), 0, |
948 | N_("Set the identifier used in syslog messages to STRING"), GRP+1 }, | 986 | N_("Set the identifier used in syslog messages to STRING"), GRP+1 }, |
949 | { "source-info", OPTION_SOURCE_INFO, NULL, 0, | 987 | { "source-info", OPTION_SOURCE_INFO, NULL, 0, |
@@ -1263,6 +1301,14 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
1263 | log_to_stderr = 0; | 1301 | log_to_stderr = 0; |
1264 | break; | 1302 | break; |
1265 | 1303 | ||
1304 | case OPTION_SYSLOG_ASYNC: | ||
1305 | use_syslog_async = 1; | ||
1306 | break; | ||
1307 | |||
1308 | case OPTION_NO_SYSLOG_ASYNC: | ||
1309 | use_syslog_async = 0; | ||
1310 | break; | ||
1311 | |||
1266 | case OPTION_TIMEOUT: | 1312 | case OPTION_TIMEOUT: |
1267 | set_option("timeout", arg, 1); | 1313 | set_option("timeout", arg, 1); |
1268 | break; | 1314 | break; |
@@ -1656,10 +1702,10 @@ mailfromd_show_defaults() | |||
1656 | printf("statedir: %s\n", mailfromd_state_dir); | 1702 | printf("statedir: %s\n", mailfromd_state_dir); |
1657 | printf("socket: %s\n", portspec); | 1703 | printf("socket: %s\n", portspec); |
1658 | printf("pidfile: %s\n", pidfile); | 1704 | printf("pidfile: %s\n", pidfile); |
1659 | #ifdef USE_SYSLOG_ASYNC | 1705 | #if DEFAULT_SYSLOG_ASYNC == 1 |
1660 | printf("syslog: non-blocking\n"); | 1706 | printf("default syslog: non-blocking\n"); |
1661 | #else | 1707 | #else |
1662 | printf("syslog: blocking\n"); | 1708 | printf("default syslog: blocking\n"); |
1663 | #endif | 1709 | #endif |
1664 | printf("database format: "); | 1710 | printf("database format: "); |
1665 | #if defined WITH_GDBM | 1711 | #if defined WITH_GDBM |
@@ -1677,8 +1723,13 @@ log_setup(int want_stderr) | |||
1677 | { | 1723 | { |
1678 | /* Set up logging */ | 1724 | /* Set up logging */ |
1679 | if (!want_stderr) { | 1725 | if (!want_stderr) { |
1680 | openlog(syslog_tag, LOG_PID, log_facility); | 1726 | if (use_syslog_async) { |
1681 | gacopyz_set_logger(gacopyz_syslog_log_printer); | 1727 | openlog_async(syslog_tag, LOG_PID, log_facility); |
1728 | gacopyz_set_logger(mf_gacopyz_syslog_async_log_printer); | ||
1729 | } else { | ||
1730 | openlog(syslog_tag, LOG_PID, log_facility); | ||
1731 | gacopyz_set_logger(gacopyz_syslog_log_printer); | ||
1732 | } | ||
1682 | mu_error_set_print(syslog_error_printer); | 1733 | mu_error_set_print(syslog_error_printer); |
1683 | } else { | 1734 | } else { |
1684 | gacopyz_set_logger(gacopyz_stderr_log_printer); | 1735 | gacopyz_set_logger(gacopyz_stderr_log_printer); |