From 0cd5fd23fdc042cd634a1033350bf91689f26d3c Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 8 May 2016 13:26:13 +0100 Subject: [PATCH] New $queue_name variable queue_run_max main option expanded, allowing per-queue values --- doc/doc-docbook/spec.xfpt | 17 ++++++++++++++++- doc/doc-txt/NewStuff | 5 +++-- src/src/daemon.c | 20 +++++++++----------- src/src/expand.c | 1 + src/src/globals.c | 2 +- src/src/globals.h | 2 +- src/src/readconf.c | 2 +- test/confs/0001 | 2 +- test/confs/0574 | 11 ++++++++++- test/log/0574 | 3 +++ test/scripts/0000-Basic/0002 | 1 + test/stdout/0002 | 1 + 12 files changed, 48 insertions(+), 19 deletions(-) diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 7b1e1ecb6..50ce06e08 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -12208,6 +12208,14 @@ The value set for the &%qualify_domain%& option in the configuration file. The value set for the &%qualify_recipient%& option in the configuration file, or if not set, the value of &$qualify_domain$&. +.new +.vitem &$queue_name$& +.vindex &$queue_name$& +.cindex "named queues" +.cindex queues named +The name of the spool queue in use; empty for the default queue. +.wen + .vitem &$rcpt_count$& .vindex "&$rcpt_count$&" When a message is being received by SMTP, this variable contains the number of @@ -15918,7 +15926,7 @@ large list. In most situations, &%queue_run_in_order%& should not be set. -.option queue_run_max main integer 5 +.option queue_run_max main integer&!! 5 .cindex "queue runner" "maximum number of" This controls the maximum number of queue runner processes that an Exim daemon can run simultaneously. This does not mean that it starts them all at once, @@ -15933,6 +15941,13 @@ the limit, allowing any number of simultaneous queue runner processes to be run. If you do not want queue runs to occur, omit the &%-q%&&'xx'& setting on the daemon's command line. +.new +.cindex queues named +.condex "named queues" +To set limits for different named queues use +an expansion depending on the &$queue_name$& variable. +.wen + .option queue_smtp_domains main "domain list&!!" unset .cindex "queueing incoming messages" .cindex "message" "queueing remote deliveries" diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index aabeff338..912fe65ee 100644 --- a/doc/doc-txt/NewStuff +++ b/doc/doc-txt/NewStuff @@ -12,9 +12,10 @@ Version 4.88 1. The new perl_tainmode option allows to run the embedded perl interpreter in taint mode. - 2. Facility for named queues. A commandline argument can specify + 2. Facility for named queues: A commandline argument can specify the queue name for a queue-runner, and an ACL modifier can set - the queue to be used for a message. + the queue to be used for a message. A $queue_name variable gives + visibility. Version 4.87 diff --git a/src/src/daemon.c b/src/src/daemon.c index 60ef33773..3634ad448 100644 --- a/src/src/daemon.c +++ b/src/src/daemon.c @@ -866,10 +866,10 @@ while ((pid = waitpid(-1, &status, WNOHANG)) > 0) /* If it wasn't an accepting process, see if it was a queue-runner process that we are tracking. */ - if (queue_pid_slots != NULL) + if (queue_pid_slots) { - for (i = 0; i < queue_run_max; i++) - { + int max = atoi(expand_string(queue_run_max)); + for (i = 0; i < max; i++) if (queue_pid_slots[i] == pid) { queue_pid_slots[i] = 0; @@ -878,7 +878,6 @@ while ((pid = waitpid(-1, &status, WNOHANG)) > 0) queue_run_count, (queue_run_count == 1)? "" : "es"); break; } - } } } } @@ -916,6 +915,7 @@ int *listen_sockets = NULL; int listen_socket_count = 0; ip_address_item *addresses = NULL; time_t last_connection_time = (time_t)0; +int local_queue_run_max = atoi(expand_string(queue_run_max)); /* If any debugging options are set, turn on the D_pid bit so that all debugging lines get the pid added. */ @@ -1572,11 +1572,11 @@ originator_login = ((pw = getpwuid(exim_uid)) != NULL)? /* Get somewhere to keep the list of queue-runner pids if we are keeping track of them (and also if we are doing queue runs). */ -if (queue_interval > 0 && queue_run_max > 0) +if (queue_interval > 0 && local_queue_run_max > 0) { int i; - queue_pid_slots = store_get(queue_run_max * sizeof(pid_t)); - for (i = 0; i < queue_run_max; i++) queue_pid_slots[i] = 0; + queue_pid_slots = store_get(local_queue_run_max * sizeof(pid_t)); + for (i = 0; i < local_queue_run_max; i++) queue_pid_slots[i] = 0; } /* Set up the handler for termination of child processes. */ @@ -1791,7 +1791,7 @@ for (;;) re-exec is required. */ if (queue_interval > 0 && - (queue_run_max <= 0 || queue_run_count < queue_run_max)) + (local_queue_run_max <= 0 || queue_run_count < local_queue_run_max)) { if ((pid = fork()) == 0) { @@ -1879,15 +1879,13 @@ for (;;) else { int i; - for (i = 0; i < queue_run_max; ++i) - { + for (i = 0; i < local_queue_run_max; ++i) if (queue_pid_slots[i] <= 0) { queue_pid_slots[i] = pid; queue_run_count++; break; } - } DEBUG(D_any) debug_printf("%d queue-runner process%s running\n", queue_run_count, (queue_run_count == 1)? "" : "es"); } diff --git a/src/src/expand.c b/src/src/expand.c index f783682b4..249254923 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -625,6 +625,7 @@ static var_entry var_table[] = { { "prvscheck_result", vtype_stringptr, &prvscheck_result }, { "qualify_domain", vtype_stringptr, &qualify_domain_sender }, { "qualify_recipient", vtype_stringptr, &qualify_domain_recipient }, + { "queue_name", vtype_stringptr, &queue_name }, { "rcpt_count", vtype_int, &rcpt_count }, { "rcpt_defer_count", vtype_int, &rcpt_defer_count }, { "rcpt_fail_count", vtype_int, &rcpt_fail_count }, diff --git a/src/src/globals.c b/src/src/globals.c index 8b2287aca..3ba82e0a7 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1031,7 +1031,7 @@ BOOL queue_run_first_delivery = FALSE; BOOL queue_run_force = FALSE; BOOL queue_run_in_order = FALSE; BOOL queue_run_local = FALSE; -int queue_run_max = 5; +uschar *queue_run_max = US"5"; pid_t queue_run_pid = (pid_t)0; int queue_run_pipe = -1; BOOL queue_running = FALSE; diff --git a/src/src/globals.h b/src/src/globals.h index bd7518074..362c2bfb9 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -677,7 +677,7 @@ extern uschar *queue_only_file; /* Queue if file exists/not-exists */ extern BOOL queue_only_override; /* Allow override from command line */ extern BOOL queue_only_policy; /* ACL or local_scan wants queue_only */ extern BOOL queue_run_in_order; /* As opposed to random */ -extern int queue_run_max; /* Max queue runners */ +extern uschar *queue_run_max; /* Max queue runners */ extern BOOL queue_smtp; /* Disable all immediate STMP (-odqs)*/ extern uschar *queue_smtp_domains; /* Ditto, for these domains */ diff --git a/src/src/readconf.c b/src/src/readconf.c index 375f01a1a..63a164122 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -374,7 +374,7 @@ static optionlist optionlist_config[] = { { "queue_only_load_latch", opt_bool, &queue_only_load_latch }, { "queue_only_override", opt_bool, &queue_only_override }, { "queue_run_in_order", opt_bool, &queue_run_in_order }, - { "queue_run_max", opt_int, &queue_run_max }, + { "queue_run_max", opt_stringptr, &queue_run_max }, { "queue_smtp_domains", opt_stringptr, &queue_smtp_domains }, { "receive_timeout", opt_time, &receive_timeout }, { "received_header_text", opt_stringptr, &received_header_text }, diff --git a/test/confs/0001 b/test/confs/0001 index 0daf053bd..0fd7efe44 100644 --- a/test/confs/0001 +++ b/test/confs/0001 @@ -148,7 +148,7 @@ no_queue_only_override queue_only_file = /var/spool/exim/queue_only queue_only_load = 8.2 no_queue_run_in_order -queue_run_max = 5 +queue_run_max = ${if = {1}{1} {5}{10}} queue_smtp_domains = x.y.z receive_timeout = 0s received_header_text = Received: ${if def:sender_rcvhost {from ${sender_rcvhost}\n\t}{${if def:sender_ident {from ${sender_ident} }}${if def:sender_helo_name {(helo=${sender_helo_name})\n\t}}}}by ${primary_hostname} ${if def:received_protocol {with ${received_protocol}}} (Exim ${version_number} #${compile_number})\n\tid ${message_id}${if def:received_for {\n\tfor $received_for}} diff --git a/test/confs/0574 b/test/confs/0574 index 722988a29..289ed1955 100644 --- a/test/confs/0574 +++ b/test/confs/0574 @@ -13,12 +13,21 @@ tls_advertise_hosts = log_selector = +received_recipients +sender_on_delivery -acl_smtp_rcpt = accept queue = ${if eq {normal}{$local_part} {} {$local_part}} +acl_smtp_rcpt = rcpt queue_only queue_run_in_order #--------------- +begin acl + +rcpt: + accept + queue = ${if eq {normal}{$local_part} {} {$local_part}} + logwrite = using queue '$queue_name' + +#--------------- + begin routers all: diff --git a/test/log/0574 b/test/log/0574 index 6b3ed743c..042d10c6e 100644 --- a/test/log/0574 +++ b/test/log/0574 @@ -1,4 +1,6 @@ +1999-03-02 09:44:33 using queue '' 1999-03-02 09:44:33 10HmaX-0005vi-00 <= CALLER@the.local.host.name U=CALLER P=local-smtp S=sss for normal@test.ex +1999-03-02 09:44:33 using queue 'alternate' 1999-03-02 09:44:33 10HmaY-0005vi-00 <= CALLER@the.local.host.name U=CALLER P=local-smtp S=sss Q=alternate for alternate@test.ex 1999-03-02 09:44:33 Start queue run: pid=pppp -qq 1999-03-02 09:44:33 10HmaX-0005vi-00 => normal F= R=all T=dump @@ -10,6 +12,7 @@ 1999-03-02 09:44:33 10HmaY-0005vi-00 => alternate F= Q=alternate R=all T=dump 1999-03-02 09:44:33 10HmaY-0005vi-00 Completed 1999-03-02 09:44:33 End 'alternate' queue run: pid=pppp +1999-03-02 09:44:33 using queue 'lowpri' 1999-03-02 09:44:33 10HmaZ-0005vi-00 <= CALLER@the.local.host.name U=CALLER P=local-smtp S=sss Q=lowpri for lowpri@test.ex ******** SERVER ******** diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002 index 583adcff0..278a38660 100644 --- a/test/scripts/0000-Basic/0002 +++ b/test/scripts/0000-Basic/0002 @@ -23,6 +23,7 @@ primary_hostname: ${primary_hostname} qualify_domain: $qualify_domain bounce_return_size_limit: ${bounce_return_size_limit} spool_directory: $spool_directory +queue_name: $queue_name unknown: ${unknown} h_subject: $h_subject:(should be empty) h_subject:$h_subject (should be empty) diff --git a/test/stdout/0002 b/test/stdout/0002 index 9a2768bdc..0bbd4c754 100644 --- a/test/stdout/0002 +++ b/test/stdout/0002 @@ -14,6 +14,7 @@ > qualify_domain: myhost.test.ex > bounce_return_size_limit: 102400 > spool_directory: TESTSUITE/spool +> queue_name: > Failed: unknown variable in "${unknown}" > h_subject: (should be empty) > h_subject: (should be empty) -- 2.25.1