diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-07-21 11:00:26 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-07-21 12:28:40 +0300 |
commit | f5caaa1b756ebb9d30d69fb01b3b65e65ab3e2f4 (patch) | |
tree | 924f20c9f284364feb214e5ce2220795c4c39a81 | |
parent | c65ec9e84abbe87e673a11c15b3a6cecb9935d5b (diff) | |
download | mailfromd-f5caaa1b756ebb9d30d69fb01b3b65e65ab3e2f4.tar.gz mailfromd-f5caaa1b756ebb9d30d69fb01b3b65e65ab3e2f4.tar.bz2 |
Make runtime constants in builtin/*.bi sources configurable.
* mfd/mailfromd.h (mf_add_runtime_params): New proto.
* mfd/main.c (mf_cfg_param)<runtime>: New entry.
(mf_add_runtime_params,mf_runtime_param_finish): New functions.
(main): Call mf_runtime_param_finish.
* mfd/builtin/io.bi (nstreams): New static, used instead of
NSTREAMS macro.
(io_cfg_param, MF_INIT): Declare a
configuration statement to confifure nstreams.
* mfd/builtin/mbox.bi (nmboxes): New static, used instead of
NMBOXES macro.
(mbox_cfg_param, MF_INIT): Declare a
configuration statement to confifure nmboxes.
* mfd/builtin/msg.bi (nmsgs): New static, used instead of
NMSGS macro.
(msg_cfg_param, MF_INIT): Declare a
configuration statement to confifure nmsgs.
* doc/Makefile.am (check-runtime-config): New rule.
(all-check-docs): Depend on check-runtime-config.
(check-sub-config): Ignore the "runtime" section.
* doc/functions.texi: Document the runtime limits.
* doc/mailfromd.texi (conf-runtime): New node.
* doc/values.texi (NSTREAMS, NMBOXES, NMSGS): New values.
* mfd/msg.h: Moved to builtin.
* mfd/Makefile.am (noinst_HEADERS): Remove msg.h
* mfd/builtin/Makefile.am (noinst_HEADERS): Add msg.h
-rw-r--r-- | doc/Makefile.am | 14 | ||||
-rw-r--r-- | doc/functions.texi | 19 | ||||
-rw-r--r-- | doc/mailfromd.texi | 28 | ||||
-rw-r--r-- | doc/values.texi | 3 | ||||
-rw-r--r-- | mfd/Makefile.am | 3 | ||||
-rw-r--r-- | mfd/builtin/Makefile.am | 3 | ||||
-rw-r--r-- | mfd/builtin/io.bi | 33 | ||||
-rw-r--r-- | mfd/builtin/mbox.bi | 22 | ||||
-rw-r--r-- | mfd/builtin/msg.bi | 24 | ||||
-rw-r--r-- | mfd/builtin/msg.h (renamed from mfd/msg.h) | 0 | ||||
-rw-r--r-- | mfd/mailfromd.h | 2 | ||||
-rw-r--r-- | mfd/main.c | 56 |
12 files changed, 173 insertions, 34 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am index 8e2419c0..58d3dd0c 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -63,7 +63,7 @@ check-config: $(info_TEXINFOS) check-sub-config: - @list=`sed -n '/mf_cfg_param\[\] *= *{/,/^}/{s/[ \t]*{ *"\([^,"]*\)", *mu_cfg_section *,.*/\1/pg}' $(top_srcdir)/mfd/main.c`; \ + @list=`sed -n '/mf_cfg_param\[\] *= *{/,/^}/{s/[ \t]*{ *"\([^,"]*\)", *mu_cfg_section *,.*/\1/pg}' $(top_srcdir)/mfd/main.c | sed /^runtime$$/d`; \ for ident in $$list; do \ cident=`echo $$ident | tr '-' '_'`; \ check-docs.sh "$$ident configuration statements" \ @@ -74,6 +74,16 @@ check-sub-config: $(info_TEXINFOS); \ done +# FIXME: This rule does not take into account possible subsections. +# None of the *.bi sources declares them anyway, so it's OK for now. +check-runtime-config: + @check-docs.sh 'MFL runtime configuration statements' \ + '/struct *mu_cfg_param *[a-zA-Z_][a-zA-Z0-9_]*_cfg_param\[\] *= *{/,/^}/s/[ \t]*{ *"\([^,"]*\)".*/\1/pg' \ + 's/@deffn {runtime} *\([^@, ]*\).*/\1/p' \ + $(top_srcdir)/mfd/builtin/*.bi -- \ + $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) -E - \ + $(info_TEXINFOS) + check-builtins: @check-docs.sh builtins \ '/MF_DEFUN/{s/[ \t]*MF_DEFUN *(\([a-zA-Z_][a-zA-Z0-9_]*\),.*/\1/p;s/[ \t]*MF_DEFUN_VARARGS\(_NO_PROM\)\? *(\([a-zA-Z_][a-zA-Z0-9_]*\),.*/\2/p;s/[ \t]*MF_DEFUN_CTYPE *(\([a-zA-Z_][a-zA-Z0-9_]*\))/\1/p}'\ @@ -150,7 +160,7 @@ check-unrevised: fi all-check-docs: check-format check-options check-pragmas \ - check-config check-sub-config \ + check-config check-sub-config check-runtime-config \ check-builtins check-mflib check-exceptions \ check-refs check-fixmes check-writeme check-unrevised diff --git a/doc/functions.texi b/doc/functions.texi index 18b4a768..23595f43 100644 --- a/doc/functions.texi +++ b/doc/functions.texi @@ -980,6 +980,11 @@ mailbox does not exist, it is created. @end multitable @end deftypefn + The number of mailbox descriptors available for simultaneous opening +is @value{NMBOXES}. This value can be changed using the +@code{max-open-mailboxes} runtime configuration statement +(@pxref{conf-runtime, max-open-mailboxes}). + @deftypefn {Built-in Function} number mailbox_messages_count (number @var{nmbx}) Return the number of messages in mailbox. The argument @var{nmbx} is a valid mailbox descriptor as returned by a previous call to @@ -1017,7 +1022,10 @@ messages. The message to operate upon is identified by its @dfn{descriptor}, an integer number returned by the previous call to @code{mailbox_get_message} (@pxref{Mailbox functions, mailbox_get_message}) or @code{current_message} -(@pxref{current_message}) function. +(@pxref{current_message}) function. The maximum number of message +descriptors is limited by @value{NMSGS}. You can change this limit +using the @code{max-open-messages} runtime configuration statement +(@pxref{conf-runtime, max-open-messages}). @deftypefn {Built-in Function} number message_size (number @var{nmsg}) Return the size of the message @var{nmsg}, in bytes. @emph{Notice}, @@ -2017,6 +2025,11 @@ can write or read from it using this descriptor. Finally, when the resource is no longer needed, you can close it with a call to @code{close}. + The number of available resource descriptors is limited. The +default limit is @value{NSTREAMS}. You can tailor it to your needs +using the @code{max-streams} runtime configuration statement. +@xref{conf-runtime, max-streams}, for a detailed description. + @anchor{open} @deftypefn {Built-in Function} number open (string @var{name}) The @var{name} argument specifies the name of a resource to open and @@ -2114,8 +2127,8 @@ previous call to @code{open}. The function @code{close} closes the resource and deallocates any memory associated with it. @code{close} will signal @code{e_range} exception if @var{rd} lies -outside of allowed range of resource descriptors. @FIXME{More info on -it. Also, it should be configurable.} +outside of allowed range of resource descriptors. @xref{conf-runtime, +max-streams}. @end deftypefn Notice that you are not required to close resources opened by @code{open}. diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi index b3cb8e4a..651ab913 100644 --- a/doc/mailfromd.texi +++ b/doc/mailfromd.texi @@ -301,12 +301,14 @@ Configuring @command{mailfromd} * conf-types:: Special Configuration Data Types * conf-base:: Base Mailfromd Configuration +* conf-server:: Server Configuration * conf-milter:: Milter Connection Configuration * conf-debug:: Logging and Debugging configuration * conf-timeout:: Timeout Configuration * conf-callout:: Call-out Configuration * conf-priv:: Privilege Configuration * conf-database:: Database Configuration +* conf-runtime:: Runtime Constants * conf-mailutils:: Standard Mailutils Statements @command{Mailfromd} Command Line Syntax @@ -346,6 +348,7 @@ Pmult Configuration Upgrading +* 600-700:: Upgrading from 6.0 to 7.0 * 5x0-600:: Upgrading from 5.x to 6.0 * 500-510:: Upgrading from 5.0 to 5.1 * 440-500:: Upgrading from 4.4 to 5.0 @@ -8598,6 +8601,7 @@ Mailutils Manual}. * conf-callout:: Call-out Configuration * conf-priv:: Privilege Configuration * conf-database:: Database Configuration +* conf-runtime:: Runtime Constants * conf-mailutils:: Standard Mailutils Statements @end menu @@ -9148,6 +9152,30 @@ allowed as argument. Sets expiration interval for all databases. @end deffn +@node conf-runtime +@section Runtime Constants Configuration + +@deffn {Mailfromd Conf} runtime @{ statements @} +The statements in the @code{runtime} section configure various values +used by @acronym{MFL} builtin functions. +@end deffn + +@deffn {runtime} max-streams number +Sets the maximum number of stream descriptors that can be opened +simultaneously. Default is @value{NSTREAMS}. @xref{I/O functions}. +@end deffn + +@deffn {runtime} max-open-mailboxes number +Sets the maximum number of available mailbox descriptors. This value +is used by @acronym{MFL} mailbox functions (@pxref{Mailbox functions}). +@end deffn + +@deffn {runtime} max-open-messages number +Sets the maximum number of messages that can be opened simultaneosly +using the @code{mailbox_get_message} function. @xref{Message +functions}, for details. +@end deffn + @node conf-mailutils @section Standard Mailutils Statements diff --git a/doc/values.texi b/doc/values.texi index 3c139a57..e3007459 100644 --- a/doc/values.texi +++ b/doc/values.texi @@ -11,3 +11,6 @@ @set GACOPYZ_CONNECT_TIMEOUT 5 minutes @set MIN_EXCEPTION 0 @set MAX_EXCEPTION 16 +@set NSTREAMS 1024 +@set NMBOXES 64 +@set NMSGS 1024 diff --git a/mfd/Makefile.am b/mfd/Makefile.am index 5524d9f5..81ce6960 100644 --- a/mfd/Makefile.am +++ b/mfd/Makefile.am @@ -62,8 +62,7 @@ noinst_HEADERS = \ dns.h\ spf.h\ drivers.c\ - debug.h\ - msg.h + debug.h EXTRA_DIST = \ debug.hin\ diff --git a/mfd/builtin/Makefile.am b/mfd/builtin/Makefile.am index d0091751..ef1c60db 100644 --- a/mfd/builtin/Makefile.am +++ b/mfd/builtin/Makefile.am @@ -15,7 +15,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. noinst_LIBRARIES = libbuiltin.a -noinst_HEADERS = builtin.h +noinst_HEADERS = builtin.h msg.h + BI_FILES=\ body.bi\ ctype.bi\ diff --git a/mfd/builtin/io.bi b/mfd/builtin/io.bi index 5d0567e4..d7a48d5e 100644 --- a/mfd/builtin/io.bi +++ b/mfd/builtin/io.bi @@ -18,7 +18,13 @@ #include <sys/stat.h> #include <sys/wait.h> -#define NSTREAMS 1024 +static size_t nstreams = 1024; + +static struct mu_cfg_param io_cfg_param[] = { + { "max-streams", mu_cfg_size, &nstreams, 0, NULL, + N_("Maximum number of stream descriptors.") }, + { NULL } +}; struct io_stream { char *name; @@ -548,8 +554,8 @@ open_inet_stream(eval_environ_t env, static void * alloc_streams() { - struct io_stream *p, *stab = xcalloc(NSTREAMS, sizeof *stab); - for (p = stab; p < stab + NSTREAMS; p++) + struct io_stream *p, *stab = xcalloc(nstreams, sizeof *stab); + for (p = stab; p < stab + nstreams; p++) p->fd[0] = p->fd[1] = -1; return stab; } @@ -559,7 +565,7 @@ destroy_streams(void *data) { struct io_stream *stab = data; struct io_stream *p; - for (p = stab; p < stab + NSTREAMS; p++) { + for (p = stab; p < stab + nstreams; p++) { close_stream(p); free(p->buf); } @@ -577,11 +583,11 @@ MF_DEFUN(open, NUMBER, STRING name) struct io_stream *, const char *, int) = open_file_stream; struct io_stream *iotab = MF_GET_DATA; - for (i = 0; i < NSTREAMS; i++) { + for (i = 0; i < nstreams; i++) { if (iotab[i].fd[0] == -1) break; } - MF_ASSERT(i < NSTREAMS, + MF_ASSERT(i < nstreams, mfe_failure, _("no more files available")); @@ -628,7 +634,7 @@ MF_DEFUN(close, VOID, NUMBER fd) { struct io_stream *iotab = MF_GET_DATA; - MF_ASSERT(fd >= 0 && fd < NSTREAMS, + MF_ASSERT(fd >= 0 && fd < nstreams, mfe_range, _("invalid file descriptor")); close_stream(&iotab[fd]); @@ -641,7 +647,7 @@ MF_DEFUN(write, VOID, NUMBER fd, STRING str, OPTIONAL, NUMBER n) int rc; debug2(10, "writing %s to %d", str, fd); - MF_ASSERT(fd >= 0 && fd < NSTREAMS && OFD(iotab[fd]), + MF_ASSERT(fd >= 0 && fd < nstreams && OFD(iotab[fd]), mfe_range, _("invalid file descriptor")); if (!MF_DEFINED(n)) @@ -661,7 +667,7 @@ MF_DEFUN(read, STRING, NUMBER fd, NUMBER size) size_t off; char *s = MF_ALLOC_HEAP(off, size + 1); - MF_ASSERT(fd >= 0 && fd < NSTREAMS && IFD(iotab[fd]), + MF_ASSERT(fd >= 0 && fd < nstreams && IFD(iotab[fd]), mfe_range, _("invalid file descriptor")); @@ -684,7 +690,7 @@ MF_DEFUN(getdelim, STRING, NUMBER fd, STRING delim) struct io_stream *iotab = MF_GET_DATA; int rc; - MF_ASSERT(fd >= 0 && fd < NSTREAMS && IFD(iotab[fd]), + MF_ASSERT(fd >= 0 && fd < nstreams && IFD(iotab[fd]), mfe_range, _("invalid file descriptor")); rc = read_stream_delim(&iotab[fd], delim[0]); @@ -704,7 +710,7 @@ MF_DEFUN(getline, STRING, NUMBER fd) struct io_stream *iotab = MF_GET_DATA; int rc; - MF_ASSERT(fd >= 0 && fd < NSTREAMS && IFD(iotab[fd]), + MF_ASSERT(fd >= 0 && fd < nstreams && IFD(iotab[fd]), mfe_range, _("invalid file descriptor")); rc = read_stream_delim(&iotab[fd], '\n'); @@ -718,4 +724,7 @@ MF_DEFUN(getline, STRING, NUMBER fd) MF_RETURN_STRING(iotab[fd].buf); } END -MF_INIT + +MF_INIT([< + mf_add_runtime_params(io_cfg_param); + >]) diff --git a/mfd/builtin/mbox.bi b/mfd/builtin/mbox.bi index 52cb2301..87293d80 100644 --- a/mfd/builtin/mbox.bi +++ b/mfd/builtin/mbox.bi @@ -16,6 +16,14 @@ #include "msg.h" +static size_t nmboxes = NMBOXES; + +static struct mu_cfg_param mbox_cfg_param[] = { + { "max-open-mailboxes", mu_cfg_size, &nmboxes, 0, NULL, + N_("Maximum number of mailboxes to open simultaneously.") }, + { NULL } +}; + static int do_close(void *item, void *data) { @@ -38,7 +46,7 @@ close_mbox(struct mf_mbox *mp) static void * alloc_mboxes() { - return xcalloc(NMBOXES, sizeof(struct mf_mbox)); + return xcalloc(nmboxes, sizeof(struct mf_mbox)); } static void @@ -46,7 +54,7 @@ destroy_mboxes(void *data) { struct mf_mbox *mtab = data; struct mf_mbox *p; - for (p = mtab; p < mtab + NMBOXES; p++) { + for (p = mtab; p < mtab + nmboxes; p++) { close_mbox(p); } free(mtab); @@ -58,7 +66,7 @@ static int find_slot(struct mf_mbox *tab) { int i; - for (i = 0; i < NMBOXES; i++) + for (i = 0; i < nmboxes; i++) if (tab[i].mbox == NULL) return i; return -1; @@ -166,7 +174,7 @@ MF_DEFUN(mailbox_close, VOID, NUMBER md) { struct mf_mbox *mbtab = MF_GET_DATA; - MF_ASSERT(md >= 0 && md < NMBOXES, + MF_ASSERT(md >= 0 && md < nmboxes, mfe_range, _("invalid mailbox descriptor")); close_mbox(mbtab + md); @@ -177,7 +185,7 @@ m4_define([<DCL_MBOX>],[< struct mf_mbox *mbtab = MF_GET_DATA; struct mf_mbox *$1; - MF_ASSERT($2 >= 0 && $2 < NMBOXES, + MF_ASSERT($2 >= 0 && $2 < nmboxes, mfe_range, _("invalid mailbox descriptor")); $1 = mbtab + $2; @@ -238,4 +246,6 @@ MF_DEFUN(mailbox_append_message, VOID, NUMBER nmbx, NUMBER msgno) } END -MF_INIT +MF_INIT([< + mf_add_runtime_params(mbox_cfg_param); + >]) diff --git a/mfd/builtin/msg.bi b/mfd/builtin/msg.bi index e2532304..7c367769 100644 --- a/mfd/builtin/msg.bi +++ b/mfd/builtin/msg.bi @@ -16,10 +16,18 @@ #include "msg.h" +static size_t nmsgs = NMSGS; + +static struct mu_cfg_param msg_cfg_param[] = { + { "max-open-messages", mu_cfg_size, &nmsgs, 0, NULL, + N_("Maximum number of messages to open simultaneously.") }, + { NULL } +}; + static void * alloc_msgs() { - return xcalloc(NMSGS, sizeof(struct mf_message)); + return xcalloc(nmsgs, sizeof(struct mf_message)); } static void @@ -27,7 +35,7 @@ destroy_msgs(void *data) { struct mf_message *mtab = data; struct mf_message *p; - for (p = mtab; p < mtab + NMSGS; p++) { + for (p = mtab; p < mtab + nmsgs; p++) { bi_close_message(p); } free(mtab); @@ -38,7 +46,7 @@ drop_current_message(void *data) { int i; struct mf_message *tab = data; - for (i = 0; i < NMSGS; i++) + for (i = 0; i < nmsgs; i++) if (tab[i].msg && tab[i].current) { bi_close_message(&tab[i]); break; @@ -51,7 +59,7 @@ static int find_slot(struct mf_message *tab) { int i; - for (i = 0; i < NMSGS; i++) + for (i = 0; i < nmsgs; i++) if (tab[i].msg == NULL) return i; return -1; @@ -102,7 +110,7 @@ bi_get_current_message(eval_environ_t env) { int i; struct mf_message *tab = MF_GET_DATA; - for (i = 0; i < NMSGS; i++) + for (i = 0; i < nmsgs; i++) if (tab[i].msg && tab[i].current) return i; return -1; @@ -113,7 +121,7 @@ m4_define([<DCL_MSG>],[< struct mf_message *mtab = MF_GET_DATA; struct mf_message *$1; - MF_ASSERT($2 >= 0 && $2 < NMSGS, + MF_ASSERT($2 >= 0 && $2 < nmsgs, mfe_range, _("invalid message descriptor")); $1 = mtab + $2; @@ -456,4 +464,6 @@ MF_DEFUN(message_read_body_line, STRING, NUMBER nmsg) } END -MF_INIT +MF_INIT([< + mf_add_runtime_params(msg_cfg_param); + >]) diff --git a/mfd/msg.h b/mfd/builtin/msg.h index 46c3b23a..46c3b23a 100644 --- a/mfd/msg.h +++ b/mfd/builtin/msg.h diff --git a/mfd/mailfromd.h b/mfd/mailfromd.h index 14e1f53f..648a57d7 100644 --- a/mfd/mailfromd.h +++ b/mfd/mailfromd.h @@ -1091,6 +1091,8 @@ int mfd_app_init (struct argp *myargp, const char **capa, int argc, char **argv, int flags, int *pindex, void *app_data, void *cfg_data); +void mf_add_runtime_params(struct mu_cfg_param *p); + /* deprecation.c */ void deprecation_warning(const char *fmt, ...) MU_PRINTFLIKE(1,2); @@ -2180,7 +2180,7 @@ server_cfg_init() mu_cfg_section_add_params(section, server_section_param); } } - + static int @@ -2305,6 +2305,7 @@ struct mu_cfg_param mf_cfg_param[] = { N_("URL of the callout server"), N_("url") }, + { "runtime", mu_cfg_section, NULL }, { NULL } }; @@ -2320,6 +2321,58 @@ config_statement_type(const char *name) return mu_cfg_string; } + +static struct mu_cfg_param *runtime_param; +static size_t runtime_param_cnt; +static size_t runtime_param_max; + +static void +_add_runtime_param_entry(struct mu_cfg_param *p) +{ + if (runtime_param_cnt == runtime_param_max) { + if (runtime_param_max == 0) + runtime_param_max = 16; + runtime_param = x2nrealloc(runtime_param, + &runtime_param_max, + sizeof(runtime_param[0])); + } + runtime_param[runtime_param_cnt++] = *p; +} + +void +mf_add_runtime_params(struct mu_cfg_param *p) +{ + for (; p->ident; p++) + _add_runtime_param_entry(p); +} + +void +mf_runtime_param_finish() +{ + + if (runtime_param_cnt) { + static struct mu_cfg_param term = { NULL }; + struct mu_cfg_section *section; + + _add_runtime_param_entry(&term); + + if (mu_create_canned_section ("runtime", §ion) == 0) { + section->parser = server_section_parser; + section->docstring = N_("Configure MFL runtime values."); + section->label = NULL; + mu_cfg_section_add_params(section, runtime_param); + } + } else { + struct mu_cfg_param *p; + for (p = mf_cfg_param; p->ident; p++) { + if (strcmp (p->ident, "runtime") == 0) { + memset (p, 0, sizeof (*p)); + break; + } + } + } +} + /* Auxiliary functions */ @@ -2660,6 +2713,7 @@ main(int argc, char **argv) init_string_space(); init_symbols(); builtin_setup(); + mf_runtime_param_finish(); db_format_setup(); include_path_setup(); pragma_setup(); |