summaryrefslogtreecommitdiffabout
path: root/src/main.c
authorSergey Poznyakoff <gray@gnu.org.ua>2010-12-20 20:48:55 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2010-12-21 08:34:44 (GMT)
commite75c9a39fd65c73c22a2966de51c875109f78946 (patch) (side-by-side diff)
tree97f83d357261961448b820c452d7a5eaa45f023e /src/main.c
parentc8007b6f1bc449154dcafaf7dc84bba188ef4fed (diff)
downloadmailfromd-e75c9a39fd65c73c22a2966de51c875109f78946.tar.gz
mailfromd-e75c9a39fd65c73c22a2966de51c875109f78946.tar.bz2
Switch to MU3 API.
* lib/debug.c: Remove. * lib/debug.h: Remove. * lib/Makefile.am (noinst_HEADERS): Remove debug.h (libmf_a_SOURCES): Remove debug.c * lib/appinit.c: Use new mu_stream_* calls. * lib/libmf.h (config_array_to_argv,config_array_to_string): Change signatures. (config_cb_timeout): Likewise. (logger)<log_print>: Remove. <log_open>: Change signature. (logger_open): Change signature. (vlogmsg,logmsg): Rewrite as macros. * lib/logger.c: Rewrite logging support using MU3 streams. * lib/utils.c (config_array_to_argv) (config_array_to_string, config_cb_timeout): Rewrite. * lib/server.c (mf_server_start): Call mu_onexit_run. * lib/version.c (version_etc_copyright): Rename to avoid name clash. * lib/dbcfg.c: Rewrite callbacks. Use MU3 configuration framework. * lib/cache.c: Use mu_debug for debugging. * lib/db.c: Likewise. * lib/dns.c: Likewise. * lib/greylist.c: Likewise. * lib/mf-dbm.c: Likewise. * lib/rate.c: Likewise. * lib/srvman.c: Likewise. * lib/tbf_rate.c: Likewise. * src/builtin/snarf.m4: Likewise. * src/calloutd.c: Likewise. * src/engine.c: Likewise. * src/spf.c: Likewise. * src/Makefile.am (mfd-dbgmod.h): Offset the indices by the value of mfd_debug_handle. * src/builtin/body.bi (current_message): Use mu_stream_to_message. * src/builtin/curhdr.bi: Use MU3 API. * src/builtin/db.bi: Likewise. * src/builtin/io.bi: Likewise. * src/builtin/mail.bi: Likewise. * src/builtin/msg.bi: Likewise. * src/builtin/mudebug.bi: Likewise. * src/builtin/sieve.bi: Likewise. * src/lex.l: Likewise. * src/savsrv.c: Likewise. * src/srvcfg.c: Likewise. * src/builtin/other.bi (debug_level): Rewrite using mu_debug_category_level (debug_spec): Rewrite using mu_debug_format_spec. (debug): Rewrite using mu_debug_parse_spec. * src/callout.c (smtp_io_data) <send_off, recv_off>: Remove. All uses updated. (smtp_io_free, smtp_send, smtp_recvline) (smtp_io_close, callout_host, callout_mx) (libcallout_init): Use new stream and debugging API. * src/mailfromd.h (mfd_debug_handle): New extern. (add_legacy_milter_port): Change signature. * src/main.c (mf_strecho): New global. (mfd_gacopyz_log_printer): Remove. (read_domain_file): Change signature. (cb_milter_timeout, cb_timeout, cb_set_variable) (cb_include_path, cb_trace_program, cb_relayed_domain_file): Rewrite. (mfd_debug_handle): New variable. (open_strecho): New function. (main): Revise logging support initialization. * src/mfdbtool.c: Use new MU API. * src/pp.c: Likewise. * src/pragma.c: Likewise. * src/prog.c: Use new MU API. (instr_echo): Send output to mf_strecho. * src/prog.h (mf_strecho): New extern. * src/builtin/msg.h (mf_message) <mstr, bstr>: New members. * src/builtin/sa.bi: Rewrite using new stream functions. * pmult/.gitignore: Remove pdbg.h. * pmult/pdbg.hm4: Remove. * pmult/debugdef.m4: Remove. * pmult/Makefile.am (EXTRA_DIST): Remove pdbg.hm4 and debugdef.m4 (pmult_SOURCES): Remove pdbg.h * pmult/pmult.c: Redo logging, debugging and configuration support. * tests/hdr-gete.at: Update. * tests/testsuite.at (AT_MTA_TEST): Filter out info prefix from the 'echo' output.
Diffstat (limited to 'src/main.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/main.c180
1 files changed, 100 insertions, 80 deletions
diff --git a/src/main.c b/src/main.c
index 8ce1732..98440ff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,6 +80,8 @@ size_t max_match_mx = MAXMXCOUNT;
char *main_function_name = "main";
char *callout_server_url;
+mu_stream_t mf_strecho; /* Output stream for 'echo' statements */
+
/* Preprocessor helper function */
static void
@@ -110,36 +112,12 @@ pp_define(const char *symbol)
/* Logging & debugging */
void
-mfd_gacopyz_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;
- }
- vlogmsg(level, fmt, ap);
-}
-
-void
trace(const char *fmt, ...)
{
if (do_trace) {
va_list ap;
va_start(ap, fmt);
- vlogmsg(LOG_INFO, fmt, ap);
+ vlogmsg(MU_LOG_INFO, fmt, ap);
va_end(ap);
}
}
@@ -148,14 +126,15 @@ void
log_status(sfsistat status, SMFICTX *ctx)
{
int lev;
- debug_module_level(NULL, &lev);
- if (lev >= 1 && status != SMFIS_CONTINUE) {
+ mu_debug_category_level(NULL, 0, &lev);
+ if ((lev & ~MU_DEBUG_LEVEL_MASK(MU_DEBUG_ERROR)) &&
+ status != SMFIS_CONTINUE) {
const char *str = sfsistat_str(status);
if (str)
- logmsg(LOG_INFO,
+ logmsg(MU_LOG_INFO,
"%s%s", mailfromd_msgid(ctx), str);
else
- logmsg(LOG_INFO,
+ logmsg(MU_LOG_INFO,
"%sstatus %d",
mailfromd_msgid(ctx), status);
}
@@ -169,7 +148,7 @@ static mu_list_t domain_list;
/* Read domains from sendmail-style domain file NAME and store them in
DOMAIN_LIST */
int
-read_domain_file(mu_debug_t err, const char *name)
+read_domain_file(const char *name)
{
FILE *fp;
char buf[256];
@@ -177,8 +156,8 @@ read_domain_file(mu_debug_t err, const char *name)
fp = fopen(name, "r");
if (!fp) {
- mf_error_on_locus(err, _("cannot open file `%s': %s"),
- name, mu_strerror(errno));
+ mu_error(_("cannot open file `%s': %s"),
+ name, mu_strerror(errno));
return 1;
}
@@ -217,8 +196,8 @@ relayed_domain_p(char *name)
while (p) {
if (mu_list_locate(domain_list, p, NULL) == 0) {
- debug(MF_SOURCE_MAIN, 10,
- ("%s is in relayed domain %s", name, p));
+ mu_debug(MF_SOURCE_MAIN, MU_DEBUG_TRACE5,
+ ("%s is in relayed domain %s", name, p));
return 1;
}
p = strchr(p, '.');
@@ -261,7 +240,7 @@ set_milter_timeout(void *value)
static int
load_relay_file(void *item, void *data)
{
- read_domain_file((mu_debug_t) data, item);
+ read_domain_file(item);
return 0;
}
@@ -704,17 +683,16 @@ static struct argp argp = {
/* Mailutils-2.0 configuration */
static int
-cb_milter_timeout(mu_debug_t err, void *data, mu_config_value_t *arg)
+cb_milter_timeout(void *data, mu_config_value_t *arg)
{
struct timeval tv;
- int rc = config_cb_timeout (&tv, err, arg);
+ int rc = config_cb_timeout (&tv, arg);
if (rc)
return 1;
if (smfi_settimeout(tv.tv_sec) == MI_FAILURE) {
- mf_error_on_locus(err,
- _("Invalid milter timeout: %lu"),
- (unsigned long) tv.tv_sec);
+ mu_error(_("Invalid milter timeout: %lu"),
+ (unsigned long) tv.tv_sec);
exit(EX_USAGE);
}
@@ -722,32 +700,32 @@ cb_milter_timeout(mu_debug_t err, void *data, mu_config_value_t *arg)
}
static int
-cb_timeout(mu_debug_t err, void *data, mu_config_value_t *arg)
+cb_timeout(void *data, mu_config_value_t *arg)
{
struct timeval tv;
- int rc = config_cb_timeout (&tv, err, arg);
+ int rc = config_cb_timeout (&tv, arg);
if (rc == 0)
*(time_t*) data = tv.tv_sec;
return rc;
}
static int
-cb_set_variable(mu_debug_t err, void *data, mu_config_value_t *arg)
+cb_set_variable(void *data, mu_config_value_t *arg)
{
const char *value;
char *alloc_str = NULL;
- if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY, err))
+ if (mu_cfg_assert_value_type(arg, MU_CFG_ARRAY))
return 1;
if (arg->v.arg.c < 2) {
- mf_error_on_locus(err, _("not enough arguments"));
+ mu_error(_("not enough arguments"));
return 1;
} else if (arg->v.arg.c > 2) {
- mf_error_on_locus(err, _("too many arguments"));
+ mu_error(_("too many arguments"));
return 1;
}
- if (mu_cfg_assert_value_type(&arg->v.arg.v[0], MU_CFG_ARRAY, err))
+ if (mu_cfg_assert_value_type(&arg->v.arg.v[0], MU_CFG_ARRAY))
return 1;
switch (arg->v.arg.v[1].type) {
@@ -756,18 +734,17 @@ cb_set_variable(mu_debug_t err, void *data, mu_config_value_t *arg)
break;
case MU_CFG_ARRAY:
- alloc_str = config_array_to_string(&arg->v.arg.v[1], err);
+ alloc_str = config_array_to_string(&arg->v.arg.v[1]);
value = alloc_str;
break;
case MU_CFG_LIST:
- mu_cfg_format_error(err, MU_DEBUG_ERROR, _("unexpected list"));
+ mu_error(_("unexpected list"));
return 1;
default:
- mu_cfg_format_error (err, MU_DEBUG_ERROR,
- _("INTERNAL ERROR at %s:%d: please report"),
- __FILE__, __LINE__);
+ mu_error (_("INTERNAL ERROR at %s:%d: please report"),
+ __FILE__, __LINE__);
abort();
}
@@ -777,33 +754,31 @@ cb_set_variable(mu_debug_t err, void *data, mu_config_value_t *arg)
}
static int
-cb_include_path(mu_debug_t err, void *data, mu_config_value_t *val)
+cb_include_path(void *data, mu_config_value_t *val)
{
int i, rc = 0;
- int argc;
- char **argv;
+ struct mu_wordsplit ws;
mu_iterator_t itr;
switch (val->type) {
case MU_CFG_STRING:
- rc = mu_argcv_get_np(val->v.string, strlen(val->v.string),
- ":", NULL, 0, &argc, &argv, NULL);
- if (rc) {
- mu_cfg_format_error(err, MU_DEBUG_ERROR,
- "mu_argcv_get: %s",
- mu_strerror(rc));
+ ws.ws_delim = ":";
+ if (mu_wordsplit(val->v.string, &ws,
+ MU_WRDSF_NOVAR |
+ MU_WRDSF_NOCMD | MU_WRDSF_DELIM)) {
+ mu_error("mu_wordsplit: %s",
+ mu_wordsplit_strerror(&ws));
return 1;
}
- for (i = 0; i < argc; i++)
- add_include_dir(argv[i]);
- mu_argcv_free(argc, argv);
+ for (i = 0; i < ws.ws_wordc; i++)
+ add_include_dir(ws.ws_wordv[i]);
+ mu_wordsplit_free(&ws);
break;
case MU_CFG_ARRAY:
for (i = 0; i < val->v.arg.c; i++) {
if (mu_cfg_assert_value_type(&val->v.arg.v[i],
- MU_CFG_STRING,
- err))
+ MU_CFG_STRING))
return 1;
add_include_dir(val->v.arg.v[i].v.string);
}
@@ -815,8 +790,7 @@ cb_include_path(mu_debug_t err, void *data, mu_config_value_t *val)
!mu_iterator_is_done(itr); mu_iterator_next(itr)) {
mu_config_value_t *pval;
mu_iterator_current(itr, (void*) &pval);
- rc = mu_cfg_assert_value_type(pval, MU_CFG_STRING,
- err);
+ rc = mu_cfg_assert_value_type(pval, MU_CFG_STRING);
if (rc)
break;
add_include_dir(pval->v.string);
@@ -827,7 +801,7 @@ cb_include_path(mu_debug_t err, void *data, mu_config_value_t *val)
}
static int
-cb_trace_program(mu_debug_t err, void *data, mu_config_value_t *val)
+cb_trace_program(void *data, mu_config_value_t *val)
{
int i, rc = 0;
@@ -839,8 +813,7 @@ cb_trace_program(mu_debug_t err, void *data, mu_config_value_t *val)
case MU_CFG_ARRAY:
for (i = 0; i < val->v.arg.c; i++) {
if (mu_cfg_assert_value_type(&val->v.arg.v[i],
- MU_CFG_STRING,
- err))
+ MU_CFG_STRING))
return 1;
enable_prog_trace(val->v.arg.v[i].v.string);
}
@@ -854,20 +827,19 @@ cb_trace_program(mu_debug_t err, void *data, mu_config_value_t *val)
}
static int
-cb_relayed_domain_file(mu_debug_t err, void *data, mu_config_value_t *val)
+cb_relayed_domain_file(void *data, mu_config_value_t *val)
{
switch (val->type) {
case MU_CFG_STRING:
- read_domain_file(err, val->v.string);
+ read_domain_file(val->v.string);
break;
case MU_CFG_LIST:
- mu_list_do(val->v.list, load_relay_file, err);
+ mu_list_do(val->v.list, load_relay_file, NULL);
break;
default:
- mu_cfg_format_error (err, MU_DEBUG_ERROR,
- _("expected string or list of strings"));
+ mu_error (_("expected string or list of strings"));
}
return 0;
}
@@ -1077,6 +1049,18 @@ static char *modnames[] = {
NULL
};
+size_t mfd_debug_handle;
+
+static void
+debug_init()
+{
+ int i;
+
+ mfd_debug_handle = mu_debug_register_category (modnames[0]);
+ for (i = 1; modnames[i]; i++)
+ mu_debug_register_category (modnames[i]);
+}
+
int
mf_server_function(const char *key, struct mf_srvcfg *cfg)
@@ -1093,7 +1077,38 @@ mf_server_function(const char *key, struct mf_srvcfg *cfg)
return 1;
return 0;
}
-
+
+static void
+open_strecho (int daemon_mode)
+{
+ int rc;
+ if (daemon_mode) {
+ rc = mu_stream_ioctl(mu_strerr, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_CLONE,
+ &mf_strecho);
+ if (rc == 0) {
+ int s = MU_LOG_INFO;
+ mu_stream_ioctl(mf_strecho, MU_IOCTL_LOGSTREAM,
+ MU_IOCTL_LOGSTREAM_SET_SEVERITY,
+ &s);
+ }
+ } else {
+#if 0
+ mf_strecho = mu_strout;
+ mu_stream_ref(mf_strecho);
+ rc = 0;
+#else
+ rc = mu_stdio_stream_create (&mf_strecho, MU_STDERR_FD, 0);
+#endif
+ }
+ if (rc) {
+ mu_diag_output (MU_LOG_CRIT,
+ _("cannot create echo output stream: %s"),
+ mu_strerror (rc));
+ exit (EX_UNAVAILABLE);
+ }
+}
+
extern char **environ;
@@ -1117,10 +1132,11 @@ main(int argc, char **argv)
yy_flex_debug = 0;
/* Set default logging */
+ mu_set_program_name (argv[0]);
+ mu_log_tag = (char*)mu_program_name;
mu_log_facility = DEFAULT_LOG_FACILITY;
- gacopyz_set_logger(mfd_gacopyz_log_printer);
- mf_srvcfg_log_setup(MU_LOG_TAG(),
- stderr_closed_p() ? "syslog" : "stderr");
+ mu_stdstream_setup ();
+ mf_srvcfg_log_setup(stderr_closed_p() ? "syslog" : "stderr");
debug_init(modnames);
libcallout_init();
@@ -1150,6 +1166,7 @@ main(int argc, char **argv)
exit(EX_CONFIG);
flush_arguments(&args);
mf_srvcfg_flush();
+ mf_server_log_setup();
alloc_ext_pp();
@@ -1263,11 +1280,13 @@ main(int argc, char **argv)
"without full file name"));
server_flags |= MF_SERVER_NORESTART;
}
+ open_strecho(1);
mf_server_start("mailfromd", mailfromd_state_dir, pidfile,
server_flags);
break;
case MAILFROMD_TEST:
+ open_strecho(0);
mailfromd_test(argc, argv);
break;
@@ -1276,6 +1295,7 @@ main(int argc, char **argv)
break;
case MAILFROMD_RUN:
+ open_strecho(0);
mailfromd_run(entry_point, argc, argv);
}

Return to:

Send suggestions and report system problems to the System administrator.