Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / oqmgr / qmgr.c
blobab5d4ec01060498210ffcda86e32944cc3e0284c
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* qmgr 8
6 /* SUMMARY
7 /* old Postfix queue manager
8 /* SYNOPSIS
9 /* \fBqmgr\fR [generic Postfix daemon options]
10 /* DESCRIPTION
11 /* The \fBqmgr\fR(8) daemon awaits the arrival of incoming mail
12 /* and arranges for its delivery via Postfix delivery processes.
13 /* The actual mail routing strategy is delegated to the
14 /* \fBtrivial-rewrite\fR(8) daemon.
15 /* This program expects to be run from the \fBmaster\fR(8) process
16 /* manager.
18 /* Mail addressed to the local \fBdouble-bounce\fR address is
19 /* logged and discarded. This stops potential loops caused by
20 /* undeliverable bounce notifications.
21 /* MAIL QUEUES
22 /* .ad
23 /* .fi
24 /* The \fBqmgr\fR(8) daemon maintains the following queues:
25 /* .IP \fBincoming\fR
26 /* Inbound mail from the network, or mail picked up by the
27 /* local \fBpickup\fR(8) agent from the \fBmaildrop\fR directory.
28 /* .IP \fBactive\fR
29 /* Messages that the queue manager has opened for delivery. Only
30 /* a limited number of messages is allowed to enter the \fBactive\fR
31 /* queue (leaky bucket strategy, for a fixed delivery rate).
32 /* .IP \fBdeferred\fR
33 /* Mail that could not be delivered upon the first attempt. The queue
34 /* manager implements exponential backoff by doubling the time between
35 /* delivery attempts.
36 /* .IP \fBcorrupt\fR
37 /* Unreadable or damaged queue files are moved here for inspection.
38 /* .IP \fBhold\fR
39 /* Messages that are kept "on hold" are kept here until someone
40 /* sets them free.
41 /* DELIVERY STATUS REPORTS
42 /* .ad
43 /* .fi
44 /* The \fBqmgr\fR(8) daemon keeps an eye on per-message delivery status
45 /* reports in the following directories. Each status report file has
46 /* the same name as the corresponding message file:
47 /* .IP \fBbounce\fR
48 /* Per-recipient status information about why mail is bounced.
49 /* These files are maintained by the \fBbounce\fR(8) daemon.
50 /* .IP \fBdefer\fR
51 /* Per-recipient status information about why mail is delayed.
52 /* These files are maintained by the \fBdefer\fR(8) daemon.
53 /* .IP \fBtrace\fR
54 /* Per-recipient status information as requested with the
55 /* Postfix "\fBsendmail -v\fR" or "\fBsendmail -bv\fR" command.
56 /* These files are maintained by the \fBtrace\fR(8) daemon.
57 /* .PP
58 /* The \fBqmgr\fR(8) daemon is responsible for asking the
59 /* \fBbounce\fR(8), \fBdefer\fR(8) or \fBtrace\fR(8) daemons to
60 /* send delivery reports.
61 /* STRATEGIES
62 /* .ad
63 /* .fi
64 /* The queue manager implements a variety of strategies for
65 /* either opening queue files (input) or for message delivery (output).
66 /* .IP "\fBleaky bucket\fR"
67 /* This strategy limits the number of messages in the \fBactive\fR queue
68 /* and prevents the queue manager from running out of memory under
69 /* heavy load.
70 /* .IP \fBfairness\fR
71 /* When the \fBactive\fR queue has room, the queue manager takes one
72 /* message from the \fBincoming\fR queue and one from the \fBdeferred\fR
73 /* queue. This prevents a large mail backlog from blocking the delivery
74 /* of new mail.
75 /* .IP "\fBslow start\fR"
76 /* This strategy eliminates "thundering herd" problems by slowly
77 /* adjusting the number of parallel deliveries to the same destination.
78 /* .IP "\fBround robin\fR
79 /* The queue manager sorts delivery requests by destination.
80 /* Round-robin selection prevents one destination from dominating
81 /* deliveries to other destinations.
82 /* .IP "\fBexponential backoff\fR"
83 /* Mail that cannot be delivered upon the first attempt is deferred.
84 /* The time interval between delivery attempts is doubled after each
85 /* attempt.
86 /* .IP "\fBdestination status cache\fR"
87 /* The queue manager avoids unnecessary delivery attempts by
88 /* maintaining a short-term, in-memory list of unreachable destinations.
89 /* TRIGGERS
90 /* .ad
91 /* .fi
92 /* On an idle system, the queue manager waits for the arrival of
93 /* trigger events, or it waits for a timer to go off. A trigger
94 /* is a one-byte message.
95 /* Depending on the message received, the queue manager performs
96 /* one of the following actions (the message is followed by the
97 /* symbolic constant used internally by the software):
98 /* .IP "\fBD (QMGR_REQ_SCAN_DEFERRED)\fR"
99 /* Start a deferred queue scan. If a deferred queue scan is already
100 /* in progress, that scan will be restarted as soon as it finishes.
101 /* .IP "\fBI (QMGR_REQ_SCAN_INCOMING)\fR"
102 /* Start an incoming queue scan. If an incoming queue scan is already
103 /* in progress, that scan will be restarted as soon as it finishes.
104 /* .IP "\fBA (QMGR_REQ_SCAN_ALL)\fR"
105 /* Ignore deferred queue file time stamps. The request affects
106 /* the next deferred queue scan.
107 /* .IP "\fBF (QMGR_REQ_FLUSH_DEAD)\fR"
108 /* Purge all information about dead transports and destinations.
109 /* .IP "\fBW (TRIGGER_REQ_WAKEUP)\fR"
110 /* Wakeup call, This is used by the master server to instantiate
111 /* servers that should not go away forever. The action is to start
112 /* an incoming queue scan.
113 /* .PP
114 /* The \fBqmgr\fR(8) daemon reads an entire buffer worth of triggers.
115 /* Multiple identical trigger requests are collapsed into one, and
116 /* trigger requests are sorted so that \fBA\fR and \fBF\fR precede
117 /* \fBD\fR and \fBI\fR. Thus, in order to force a deferred queue run,
118 /* one would request \fBA F D\fR; in order to notify the queue manager
119 /* of the arrival of new mail one would request \fBI\fR.
120 /* STANDARDS
121 /* RFC 3463 (Enhanced status codes)
122 /* RFC 3464 (Delivery status notifications)
123 /* SECURITY
124 /* .ad
125 /* .fi
126 /* The \fBqmgr\fR(8) daemon is not security sensitive. It reads
127 /* single-character messages from untrusted local users, and thus may
128 /* be susceptible to denial of service attacks. The \fBqmgr\fR(8) daemon
129 /* does not talk to the outside world, and it can be run at fixed low
130 /* privilege in a chrooted environment.
131 /* DIAGNOSTICS
132 /* Problems and transactions are logged to the \fBsyslog\fR(8) daemon.
133 /* Corrupted message files are saved to the \fBcorrupt\fR queue
134 /* for further inspection.
136 /* Depending on the setting of the \fBnotify_classes\fR parameter,
137 /* the postmaster is notified of bounces and of other trouble.
138 /* BUGS
139 /* A single queue manager process has to compete for disk access with
140 /* multiple front-end processes such as \fBcleanup\fR(8). A sudden burst of
141 /* inbound mail can negatively impact outbound delivery rates.
142 /* CONFIGURATION PARAMETERS
143 /* .ad
144 /* .fi
145 /* Changes to \fBmain.cf\fR are not picked up automatically,
146 /* as \fBqmgr\fR(8)
147 /* is a persistent process. Use the command "\fBpostfix reload\fR" after
148 /* a configuration change.
150 /* The text below provides only a parameter summary. See
151 /* \fBpostconf\fR(5) for more details including examples.
153 /* In the text below, \fItransport\fR is the first field in a
154 /* \fBmaster.cf\fR entry.
155 /* COMPATIBILITY CONTROLS
156 /* .ad
157 /* .fi
158 /* Available before Postfix version 2.5:
159 /* .IP "\fBallow_min_user (no)\fR"
160 /* Allow a sender or recipient address to have `-' as the first
161 /* character.
162 /* ACTIVE QUEUE CONTROLS
163 /* .ad
164 /* .fi
165 /* .IP "\fBqmgr_clog_warn_time (300s)\fR"
166 /* The minimal delay between warnings that a specific destination is
167 /* clogging up the Postfix active queue.
168 /* .IP "\fBqmgr_message_active_limit (20000)\fR"
169 /* The maximal number of messages in the active queue.
170 /* .IP "\fBqmgr_message_recipient_limit (20000)\fR"
171 /* The maximal number of recipients held in memory by the Postfix
172 /* queue manager, and the maximal size of the size of the short-term,
173 /* in-memory "dead" destination status cache.
174 /* DELIVERY CONCURRENCY CONTROLS
175 /* .ad
176 /* .fi
177 /* .IP "\fBqmgr_fudge_factor (100)\fR"
178 /* Obsolete feature: the percentage of delivery resources that a busy
179 /* mail system will use up for delivery of a large mailing list
180 /* message.
181 /* .IP "\fBinitial_destination_concurrency (5)\fR"
182 /* The initial per-destination concurrency level for parallel delivery
183 /* to the same destination.
184 /* .IP "\fBdefault_destination_concurrency_limit (20)\fR"
185 /* The default maximal number of parallel deliveries to the same
186 /* destination.
187 /* .IP "\fItransport\fB_destination_concurrency_limit ($default_destination_concurrency_limit)\fR"
188 /* Idem, for delivery via the named message \fItransport\fR.
189 /* .PP
190 /* Available in Postfix version 2.5 and later:
191 /* .IP "\fItransport\fB_initial_destination_concurrency ($initial_destination_concurrency)\fR"
192 /* Initial concurrency for delivery via the named message
193 /* \fItransport\fR.
194 /* .IP "\fBdefault_destination_concurrency_failed_cohort_limit (1)\fR"
195 /* How many pseudo-cohorts must suffer connection or handshake
196 /* failure before a specific destination is considered unavailable
197 /* (and further delivery is suspended).
198 /* .IP "\fItransport\fB_destination_concurrency_failed_cohort_limit ($default_destination_concurrency_failed_cohort_limit)\fR"
199 /* Idem, for delivery via the named message \fItransport\fR.
200 /* .IP "\fBdefault_destination_concurrency_negative_feedback (1)\fR"
201 /* The per-destination amount of delivery concurrency negative
202 /* feedback, after a delivery completes with a connection or handshake
203 /* failure.
204 /* .IP "\fItransport\fB_destination_concurrency_negative_feedback ($default_destination_concurrency_negative_feedback)\fR"
205 /* Idem, for delivery via the named message \fItransport\fR.
206 /* .IP "\fBdefault_destination_concurrency_positive_feedback (1)\fR"
207 /* The per-destination amount of delivery concurrency positive
208 /* feedback, after a delivery completes without connection or handshake
209 /* failure.
210 /* .IP "\fItransport\fB_destination_concurrency_positive_feedback ($default_destination_concurrency_positive_feedback)\fR"
211 /* Idem, for delivery via the named message \fItransport\fR.
212 /* .IP "\fBdestination_concurrency_feedback_debug (no)\fR"
213 /* Make the queue manager's feedback algorithm verbose for performance
214 /* analysis purposes.
215 /* RECIPIENT SCHEDULING CONTROLS
216 /* .ad
217 /* .fi
218 /* .IP "\fBdefault_destination_recipient_limit (50)\fR"
219 /* The default maximal number of recipients per message delivery.
220 /* .IP \fItransport\fB_destination_recipient_limit\fR
221 /* Idem, for delivery via the named message \fItransport\fR.
222 /* OTHER RESOURCE AND RATE CONTROLS
223 /* .ad
224 /* .fi
225 /* .IP "\fBminimal_backoff_time (300s)\fR"
226 /* The minimal time between attempts to deliver a deferred message;
227 /* prior to Postfix 2.4 the default value was 1000s.
228 /* .IP "\fBmaximal_backoff_time (4000s)\fR"
229 /* The maximal time between attempts to deliver a deferred message.
230 /* .IP "\fBmaximal_queue_lifetime (5d)\fR"
231 /* The maximal time a message is queued before it is sent back as
232 /* undeliverable.
233 /* .IP "\fBqueue_run_delay (300s)\fR"
234 /* The time between deferred queue scans by the queue manager;
235 /* prior to Postfix 2.4 the default value was 1000s.
236 /* .IP "\fBtransport_retry_time (60s)\fR"
237 /* The time between attempts by the Postfix queue manager to contact
238 /* a malfunctioning message delivery transport.
239 /* .PP
240 /* Available in Postfix version 2.1 and later:
241 /* .IP "\fBbounce_queue_lifetime (5d)\fR"
242 /* The maximal time a bounce message is queued before it is considered
243 /* undeliverable.
244 /* .PP
245 /* Available in Postfix version 2.5 and later:
246 /* .IP "\fBdefault_destination_rate_delay (0s)\fR"
247 /* The default amount of delay that is inserted between individual
248 /* deliveries to the same destination; with per-destination recipient
249 /* limit > 1, a destination is a domain, otherwise it is a recipient.
250 /* .IP "\fItransport\fB_destination_rate_delay $default_destination_rate_delay
251 /* Idem, for delivery via the named message \fItransport\fR.
252 /* .SH MISCELLANEOUS CONTROLS
253 /* .ad
254 /* .fi
255 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
256 /* The default location of the Postfix main.cf and master.cf
257 /* configuration files.
258 /* .IP "\fBdefer_transports (empty)\fR"
259 /* The names of message delivery transports that should not deliver mail
260 /* unless someone issues "\fBsendmail -q\fR" or equivalent.
261 /* .IP "\fBdelay_logging_resolution_limit (2)\fR"
262 /* The maximal number of digits after the decimal point when logging
263 /* sub-second delay values.
264 /* .IP "\fBhelpful_warnings (yes)\fR"
265 /* Log warnings about problematic configuration settings, and provide
266 /* helpful suggestions.
267 /* .IP "\fBipc_timeout (3600s)\fR"
268 /* The time limit for sending or receiving information over an internal
269 /* communication channel.
270 /* .IP "\fBprocess_id (read-only)\fR"
271 /* The process ID of a Postfix command or daemon process.
272 /* .IP "\fBprocess_name (read-only)\fR"
273 /* The process name of a Postfix command or daemon process.
274 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
275 /* The location of the Postfix top-level queue directory.
276 /* .IP "\fBsyslog_facility (mail)\fR"
277 /* The syslog facility of Postfix logging.
278 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR"
279 /* The mail system name that is prepended to the process name in syslog
280 /* records, so that "smtpd" becomes, for example, "postfix/smtpd".
281 /* FILES
282 /* /var/spool/postfix/incoming, incoming queue
283 /* /var/spool/postfix/active, active queue
284 /* /var/spool/postfix/deferred, deferred queue
285 /* /var/spool/postfix/bounce, non-delivery status
286 /* /var/spool/postfix/defer, non-delivery status
287 /* /var/spool/postfix/trace, delivery status
288 /* SEE ALSO
289 /* trivial-rewrite(8), address routing
290 /* bounce(8), delivery status reports
291 /* postconf(5), configuration parameters
292 /* master(5), generic daemon options
293 /* master(8), process manager
294 /* syslogd(8), system logging
295 /* README FILES
296 /* .ad
297 /* .fi
298 /* Use "\fBpostconf readme_directory\fR" or
299 /* "\fBpostconf html_directory\fR" to locate this information.
300 /* .na
301 /* .nf
302 /* QSHAPE_README, Postfix queue analysis
303 /* LICENSE
304 /* .ad
305 /* .fi
306 /* The Secure Mailer license must be distributed with this software.
307 /* AUTHOR(S)
308 /* Wietse Venema
309 /* IBM T.J. Watson Research
310 /* P.O. Box 704
311 /* Yorktown Heights, NY 10598, USA
312 /*--*/
314 /* System library. */
316 #include <sys_defs.h>
317 #include <stdlib.h>
318 #include <unistd.h>
319 #include <ctype.h>
321 /* Utility library. */
323 #include <msg.h>
324 #include <events.h>
325 #include <vstream.h>
326 #include <dict.h>
328 /* Global library. */
330 #include <mail_queue.h>
331 #include <recipient_list.h>
332 #include <mail_conf.h>
333 #include <mail_params.h>
334 #include <mail_version.h>
335 #include <mail_proto.h> /* QMGR_SCAN constants */
336 #include <mail_flow.h>
337 #include <flush_clnt.h>
339 /* Master process interface */
341 #include <master_proto.h>
342 #include <mail_server.h>
344 /* Application-specific. */
346 #include "qmgr.h"
349 * Tunables.
351 int var_queue_run_delay;
352 int var_min_backoff_time;
353 int var_max_backoff_time;
354 int var_max_queue_time;
355 int var_dsn_queue_time;
356 int var_qmgr_active_limit;
357 int var_qmgr_rcpt_limit;
358 int var_init_dest_concurrency;
359 int var_transport_retry_time;
360 int var_dest_con_limit;
361 int var_dest_rcpt_limit;
362 char *var_defer_xports;
363 int var_qmgr_fudge;
364 int var_local_rcpt_lim; /* XXX */
365 int var_local_con_lim; /* XXX */
366 int var_proc_limit;
367 bool var_verp_bounce_off;
368 int var_qmgr_clog_warn_time;
369 char *var_conc_pos_feedback;
370 char *var_conc_neg_feedback;
371 int var_conc_cohort_limit;
372 int var_conc_feedback_debug;
373 int var_dest_rate_delay;
375 static QMGR_SCAN *qmgr_scans[2];
377 #define QMGR_SCAN_IDX_INCOMING 0
378 #define QMGR_SCAN_IDX_DEFERRED 1
379 #define QMGR_SCAN_IDX_COUNT (sizeof(qmgr_scans) / sizeof(qmgr_scans[0]))
381 /* qmgr_deferred_run_event - queue manager heartbeat */
383 static void qmgr_deferred_run_event(int unused_event, char *dummy)
387 * This routine runs when it is time for another deferred queue scan.
388 * Make sure this routine gets called again in the future.
390 qmgr_scan_request(qmgr_scans[QMGR_SCAN_IDX_DEFERRED], QMGR_SCAN_START);
391 event_request_timer(qmgr_deferred_run_event, dummy, var_queue_run_delay);
394 /* qmgr_trigger_event - respond to external trigger(s) */
396 static void qmgr_trigger_event(char *buf, int len,
397 char *unused_service, char **argv)
399 int incoming_flag = 0;
400 int deferred_flag = 0;
401 int i;
404 * Sanity check. This service takes no command-line arguments.
406 if (argv[0])
407 msg_fatal("unexpected command-line argument: %s", argv[0]);
410 * Collapse identical requests that have arrived since we looked last
411 * time. There is no client feedback so there is no need to process each
412 * request in order. And as long as we don't have conflicting requests we
413 * are free to sort them into the most suitable order.
415 #define QMGR_FLUSH_BEFORE (QMGR_FLUSH_ONCE | QMGR_FLUSH_DFXP)
417 for (i = 0; i < len; i++) {
418 if (msg_verbose)
419 msg_info("request: %d (%c)",
420 buf[i], ISALNUM(buf[i]) ? buf[i] : '?');
421 switch (buf[i]) {
422 case TRIGGER_REQ_WAKEUP:
423 case QMGR_REQ_SCAN_INCOMING:
424 incoming_flag |= QMGR_SCAN_START;
425 break;
426 case QMGR_REQ_SCAN_DEFERRED:
427 deferred_flag |= QMGR_SCAN_START;
428 break;
429 case QMGR_REQ_FLUSH_DEAD:
430 deferred_flag |= QMGR_FLUSH_BEFORE;
431 incoming_flag |= QMGR_FLUSH_BEFORE;
432 break;
433 case QMGR_REQ_SCAN_ALL:
434 deferred_flag |= QMGR_SCAN_ALL;
435 incoming_flag |= QMGR_SCAN_ALL;
436 break;
437 default:
438 if (msg_verbose)
439 msg_info("request ignored");
440 break;
445 * Process each request type at most once. Modifiers take effect upon the
446 * next queue run. If no queue run is in progress, and a queue scan is
447 * requested, the request takes effect immediately.
449 if (incoming_flag != 0)
450 qmgr_scan_request(qmgr_scans[QMGR_SCAN_IDX_INCOMING], incoming_flag);
451 if (deferred_flag != 0)
452 qmgr_scan_request(qmgr_scans[QMGR_SCAN_IDX_DEFERRED], deferred_flag);
455 /* qmgr_loop - queue manager main loop */
457 static int qmgr_loop(char *unused_name, char **unused_argv)
459 char *path;
460 int token_count;
461 int feed = 0;
462 int scan_idx; /* Priority order scan index */
463 static int first_scan_idx = QMGR_SCAN_IDX_INCOMING;
464 int last_scan_idx = QMGR_SCAN_IDX_COUNT - 1;
465 int delay;
468 * This routine runs as part of the event handling loop, after the event
469 * manager has delivered a timer or I/O event (including the completion
470 * of a connection to a delivery process), or after it has waited for a
471 * specified amount of time. The result value of qmgr_loop() specifies
472 * how long the event manager should wait for the next event.
474 #define DONT_WAIT 0
475 #define WAIT_FOR_EVENT (-1)
478 * Attempt to drain the active queue by allocating a suitable delivery
479 * process and by delivering mail via it. Delivery process allocation and
480 * mail delivery are asynchronous.
482 qmgr_active_drain();
485 * Let some new blood into the active queue when the queue size is
486 * smaller than some configurable limit, and when the number of in-core
487 * recipients does not exceed some configurable limit.
489 * We import one message per interrupt, to optimally tune the input count
490 * for the number of delivery agent protocol wait states, as explained in
491 * qmgr_transport.c.
493 delay = WAIT_FOR_EVENT;
494 for (scan_idx = 0; qmgr_message_count < var_qmgr_active_limit
495 && qmgr_recipient_count < var_qmgr_rcpt_limit
496 && scan_idx < QMGR_SCAN_IDX_COUNT; ++scan_idx) {
497 last_scan_idx = (scan_idx + first_scan_idx) % QMGR_SCAN_IDX_COUNT;
498 if ((path = qmgr_scan_next(qmgr_scans[last_scan_idx])) != 0) {
499 delay = DONT_WAIT;
500 if ((feed = qmgr_active_feed(qmgr_scans[last_scan_idx], path)) != 0)
501 break;
506 * Round-robin the queue scans. When the active queue becomes full,
507 * prefer new mail over deferred mail.
509 if (qmgr_message_count < var_qmgr_active_limit
510 && qmgr_recipient_count < var_qmgr_rcpt_limit) {
511 first_scan_idx = (last_scan_idx + 1) % QMGR_SCAN_IDX_COUNT;
512 } else if (first_scan_idx != QMGR_SCAN_IDX_INCOMING) {
513 first_scan_idx = QMGR_SCAN_IDX_INCOMING;
517 * Global flow control. If enabled, slow down receiving processes that
518 * get ahead of the queue manager, but don't block them completely.
520 if (var_in_flow_delay > 0) {
521 token_count = mail_flow_count();
522 if (token_count < var_proc_limit) {
523 if (feed != 0 && last_scan_idx == QMGR_SCAN_IDX_INCOMING)
524 mail_flow_put(1);
525 else if (qmgr_scans[QMGR_SCAN_IDX_INCOMING]->handle == 0)
526 mail_flow_put(var_proc_limit - token_count);
527 } else if (token_count > var_proc_limit) {
528 mail_flow_get(token_count - var_proc_limit);
531 return (delay);
534 /* pre_accept - see if tables have changed */
536 static void pre_accept(char *unused_name, char **unused_argv)
538 const char *table;
540 if ((table = dict_changed_name()) != 0) {
541 msg_info("table %s has changed -- restarting", table);
542 exit(0);
546 /* qmgr_pre_init - pre-jail initialization */
548 static void qmgr_pre_init(char *unused_name, char **unused_argv)
550 flush_init();
553 /* qmgr_post_init - post-jail initialization */
555 static void qmgr_post_init(char *unused_name, char **unused_argv)
559 * Sanity check.
561 if (var_qmgr_rcpt_limit < var_qmgr_active_limit) {
562 msg_warn("%s is smaller than %s - adjusting %s",
563 VAR_QMGR_RCPT_LIMIT, VAR_QMGR_ACT_LIMIT, VAR_QMGR_RCPT_LIMIT);
564 var_qmgr_rcpt_limit = var_qmgr_active_limit;
566 if (var_dsn_queue_time > var_max_queue_time) {
567 msg_warn("%s is larger than %s - adjusting %s",
568 VAR_DSN_QUEUE_TIME, VAR_MAX_QUEUE_TIME, VAR_DSN_QUEUE_TIME);
569 var_dsn_queue_time = var_max_queue_time;
573 * This routine runs after the skeleton code has entered the chroot jail.
574 * Prevent automatic process suicide after a limited number of client
575 * requests or after a limited amount of idle time. Move any left-over
576 * entries from the active queue to the incoming queue, and give them a
577 * time stamp into the future, in order to allow ongoing deliveries to
578 * finish first. Start scanning the incoming and deferred queues.
579 * Left-over active queue entries are moved to the incoming queue because
580 * the incoming queue has priority; moving left-overs to the deferred
581 * queue could cause anomalous delays when "postfix reload/start" are
582 * issued often.
584 var_use_limit = 0;
585 var_idle_limit = 0;
586 qmgr_move(MAIL_QUEUE_ACTIVE, MAIL_QUEUE_INCOMING, event_time());
587 qmgr_scans[QMGR_SCAN_IDX_INCOMING] = qmgr_scan_create(MAIL_QUEUE_INCOMING);
588 qmgr_scans[QMGR_SCAN_IDX_DEFERRED] = qmgr_scan_create(MAIL_QUEUE_DEFERRED);
589 qmgr_scan_request(qmgr_scans[QMGR_SCAN_IDX_INCOMING], QMGR_SCAN_START);
590 qmgr_deferred_run_event(0, (char *) 0);
593 MAIL_VERSION_STAMP_DECLARE;
595 /* main - the main program */
597 int main(int argc, char **argv)
599 static const CONFIG_STR_TABLE str_table[] = {
600 VAR_DEFER_XPORTS, DEF_DEFER_XPORTS, &var_defer_xports, 0, 0,
601 VAR_CONC_POS_FDBACK, DEF_CONC_POS_FDBACK, &var_conc_pos_feedback, 1, 0,
602 VAR_CONC_NEG_FDBACK, DEF_CONC_NEG_FDBACK, &var_conc_neg_feedback, 1, 0,
605 static const CONFIG_TIME_TABLE time_table[] = {
606 VAR_QUEUE_RUN_DELAY, DEF_QUEUE_RUN_DELAY, &var_queue_run_delay, 1, 0,
607 VAR_MIN_BACKOFF_TIME, DEF_MIN_BACKOFF_TIME, &var_min_backoff_time, 1, 0,
608 VAR_MAX_BACKOFF_TIME, DEF_MAX_BACKOFF_TIME, &var_max_backoff_time, 1, 0,
609 VAR_MAX_QUEUE_TIME, DEF_MAX_QUEUE_TIME, &var_max_queue_time, 0, 8640000,
610 VAR_DSN_QUEUE_TIME, DEF_DSN_QUEUE_TIME, &var_dsn_queue_time, 0, 8640000,
611 VAR_XPORT_RETRY_TIME, DEF_XPORT_RETRY_TIME, &var_transport_retry_time, 1, 0,
612 VAR_QMGR_CLOG_WARN_TIME, DEF_QMGR_CLOG_WARN_TIME, &var_qmgr_clog_warn_time, 0, 0,
613 VAR_DEST_RATE_DELAY, DEF_DEST_RATE_DELAY, &var_dest_rate_delay, 0, 0,
616 static const CONFIG_INT_TABLE int_table[] = {
617 VAR_QMGR_ACT_LIMIT, DEF_QMGR_ACT_LIMIT, &var_qmgr_active_limit, 1, 0,
618 VAR_QMGR_RCPT_LIMIT, DEF_QMGR_RCPT_LIMIT, &var_qmgr_rcpt_limit, 1, 0,
619 VAR_INIT_DEST_CON, DEF_INIT_DEST_CON, &var_init_dest_concurrency, 1, 0,
620 VAR_DEST_CON_LIMIT, DEF_DEST_CON_LIMIT, &var_dest_con_limit, 0, 0,
621 VAR_DEST_RCPT_LIMIT, DEF_DEST_RCPT_LIMIT, &var_dest_rcpt_limit, 0, 0,
622 VAR_QMGR_FUDGE, DEF_QMGR_FUDGE, &var_qmgr_fudge, 10, 100,
623 VAR_LOCAL_RCPT_LIMIT, DEF_LOCAL_RCPT_LIMIT, &var_local_rcpt_lim, 0, 0,
624 VAR_LOCAL_CON_LIMIT, DEF_LOCAL_CON_LIMIT, &var_local_con_lim, 0, 0,
625 VAR_PROC_LIMIT, DEF_PROC_LIMIT, &var_proc_limit, 1, 0,
626 VAR_CONC_COHORT_LIM, DEF_CONC_COHORT_LIM, &var_conc_cohort_limit, 0, 0,
629 static const CONFIG_BOOL_TABLE bool_table[] = {
630 VAR_VERP_BOUNCE_OFF, DEF_VERP_BOUNCE_OFF, &var_verp_bounce_off,
631 VAR_CONC_FDBACK_DEBUG, DEF_CONC_FDBACK_DEBUG, &var_conc_feedback_debug,
636 * Fingerprint executables and core dumps.
638 MAIL_VERSION_STAMP_ALLOCATE;
641 * Use the trigger service skeleton, because no-one else should be
642 * monitoring our service port while this process runs, and because we do
643 * not talk back to the client.
645 trigger_server_main(argc, argv, qmgr_trigger_event,
646 MAIL_SERVER_INT_TABLE, int_table,
647 MAIL_SERVER_STR_TABLE, str_table,
648 MAIL_SERVER_BOOL_TABLE, bool_table,
649 MAIL_SERVER_TIME_TABLE, time_table,
650 MAIL_SERVER_PRE_INIT, qmgr_pre_init,
651 MAIL_SERVER_POST_INIT, qmgr_post_init,
652 MAIL_SERVER_LOOP, qmgr_loop,
653 MAIL_SERVER_PRE_ACCEPT, pre_accept,
654 MAIL_SERVER_SOLITARY,