Hintsdb transactions
[exim.git] / src / src / queue.c
index 2c3d014f5638405404e06bacd0f2d7f73fcb4129..3073ee7805cefd6654a6474cc88e7529873fad45 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) The Exim Maintainers 2020 - 2022 */
+/* Copyright (c) The Exim Maintainers 2020 - 2024 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
 /* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -341,8 +341,10 @@ so force the first one. The selecting string can optionally be a regex, or
 refer to the sender instead of recipients.
 
 If queue_2stage is set, the queue is scanned twice. The first time, queue_smtp
-is set so that routing is done for all messages. Thus in the second run those
-that are routed to the same host should go down the same SMTP connection.
+is set so that routing is done for all messages. A call of the transport adds
+each message_id in turn to a list for the resulting host.
+Then in the second run those that are routed to the same host should all go down
+a single SMTP connection.
 
 Arguments:
   q         queue-runner descriptor
@@ -358,9 +360,9 @@ queue_run(qrunner * q, const uschar * start_id, const uschar * stop_id, BOOL rec
 {
 BOOL force_delivery = q->queue_run_force
   || deliver_selectstring || deliver_selectstring_sender;
-const pcre2_code *selectstring_regex = NULL;
-const pcre2_code *selectstring_regex_sender = NULL;
-uschar *log_detail = NULL;
+const pcre2_code * selectstring_regex = NULL;
+const pcre2_code * selectstring_regex_sender = NULL;
+uschar * log_detail = NULL;
 int subcount = 0;
 uschar subdirs[64];
 pid_t qpid[4] = {0};   /* Parallelism factor for q2stage 1st phase */
@@ -394,20 +396,19 @@ f.queue_running = TRUE;
 
 if (!recurse)
   {
-  uschar extras[8];
-  uschar *p = extras;
+  uschar extras[8], * p = extras;
 
   if (q->queue_2stage)         *p++ = 'q';
   if (q->queue_run_first_delivery) *p++ = 'i';
   if (q->queue_run_force)      *p++ = 'f';
   if (q->deliver_force_thaw)   *p++ = 'f';
   if (q->queue_run_local)      *p++ = 'l';
-  *p = 0;
+  *p = '\0';
 
   p = big_buffer;
   p += sprintf(CS p, "pid=%d", (int)queue_run_pid);
 
-  if (extras[0] != 0)
+  if (*extras)
     p += sprintf(CS p, " -q%s", extras);
 
   if (deliver_selectstring)
@@ -444,6 +445,15 @@ if (deliver_selectstring_sender && f.deliver_selectstring_sender_regex)
   selectstring_regex_sender =
     regex_must_compile(deliver_selectstring_sender, MCS_CASELESS, FALSE);
 
+#ifndef DISABLE_TLS
+if (!queue_tls_init)
+  {
+  queue_tls_init = TRUE;
+  /* Preload TLS library info for smtp transports. */
+  tls_client_creds_reload(FALSE);
+  }
+#endif
+
 /* If the spool is split into subdirectories, we want to process it one
 directory at a time, so as to spread out the directory scanning and the
 delivering when there are lots of messages involved, except when
@@ -664,23 +674,15 @@ for (int i = queue_run_in_order ? -1 : 0;
     name. The return of the process is zero if a delivery was attempted. */
 
     fq->text[Ustrlen(fq->text)-2] = 0;
-    set_process_info("running queue: %s", fq->text);
+    set_process_info("running queue%s: %s",
+      q->queue_2stage ? "(ph 1)" : "", fq->text);
 #ifdef MEASURE_TIMING
     report_time_since(&timestamp_startup, US"queue msg selected");
 #endif
 
-#ifndef DISABLE_TLS
-    if (!queue_tls_init)
-      {
-      queue_tls_init = TRUE;
-      /* Preload TLS library info for smtp transports.  Once, and only if we
-      have a delivery to do. */
-      tls_client_creds_reload(FALSE);
-      }
-#endif
-
 single_item_retry:
-    if ((pid = exim_fork(US"qrun-delivery")) == 0)
+    if ((pid = exim_fork(
+       q->queue_2stage ? US"qrun-p1-delivery" : US"qrun-delivery")) == 0)
       {
       int rc;
       (void)close(pfd[pipe_read]);
@@ -794,9 +796,10 @@ if (q->queue_2stage)
     else break;
 
 #ifdef MEASURE_TIMING
-  report_time_since(&timestamp_startup, US"queue_run 1st phase done");
+  report_time_since(&timestamp_startup, US"queue_run phase 1 done");
 #endif
   q->queue_2stage = f.queue_2stage = FALSE;
+  DEBUG(D_queue_run) debug_printf("queue_run phase 2 start\n");
   queue_run(q, start_id, stop_id, TRUE);
   }
 
@@ -1619,3 +1622,5 @@ else DEBUG(D_queue_run) debug_printf(" socket: %s\n", strerror(errno));
 #endif /*!COMPILE_UTILITY*/
 
 /* End of queue.c */
+/* vi: aw ai sw=2
+*/