debug tidying
[exim.git] / src / src / exim.c
index dfd6df76cb364f3de83e3ad59630455826b7f229..1c0ea6b6e2c80106bd3c1192f06f9c917e8cfc19 100644 (file)
@@ -309,6 +309,7 @@ milliwait(struct itimerval *itval)
 {
 sigset_t sigmask;
 sigset_t old_sigmask;
+int save_errno = errno;
 
 if (itval->it_value.tv_usec < 50 && itval->it_value.tv_sec == 0)
   return;
@@ -322,6 +323,8 @@ if (setitimer(ITIMER_REAL, itval, NULL) < 0)           /* Start timer */
 (void)sigdelset(&sigmask, SIGALRM);                    /* Remove SIGALRM */
 (void)sigsuspend(&sigmask);                            /* Until SIGALRM */
 (void)sigprocmask(SIG_SETMASK, &old_sigmask, NULL);    /* Restore mask */
+errno = save_errno;
+sigalrm_seen = FALSE;
 }
 
 
@@ -342,11 +345,9 @@ Returns:     nothing
 void
 millisleep(int msec)
 {
-struct itimerval itval;
-itval.it_interval.tv_sec = 0;
-itval.it_interval.tv_usec = 0;
-itval.it_value.tv_sec = msec/1000;
-itval.it_value.tv_usec = (msec % 1000) * 1000;
+struct itimerval itval = {.it_interval = {.tv_sec = 0, .tv_usec = 0},
+                         .it_value = {.tv_sec = msec/1000,
+                                      .tv_usec = (msec % 1000) * 1000}};
 milliwait(&itval);
 }
 
@@ -727,9 +728,13 @@ exit(rc);
 
 
 void
-exim_underbar_exit(int rc)
+exim_underbar_exit(int rc, const uschar * process)
 {
 store_exit();
+DEBUG(D_any)
+  debug_printf(">>>>>>>>>>>>>>>> Exim pid=%d %s%s%sterminating with rc=%d "
+    ">>>>>>>>>>>>>>>>\n", (int)getpid(),
+    process ? "(" : "", process, process ? ") " : "", rc);
 _exit(rc);
 }
 
@@ -2755,6 +2760,13 @@ for (i = 1; i < argc; i++)
 
        case 'D': smtp_peer_options |= OPTION_DSN; break;
 
+    /* -MCd: for debug, set a process-purpose string */
+
+       case 'd': if (++i < argc)
+                   process_purpose = string_copy_taint(argv[i], TRUE);
+                 else badarg = TRUE;
+                 break;
+
     /* -MCG: set the queue name, to a non-default value */
 
        case 'G': if (++i < argc) queue_name = string_copy(argv[i]);
@@ -3138,8 +3150,7 @@ for (i = 1; i < argc; i++)
 
       case 'm':
       case 'o':
-       if (!*argrest) {}
-       else badarg = TRUE;
+       if (*argrest) badarg = TRUE;
        break;
 
       /* -oP <name>: set pid file path for daemon
@@ -3157,27 +3168,24 @@ for (i = 1; i < argc; i++)
 
       case 'r':
       case 's':
-       if (!*argrest)
-         {
-         int *tp = (*argrest == 'r')?
-           &arg_receive_timeout : &arg_smtp_receive_timeout;
-         if (argrest[1] == 0)
-           {
-           if (i+1 < argc) *tp= readconf_readtime(argv[++i], 0, FALSE);
-           }
-         else *tp = readconf_readtime(argrest + 1, 0, FALSE);
-         if (*tp < 0)
-           exim_fail("exim: bad time value %s: abandoned\n", argv[i]);
-         }
-       else badarg = TRUE;
+       {
+       int * tp = argrest[-1] == 'r'
+         ? &arg_receive_timeout : &arg_smtp_receive_timeout;
+       if (*argrest)
+         *tp = readconf_readtime(argrest, 0, FALSE);
+       else if (i+1 < argc)
+         *tp = readconf_readtime(argv[++i], 0, FALSE);
+
+       if (*tp < 0)
+         exim_fail("exim: bad time value %s: abandoned\n", argv[i]);
+       }
        break;
 
       /* -oX <list>: Override local_interfaces and/or default daemon ports */
 
       case 'X':
-       if (!*argrest)
-         override_local_interfaces = argv[++i];
-       else badarg = TRUE;
+       if (*argrest) badarg = TRUE;
+       else override_local_interfaces = argv[++i];
        break;
 
       /* Unknown -o argument */
@@ -4608,10 +4616,10 @@ if (msg_action_arg > 0 && msg_action != MSG_LOAD)
     pid_t pid;
     if (i == argc - 1)
       (void)deliver_message(argv[i], forced_delivery, deliver_give_up);
-    else if ((pid = fork()) == 0)
+    else if ((pid = exim_fork(US"cmdline-delivery")) == 0)
       {
       (void)deliver_message(argv[i], forced_delivery, deliver_give_up);
-      exim_underbar_exit(EXIT_SUCCESS);
+      exim_underbar_exit(EXIT_SUCCESS, US"cmdline-delivery");
       }
     else if (pid < 0)
       {
@@ -4631,10 +4639,10 @@ turn into a queue runner, with an optional starting message id. */
 if (queue_interval == 0 && !f.daemon_listen)
   {
   DEBUG(D_queue_run) debug_printf("Single queue run%s%s%s%s\n",
-    (start_queue_run_id == NULL)? US"" : US" starting at ",
-    (start_queue_run_id == NULL)? US"" : start_queue_run_id,
-    (stop_queue_run_id == NULL)?  US"" : US" stopping at ",
-    (stop_queue_run_id == NULL)?  US"" : stop_queue_run_id);
+    start_queue_run_id ? US" starting at " : US"",
+    start_queue_run_id ? start_queue_run_id: US"",
+    stop_queue_run_id ?  US" stopping at " : US"",
+    stop_queue_run_id ?  stop_queue_run_id : US"");
   if (*queue_name)
     set_process_info("running the '%s' queue (single queue run)", queue_name);
   else
@@ -5694,7 +5702,7 @@ while (more)
     pid_t pid;
     search_tidyup();
 
-    if ((pid = fork()) == 0)
+    if ((pid = exim_fork(US"local-accept-delivery")) == 0)
       {
       int rc;
       close_unwanted();      /* Close unwanted file descriptors and TLS */
@@ -5714,7 +5722,7 @@ while (more)
       rc = deliver_message(message_id, FALSE, FALSE);
       search_tidyup();
       exim_underbar_exit(!mua_wrapper || rc == DELIVER_MUA_SUCCEEDED
-        ? EXIT_SUCCESS : EXIT_FAILURE);
+        ? EXIT_SUCCESS : EXIT_FAILURE, US"cmdline-delivery");
       }
 
     if (pid < 0)