Fix 2-phase, in-order queue run delivery order
[exim.git] / src / src / queue.c
index fa4fc0aeccfbaae90a3a3ee593a7c6d4ea4de04e..a4afdcc98e4db0564055186768f8bc17f2ca0f59 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
 *     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 */
 /* 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 */
@@ -354,7 +354,7 @@ Returns:     nothing
 */
 
 void
 */
 
 void
-queue_run(qrunner * q, uschar * start_id, uschar * stop_id, BOOL recurse)
+queue_run(qrunner * q, const uschar * start_id, const uschar * stop_id, BOOL recurse)
 {
 BOOL force_delivery = q->queue_run_force
   || deliver_selectstring || deliver_selectstring_sender;
 {
 BOOL force_delivery = q->queue_run_force
   || deliver_selectstring || deliver_selectstring_sender;
@@ -394,20 +394,19 @@ f.queue_running = TRUE;
 
 if (!recurse)
   {
 
 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';
 
   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);
 
 
   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)
     p += sprintf(CS p, " -q%s", extras);
 
   if (deliver_selectstring)
@@ -444,6 +443,15 @@ if (deliver_selectstring_sender && f.deliver_selectstring_sender_regex)
   selectstring_regex_sender =
     regex_must_compile(deliver_selectstring_sender, MCS_CASELESS, FALSE);
 
   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
 /* 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
@@ -585,7 +593,7 @@ for (int i = queue_run_in_order ? -1 : 0;
       else if (  deliver_selectstring_sender
              && !(f.deliver_selectstring_sender_regex
                  ? regex_match(selectstring_regex_sender, sender_address, -1, NULL)
       else if (  deliver_selectstring_sender
              && !(f.deliver_selectstring_sender_regex
                  ? regex_match(selectstring_regex_sender, sender_address, -1, NULL)
-                 : (strstric(sender_address, deliver_selectstring_sender, FALSE)
+                 : (strstric_c(sender_address, deliver_selectstring_sender, FALSE)
                      != NULL)
              )   )
         {
                      != NULL)
              )   )
         {
@@ -601,10 +609,10 @@ for (int i = queue_run_in_order ? -1 : 0;
         int i;
         for (i = 0; i < recipients_count; i++)
           {
         int i;
         for (i = 0; i < recipients_count; i++)
           {
-          uschar *address = recipients_list[i].address;
+          const uschar * address = recipients_list[i].address;
           if (  (f.deliver_selectstring_regex
                ? regex_match(selectstring_regex, address, -1, NULL)
           if (  (f.deliver_selectstring_regex
                ? regex_match(selectstring_regex, address, -1, NULL)
-                : (strstric(address, deliver_selectstring, FALSE) != NULL)
+                : (strstric_c(address, deliver_selectstring, FALSE) != NULL)
                )
              && tree_search(tree_nonrecipients, address) == NULL
             )
                )
              && tree_search(tree_nonrecipients, address) == NULL
             )
@@ -669,16 +677,6 @@ for (int i = queue_run_in_order ? -1 : 0;
     report_time_since(&timestamp_startup, US"queue msg selected");
 #endif
 
     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)
       {
 single_item_retry:
     if ((pid = exim_fork(US"qrun-delivery")) == 0)
       {
@@ -813,7 +811,7 @@ if (!recurse)
 
 
 void
 
 
 void
-single_queue_run(qrunner * q, uschar * start_id, uschar * stop_id)
+single_queue_run(qrunner * q, const uschar * start_id, const uschar * stop_id)
 {
 DEBUG(D_queue_run) debug_printf("Single queue run%s%s%s%s\n",
   start_id ? US" starting at " : US"",
 {
 DEBUG(D_queue_run) debug_printf("Single queue run%s%s%s%s\n",
   start_id ? US" starting at " : US"",
@@ -919,7 +917,7 @@ Returns:      nothing
 */
 
 void
 */
 
 void
-queue_list(int option, uschar ** list, int count)
+queue_list(int option, const uschar ** list, int count)
 {
 int subcount;
 int now = (int)time(NULL);
 {
 int subcount;
 int now = (int)time(NULL);
@@ -961,7 +959,9 @@ each time. */
 
 if (option == QL_MSGID_ONLY)   /* Print only the message IDs from the chain */
   for (; qf; qf = qf->next)
 
 if (option == QL_MSGID_ONLY)   /* Print only the message IDs from the chain */
   for (; qf; qf = qf->next)
-    fprintf(stdout, "%.*s\n", MESSAGE_ID_LENGTH, qf->text);
+    fprintf(stdout, "%.*s\n",
+      is_old_message_id(qf->text) ? MESSAGE_ID_LENGTH_OLD : MESSAGE_ID_LENGTH,
+      qf->text);
 
 else for (;
          qf && (reset_point = store_mark());
 
 else for (;
          qf && (reset_point = store_mark());
@@ -1021,7 +1021,9 @@ else for (;
     }
 
   fprintf(stdout, "%s %.*s",
     }
 
   fprintf(stdout, "%s %.*s",
-    string_format_size(size, big_buffer), MESSAGE_ID_LENGTH, qf->text);
+    string_format_size(size, big_buffer),
+    is_old_message_id(qf->text) ? MESSAGE_ID_LENGTH_OLD : MESSAGE_ID_LENGTH,
+    qf->text);
 
   if (env_read && sender_address)
     {
 
   if (env_read && sender_address)
     {
@@ -1093,7 +1095,7 @@ Returns:          FALSE if there was any problem
 */
 
 BOOL
 */
 
 BOOL
-queue_action(uschar * id, int action, uschar ** argv, int argc,
+queue_action(const uschar * id, int action, const uschar ** argv, int argc,
   int recipients_arg)
 {
 BOOL yield = TRUE;
   int recipients_arg)
 {
 BOOL yield = TRUE;
@@ -1369,9 +1371,10 @@ switch(action)
          tree_search(tree_nonrecipients, recipients_list[i].address);
        if (!delivered)
          {
          tree_search(tree_nonrecipients, recipients_list[i].address);
        if (!delivered)
          {
-         uschar * save_local = deliver_localpart;
+         const uschar * save_local = deliver_localpart;
          const uschar * save_domain = deliver_domain;
          const uschar * save_domain = deliver_domain;
-         uschar * addr = recipients_list[i].address, * errmsg = NULL;
+         const uschar * addr = recipients_list[i].address;
+         uschar * errmsg = NULL;
          int start, end, dom;
 
          if (!parse_extract_address(addr, &errmsg, &start, &end, &dom, TRUE))
          int start, end, dom;
 
          if (!parse_extract_address(addr, &errmsg, &start, &end, &dom, TRUE))
@@ -1614,3 +1617,5 @@ else DEBUG(D_queue_run) debug_printf(" socket: %s\n", strerror(errno));
 #endif /*!COMPILE_UTILITY*/
 
 /* End of queue.c */
 #endif /*!COMPILE_UTILITY*/
 
 /* End of queue.c */
+/* vi: aw ai sw=2
+*/