[exim-cvs] Log & debug: care with 64b PIDs

トップ ページ
このメッセージを削除
このメッセージに返信
著者: Exim Git Commits Mailing List
日付:  
To: exim-cvs
題目: [exim-cvs] Log & debug: care with 64b PIDs
Gitweb: https://git.exim.org/exim.git/commitdiff/6f3d774993c37967d5ad236691a194a40cc9da3f
Commit:     6f3d774993c37967d5ad236691a194a40cc9da3f
Parent:     7bdac8a13cc021ac78709b449ed4e0404bcf642a
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Mon Jul 29 17:26:37 2024 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Mon Jul 29 20:12:23 2024 +0100


    Log & debug: care with 64b PIDs
---
 src/src/daemon.c  | 20 +++++++-------
 src/src/deliver.c | 80 ++++++++++++++++++++++++++++---------------------------
 2 files changed, 51 insertions(+), 49 deletions(-)


diff --git a/src/src/daemon.c b/src/src/daemon.c
index f3c49e25e..823c91937 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -898,7 +898,7 @@ while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
   {
   DEBUG(D_any)
     {
-    debug_printf("child %d ended: status=0x%x\n", (int)pid, status);
+    debug_printf("child %ld ended: status=0x%x\n", (long)pid, status);
 #ifdef WCOREDUMP
     if (WIFEXITED(status))
       debug_printf("  normal exit, %d\n", WEXITSTATUS(status));
@@ -986,7 +986,7 @@ static BOOL
 operate_on_pid_file(const enum pid_op operation, const pid_t pid)
 {
 char pid_line[sizeof(int) * 3 + 2];
-const int pid_len = snprintf(pid_line, sizeof(pid_line), "%d\n", (int)pid);
+const int pid_len = snprintf(pid_line, sizeof(pid_line), "%ld\n", (long)pid);
 BOOL lines_match = FALSE;
 uschar * path, * base, * dir;


@@ -1116,7 +1116,7 @@ since we may require privs for the containing directory */
static void
daemon_die(void)
{
-int pid;
+pid_t pid;

 DEBUG(D_any) debug_printf("SIGTERM/SIGINT seen\n");
 #if !defined(DISABLE_TLS) && (defined(EXIM_HAVE_INOTIFY) || defined(EXIM_HAVE_KEVENT))
@@ -1324,8 +1324,8 @@ for (struct cmsghdr * cp = CMSG_FIRSTHDR(&msg);
   struct ucred * cr = (struct ucred *) CMSG_DATA(cp);
   if (cr->uid && cr->uid != exim_uid)
     {
-    DEBUG(D_queue_run) debug_printf("%s: sender creds pid %d uid %d gid %d\n",
-      __FUNCTION__, (int)cr->pid, (int)cr->uid, (int)cr->gid);
+    DEBUG(D_queue_run) debug_printf("%s: sender creds pid %ld uid %d gid %d\n",
+      __FUNCTION__, (long)cr->pid, (int)cr->uid, (int)cr->gid);
     }
 # elif defined(LOCAL_CREDS)                /* BSD-ish */
   struct sockcred * cr = (struct sockcred *) CMSG_DATA(cp);
@@ -2435,7 +2435,7 @@ if (f.inetd_wait_mode)
     sprintf(CS p, "with no wait timeout");


   log_write(0, LOG_MAIN,
-    "exim %s daemon started: pid=%d, launched with listening socket, %s",
+    "exim %s daemon started: pid=%ld, launched with listening socket, %s",
     version_string, getpid(), big_buffer);
   set_process_info("daemon(%s): pre-listening socket", version_string);


@@ -2541,7 +2541,7 @@ else if (f.daemon_listen)
     }


   log_write(0, LOG_MAIN,
-    "exim %s daemon started: pid=%d, %s, listening for %s",
+    "exim %s daemon started: pid=%ld, %s, listening for %s",
     version_string, getpid(), qinfo, big_buffer);
   set_process_info("daemon(%s): %s, listening for %s",
     version_string, qinfo, big_buffer);
@@ -2551,7 +2551,7 @@ else    /* no listening sockets, only queue-runs */
   {
   const uschar * s = describe_queue_runners();
   log_write(0, LOG_MAIN,
-    "exim %s daemon started: pid=%d, %s, not listening for SMTP",
+    "exim %s daemon started: pid=%ld, %s, not listening for SMTP",
     version_string, getpid(), s);
   set_process_info("daemon(%s): %s, not listening", version_string, s);
   }
@@ -2872,7 +2872,7 @@ for (;;)


   if (sighup_seen)
     {
-    log_write(0, LOG_MAIN, "pid %d: SIGHUP received: re-exec daemon",
+    log_write(0, LOG_MAIN, "pid %ld: SIGHUP received: re-exec daemon",
       getpid());
     close_daemon_sockets(daemon_notifier_fd, fd_polls, listen_socket_count);
     unlink_notifier_socket();
@@ -2881,7 +2881,7 @@ for (;;)
     sighup_argv[0] = exim_path;
     exim_nullstd();
     execv(CS exim_path, (char *const *)sighup_argv);
-    log_write(0, LOG_MAIN|LOG_PANIC_DIE, "pid %d: exec of %s failed: %s",
+    log_write(0, LOG_MAIN|LOG_PANIC_DIE, "pid %ld: exec of %s failed: %s",
       getpid(), exim_path, strerror(errno));
     log_close_all();
     }
diff --git a/src/src/deliver.c b/src/src/deliver.c
index ef2800efe..9d26d07c0 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -2246,7 +2246,7 @@ if (  !shadowing


   addr->return_filename =
     spool_fname(US"msglog", message_subdir, message_id,
-      string_sprintf("-%d-%d", getpid(), return_count++));
+      string_sprintf("-%ld-%d", (long)getpid(), return_count++));


   if ((addr->return_file = open_msglog_file(addr->return_filename, 0400, &error)) < 0)
     {
@@ -3347,8 +3347,8 @@ same channel (pipe).


*/

-DEBUG(D_deliver) debug_printf("reading pipe for subprocess %d (%s)\n",
- (int)p->pid, eop? "ended" : "not ended yet");
+DEBUG(D_deliver) debug_printf("reading pipe for subprocess %ld (%s)\n",
+ (long)p->pid, eop? "ended" : "not ended yet");

while (!done)
{
@@ -3360,8 +3360,9 @@ while (!done)
size_t required = PIPE_HEADER_SIZE; /* first the pipehaeder, later the data */
ssize_t got;

-  DEBUG(D_deliver) debug_printf(
-    "expect %lu bytes (pipeheader) from tpt process %d\n", (u_long)required, pid);
+  DEBUG(D_deliver)
+    debug_printf("expect %lu bytes (pipeheader) from tpt process %ld\n",
+    (u_long)required, (long)pid);


   /* We require(!) all the PIPE_HEADER_SIZE bytes here, as we know,
   they're written in a timely manner, so waiting for the write shouldn't hurt a lot.
@@ -3371,16 +3372,16 @@ while (!done)
   if ((got = readn(fd, pipeheader, required)) != required)
     {
     msg = string_sprintf("got " SSIZE_T_FMT " of %d bytes (pipeheader) "
-      "from transport process %d for transport %s",
-      got, PIPE_HEADER_SIZE, pid, addr->transport->driver_name);
+      "from transport process %ld for transport %s",
+      got, PIPE_HEADER_SIZE, (long)pid, addr->transport->driver_name);
     done = TRUE;
     break;
     }


   pipeheader[PIPE_HEADER_SIZE] = '\0';
   DEBUG(D_deliver)
-    debug_printf("got %ld bytes (pipeheader) '%c' from transport process %d\n",
-      (long) got, *id, pid);
+    debug_printf("got %ld bytes (pipeheader) '%c' from transport process %ld\n",
+      (long) got, *id, (long)pid);


   {
   /* If we can't decode the pipeheader, the subprocess seems to have a
@@ -3390,16 +3391,16 @@ while (!done)
   if (*endc)
     {
     msg = string_sprintf("failed to read pipe "
-      "from transport process %d for transport %s: error decoding size from header",
-      pid, addr->transport->driver_name);
+      "from transport process %ld for transport %s: error decoding size from header",
+      (long)pid, addr ? addr->transport->driver_name : US"?");
     done = TRUE;
     break;
     }
   }


   DEBUG(D_deliver)
-    debug_printf("expect %lu bytes (pipedata) from transport process %d\n",
-      (u_long)required, pid);
+    debug_printf("expect %lu bytes (pipedata) from transport process %ld\n",
+      (u_long)required, (long)pid);


   /* Same as above, the transport process will write the bytes announced
   in a timely manner, so we can just wait for the bytes, getting less than expected
@@ -3407,8 +3408,8 @@ while (!done)
   if ((got = readn(fd, big_buffer, required)) != required)
     {
     msg = string_sprintf("got only " SSIZE_T_FMT " of " SIZE_T_FMT
-      " bytes (pipedata) from transport process %d for transport %s",
-      got, required, pid, addr->transport->driver_name);
+      " bytes (pipedata) from transport process %ld for transport %s",
+      got, required, (long)pid, addr->transport->driver_name);
     done = TRUE;
     break;
     }
@@ -3597,8 +3598,8 @@ while (!done)
     {
     ADDR_MISMATCH:
     msg = string_sprintf("address count mismatch for data read from pipe "
-      "for transport process %d for transport %s", pid,
-        addrlist->transport->driver_name);
+      "for transport process %ld for transport %s",
+        (long)pid, addrlist->transport->driver_name);
     done = TRUE;
     break;
     }
@@ -3742,8 +3743,8 @@ while (!done)
       close(recvd_fd);


       DEBUG(D_deliver)
-        debug_printf("continue: tpt '%s' host '%s' addr '%s' seq %d\n",
-              continue_transport, continue_hostname,
+        debug_printf("continue: fd %d tpt %s host '%s' addr '%s' seq %d\n",
+              recvd_fd, continue_transport, continue_hostname,
               continue_host_address, continue_sequence);
       break;
       }
@@ -3785,8 +3786,8 @@ while (!done)


     default:
       msg = string_sprintf("malformed data (%d) read from pipe for transport "
-    "process %d for transport %s", ptr[-1], pid,
-      addr->transport->driver_name);
+    "process %ld for transport %s", ptr[-1], (long)pid,
+      addr ? addr->transport->driver_name : US"?");
       done = TRUE;
       break;
     }
@@ -3819,7 +3820,7 @@ something is wrong. */


 if (!msg && addr)
   msg = string_sprintf("insufficient address data read from pipe "
-    "for transport process %d for transport %s", pid,
+    "for transport process %ld for transport %s", (long)pid,
       addr->transport->driver_name);


 /* If an error message is set, something has gone wrong in getting back
@@ -3831,7 +3832,8 @@ if (msg)
     addr->transport_return = DEFER;
     addr->special_action = SPECIAL_FREEZE;
     addr->message = msg;
-    log_write(0, LOG_MAIN|LOG_PANIC, "Delivery status for %s: %s\n", addr->address, addr->message);
+    log_write(0, LOG_MAIN|LOG_PANIC, "Delivery status for %s: %s\n",
+          addr->address, addr->message);
     }


 /* Return TRUE to indicate we have got all we need from this process, even
@@ -4024,8 +4026,8 @@ for (;;)   /* Normally we do not repeat this loop */
         {
         if ((pid = parlist[poffset].pid) != 0 && kill(pid, 0) == 0)
           {
-          DEBUG(D_deliver) debug_printf("process %d still exists: assume "
-            "stolen by strace\n", (int)pid);
+          DEBUG(D_deliver) debug_printf("process %ld still exists: assume "
+            "stolen by strace\n", (long)pid);
           break;   /* With poffset set */
           }
         }
@@ -4086,8 +4088,8 @@ for (;;)   /* Normally we do not repeat this loop */
             if (endedpid == pid) goto PROCESS_DONE;
             if (endedpid != (pid_t)(-1) || errno != EINTR)
               log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Unexpected error return "
-                "%d (errno = %d) from waitpid() for process %d",
-                (int)endedpid, errno, (int)pid);
+                "%d (errno = %d) from waitpid() for process %ld",
+                (int)endedpid, errno, (long)pid);
             }
         }
       }
@@ -4109,8 +4111,8 @@ for (;;)   /* Normally we do not repeat this loop */
   /* This situation is an error, but it's probably better to carry on looking
   for another process than to give up (as we used to do). */


-  log_write(0, LOG_MAIN|LOG_PANIC, "Process %d finished: not found in remote "
-    "transport process list", pid);
+  log_write(0, LOG_MAIN|LOG_PANIC, "Process %ld finished: not found in remote "
+    "transport process list", (long)pid);
   }  /* End of the "for" loop */


 /* Come here when all the data was completely read after a poll(), and
@@ -4121,9 +4123,9 @@ PROCESS_DONE:
 DEBUG(D_deliver)
   {
   if (status == 0)
-    debug_printf("remote delivery process %d ended\n", (int)pid);
+    debug_printf("remote delivery process %ld ended\n", (long)pid);
   else
-    debug_printf("remote delivery process %d ended: status=%04x\n", (int)pid,
+    debug_printf("remote delivery process %ld ended: status=%04x\n", (long)pid,
       status);
   }


@@ -5837,9 +5839,9 @@ if (!(bounce_recipient = addr_failed->prop.errors_address))
/* Make a subprocess to send a message, using its stdin */

 if ((pid = child_open_exim(&fd, US"bounce-message")) < 0)
-  log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %d (parent %d) failed to "
-    "create child process to send failure message: %s", getpid(),
-    getppid(), strerror(errno));
+  log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %ld (parent %ld) failed to "
+    "create child process to send failure message: %s",
+    (long)getpid(), (long)getppid(), strerror(errno));


/* Creation of child succeeded */

@@ -6489,13 +6491,13 @@ if (addr_senddsn)
int fd;
pid_t pid = child_open_exim(&fd, US"DSN");

- DEBUG(D_deliver) debug_printf("DSN: child_open_exim returns: %d\n", pid);
+ DEBUG(D_deliver) debug_printf("DSN: child_open_exim returns: %ld\n", (long)pid);

   if (pid < 0)  /* Creation of child failed */
     {
-    log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %d (parent %d) failed to "
-      "create child process to send success-dsn message: %s", getpid(),
-      getppid(), strerror(errno));
+    log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %ld (parent %ld) failed to "
+      "create child process to send success-dsn message: %s",
+      (long)getpid(), (long)getppid(), strerror(errno));


     DEBUG(D_deliver) debug_printf("DSN: child_open_exim failed\n");
     }
@@ -6656,7 +6658,7 @@ report_time_since(&timestamp_startup, US"delivery start");    /* testcase 0022, 210


info = queue_run_pid == (pid_t)0
? string_sprintf("delivering %s", id)
- : string_sprintf("delivering %s (queue run pid %d)", id, queue_run_pid);
+ : string_sprintf("delivering %s (queue run pid %ld)", id, (long)queue_run_pid);

/* If the D_process_info bit is on, set_process_info() will output debugging
information. If not, we want to show this initial information if D_deliver or

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-cvs.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-cvs-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/