aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-02-26 22:41:24 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-02-26 23:15:39 +0200
commit795b7f52f03db80ef079b28e53070471f2959153 (patch)
tree851596fe85fe031bb471268023d3a45b05642412
parent649cc9a9c5384137194f32d11de8e3037cd05ff1 (diff)
downloadmailfromd-795b7f52f03db80ef079b28e53070471f2959153.tar.gz
mailfromd-795b7f52f03db80ef079b28e53070471f2959153.tar.bz2
Restore legacy lock-* configuration statements.
* lib/libmf.h (config_cb_lock_retry_count) (config_cb_lock_retry_timeout) (mf_option_size_t,mf_init_lock_options): New prototypes. * lib/optcache.c (mf_option_size_t): New function. * lib/utils.c (config_cb_lock_retry_count) (config_cb_lock_retry_timeout) (mf_init_lock_options): New functions. * src/main.c (mf_cfg_param): Restore lock-retry-count and lock-retry-timeout for backward compatibility. (main): Call mf_init_lock_options. * src/mfdbtool.c (mfdbtool_cfg_param): Restore lock-retry-count and lock-retry-timeout for backward compatibility. (main): Call mf_init_lock_options. * src/calloutd.c: Likewise. * lib/close-fds.c (close_fds_except): Don't access FD_SET unless i is less than FD_SETSIZE.
-rw-r--r--lib/close-fds.c2
-rw-r--r--lib/libmf.h5
-rw-r--r--lib/optcache.c9
-rw-r--r--lib/utils.c60
-rw-r--r--src/calloutd.c11
-rw-r--r--src/main.c13
-rw-r--r--src/mfdbtool.c18
7 files changed, 105 insertions, 13 deletions
diff --git a/lib/close-fds.c b/lib/close-fds.c
index 2ff04140..77dc5617 100644
--- a/lib/close-fds.c
+++ b/lib/close-fds.c
@@ -35,6 +35,6 @@ close_fds_except(fd_set *exfd)
int i;
for (i = getmaxfd(); i >= 0; i--)
- if (!FD_ISSET(i, exfd))
+ if (!(i < FD_SETSIZE && FD_ISSET(i, exfd)))
close(i);
}
diff --git a/lib/libmf.h b/lib/libmf.h
index 4d71483c..6de8bff5 100644
--- a/lib/libmf.h
+++ b/lib/libmf.h
@@ -131,6 +131,8 @@ char *config_array_to_string (mu_config_value_t *val);
int config_cb_timeout (struct timeval *pt, mu_config_value_t *val);
int config_cb_time_t(void *data, mu_config_value_t *arg);
int config_cb_ignore(void *data, mu_config_value_t *val);
+int config_cb_lock_retry_count(void *data, mu_config_value_t *val);
+int config_cb_lock_retry_timeout(void *data, mu_config_value_t *val);
void mf_proctitle_init (int argc, char *argv[], char *env[]);
void mf_proctitle_format (const char *fmt, ...);
@@ -306,6 +308,9 @@ int mf_option_string(char *opt, void **pval, char *newval);
int mf_option_boolean(char *opt, void **pval, char *newval);
int mf_option_time(char *opt, void **pval, char *newval);
int mf_option_time_t(char *opt, void **pval, char *newval);
+int mf_option_size_t(char *opt, void **pval, char *newval);
+
+void mf_init_lock_options(void);
/* namefixup.c */
diff --git a/lib/optcache.c b/lib/optcache.c
index cd89bff3..90045be5 100644
--- a/lib/optcache.c
+++ b/lib/optcache.c
@@ -175,4 +175,13 @@ mf_option_time_t(char *opt, void **pval, char *newval)
memcpy(*pval, newval, sizeof(time_t));
return 0;
}
+
+int
+mf_option_size_t(char *opt, void **pval, char *newval)
+{
+ if (!*pval)
+ *pval = xmalloc(sizeof(size_t));
+ memcpy(*pval, newval, sizeof(size_t));
+ return 0;
+}
diff --git a/lib/utils.c b/lib/utils.c
index d618a024..b6036450 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -19,6 +19,7 @@
#endif
#include <libmf.h>
+#include <mailutils/locker.h>
#include "xalloc.h"
@@ -129,6 +130,65 @@ config_cb_ignore(void *data, mu_config_value_t *val)
PACKAGE_STRING);
return 0;
}
+
+int
+config_cb_lock_retry_count(void *data, mu_config_value_t *val)
+{
+ char *p;
+ size_t n;
+
+ if (mu_cfg_assert_value_type(val, MU_CFG_STRING))
+ return 1;
+ n = strtoul(val->v.string, &p, 10);
+ if (*p) {
+ mu_error(_("not a number"));
+ return 1;
+ }
+ mf_optcache_set_option("lock-retry-count", (void*)&n);
+ return 0;
+}
+
+int
+config_cb_lock_retry_timeout(void *data, mu_config_value_t *val)
+{
+ int rc;
+ time_t t;
+
+ rc = config_cb_time_t(&t, val);
+ if (rc == 0)
+ mf_optcache_set_option("lock-retry-timeout", (void*)&t);
+ return rc;
+}
+
+static void
+set_lock_retry_count(void *value)
+{
+ size_t *n = value;
+ mu_locker_set_default_retry_count(*n);
+ free(value);
+}
+
+static void
+set_lock_retry_timeout(void *value)
+{
+ time_t *t = value;
+ mu_locker_set_default_retry_timeout(*t);
+ free(value);
+}
+
+static struct mf_option_cache lock_option_cache[] = {
+ { "lock-retry-count", NULL, mf_option_size_t,
+ set_lock_retry_count },
+ { "lock-retry-timeout", NULL, mf_option_time_t,
+ set_lock_retry_timeout },
+ { NULL }
+};
+
+void
+mf_init_lock_options()
+{
+ mf_optcache_add(lock_option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC);
+}
int
diff --git a/src/calloutd.c b/src/calloutd.c
index c3753593..54526fd7 100644
--- a/src/calloutd.c
+++ b/src/calloutd.c
@@ -76,6 +76,14 @@ parse_opt(int key, char *arg, struct argp_state *state)
struct mu_cfg_param callout_cfg_param[] = {
{ ".mfd:server", mu_cfg_section, NULL, 0, NULL, NULL },
+ { "lock-retry-count", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_count,
+ N_("Retry acquiring DBM file lock this number of times.") },
+ { "lock-retry-timeout", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_timeout,
+ N_("Set the time span between the two DBM locking attempts."),
+ N_("time") },
+
{ NULL }
};
@@ -87,6 +95,7 @@ static const char *capa[] = {
"common",
"debug",
"logging",
+ "locking",
NULL
};
@@ -129,6 +138,7 @@ main(int argc, char **argv)
mf_server_save_cmdline(argc, argv);
dnsbase_init();
database_cfg_init();
+ mf_init_lock_options();
mu_acl_cfg_init();
srvman_init();
mf_srvcfg_init(argv[0], NULL);
@@ -139,6 +149,7 @@ main(int argc, char **argv)
0, NULL, NULL);
if (rc)
exit(EX_CONFIG);
+ mf_optcache_flush();
mf_srvcfg_flush();
mf_server_lint_option = "--config-lint";
diff --git a/src/main.c b/src/main.c
index b833a0c0..11a60aba 100644
--- a/src/main.c
+++ b/src/main.c
@@ -694,6 +694,7 @@ static const char *capa[] = {
"common",
"debug",
"logging",
+ "locking",
"mailer",
NULL
};
@@ -918,10 +919,12 @@ struct mu_cfg_param mf_cfg_param[] = {
{ "database", mu_cfg_section, NULL },
- { "lock-retry-count", mu_cfg_callback, 0, 0, config_cb_ignore,
- N_("Ignored for backward compatibility.") },
- { "lock-retry-timeout", mu_cfg_callback, 0,0, config_cb_ignore,
- N_("Ignored for backward compatibility."),
+ { "lock-retry-count", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_count,
+ N_("Retry acquiring DBM file lock this number of times.") },
+ { "lock-retry-timeout", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_timeout,
+ N_("Set the time span between the two DBM locking attempts."),
N_("time") },
{ "max-match-mx", mu_cfg_size, &max_match_mx, 0, NULL,
@@ -1219,7 +1222,9 @@ main(int argc, char **argv)
db_format_setup();
include_path_setup();
pragma_setup();
+ mf_init_lock_options();
mf_optcache_add(option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC);
+
mf_server_save_cmdline(argc, argv);
dnsbase_init();
diff --git a/src/mfdbtool.c b/src/mfdbtool.c
index 98e87acc..6cffac5f 100644
--- a/src/mfdbtool.c
+++ b/src/mfdbtool.c
@@ -170,7 +170,6 @@ mfdbtool_compact(int argc, char **argv)
}
}
-
const char *program_version = "mfdbtool (" PACKAGE_STRING ")";
static char doc[] = N_("mfdbtool -- Mailfromd database management tool");
@@ -318,7 +317,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
}
return 0;
}
-
+
static int
cb_debug(void *data, mu_config_value_t *arg)
@@ -347,10 +346,12 @@ struct mu_cfg_param mfdbtool_cfg_param[] = {
"is the desired verbosity level for that module."),
N_("spec: list") },
- { "lock-retry-count", mu_cfg_callback, 0, 0, config_cb_ignore,
- N_("Ignored for backward compatibility.") },
- { "lock-retry-timeout", mu_cfg_callback, 0,0, config_cb_ignore,
- N_("Ignored for backward compatibility."),
+ { "lock-retry-count", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_count,
+ N_("Retry acquiring DBM file lock this number of times.") },
+ { "lock-retry-timeout", mu_cfg_callback, NULL, 0,
+ config_cb_lock_retry_timeout,
+ N_("Set the time span between the two DBM locking attempts."),
N_("time") },
{ NULL }
@@ -378,6 +379,7 @@ static struct mf_option_cache option_cache[] = {
static const char *capa[] = {
"common",
"debug",
+ "locking",
NULL
};
@@ -416,9 +418,9 @@ main(int argc, char **argv)
db_format_setup();
database_cfg_init();
-
+ mf_init_lock_options();
mf_optcache_add(option_cache, 0, MF_OCF_NULL|MF_OCF_STATIC);
-
+
mu_argp_init(program_version, "<" PACKAGE_BUGREPORT ">");
/* FIXME: Use mailfromd.conf somehow? */
mu_site_rcfile = SYSCONFDIR "/mfdbtool.conf";

Return to:

Send suggestions and report system problems to the System administrator.