Standardize format for printing PIDs
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 14 Oct 2022 06:37:12 +0000 (08:37 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 14 Oct 2022 06:38:53 +0000 (08:38 +0200)
Most code prints PIDs as %d, but some code tried to print them as long
or unsigned long.  While this is in theory allowed, the fact that PIDs
fit into int is deeply baked into all PostgreSQL code, so these random
deviations don't accomplish anything except confusion.

Note that we still need casts from pid_t to int, because on 64-bit
MinGW, pid_t is long long int.  (But per above, actually supporting
that range in PostgreSQL code would be major surgery and probably not
useful.)

Discussion: https://www.postgresql.org/message-id/289c2e45-c7d9-5ce4-7eff-a9e2a33e1580@enterprisedb.com

contrib/pg_prewarm/autoprewarm.c
src/backend/postmaster/bgworker.c
src/backend/storage/ipc/procsignal.c

index c8d673a20e36ebec67df7fab6c9cd69293d84753..1843b1862e578e3a49e5461d82cb6a89e7c4f978 100644 (file)
@@ -193,8 +193,8 @@ autoprewarm_main(Datum main_arg)
    {
        LWLockRelease(&apw_state->lock);
        ereport(LOG,
-               (errmsg("autoprewarm worker is already running under PID %lu",
-                       (unsigned long) apw_state->bgworker_pid)));
+               (errmsg("autoprewarm worker is already running under PID %d",
+                       (int) apw_state->bgworker_pid)));
        return;
    }
    apw_state->bgworker_pid = MyProcPid;
@@ -303,8 +303,8 @@ apw_load_buffers(void)
    {
        LWLockRelease(&apw_state->lock);
        ereport(LOG,
-               (errmsg("skipping prewarm because block dump file is being written by PID %lu",
-                       (unsigned long) apw_state->pid_using_dumpfile)));
+               (errmsg("skipping prewarm because block dump file is being written by PID %d",
+                       (int) apw_state->pid_using_dumpfile)));
        return;
    }
    LWLockRelease(&apw_state->lock);
@@ -599,12 +599,12 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
    {
        if (!is_bgworker)
            ereport(ERROR,
-                   (errmsg("could not perform block dump because dump file is being used by PID %lu",
-                           (unsigned long) apw_state->pid_using_dumpfile)));
+                   (errmsg("could not perform block dump because dump file is being used by PID %d",
+                           (int) apw_state->pid_using_dumpfile)));
 
        ereport(LOG,
-               (errmsg("skipping block dump because it is already being performed by PID %lu",
-                       (unsigned long) apw_state->pid_using_dumpfile)));
+               (errmsg("skipping block dump because it is already being performed by PID %d",
+                       (int) apw_state->pid_using_dumpfile)));
        return 0;
    }
 
@@ -737,8 +737,8 @@ autoprewarm_start_worker(PG_FUNCTION_ARGS)
    if (pid != InvalidPid)
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                errmsg("autoprewarm worker is already running under PID %lu",
-                       (unsigned long) pid)));
+                errmsg("autoprewarm worker is already running under PID %d",
+                       (int) pid)));
 
    apw_start_leader_worker();
 
index 8dd7d64630c4866a8738f184a9394f82980af7b2..0d72de24b02bd519072d869a26947c9142ca9858 100644 (file)
@@ -389,8 +389,8 @@ BackgroundWorkerStateChange(bool allow_new_workers)
        rw->rw_worker.bgw_notify_pid = slot->worker.bgw_notify_pid;
        if (!PostmasterMarkPIDForWorkerNotify(rw->rw_worker.bgw_notify_pid))
        {
-           elog(DEBUG1, "worker notification PID %ld is not valid",
-                (long) rw->rw_worker.bgw_notify_pid);
+           elog(DEBUG1, "worker notification PID %d is not valid",
+                (int) rw->rw_worker.bgw_notify_pid);
            rw->rw_worker.bgw_notify_pid = 0;
        }
 
index 21a9fc0fdd2edc18d7160d1500b4e86994742383..7767657f2713468eca7008ee2bf711572418d7d8 100644 (file)
@@ -416,8 +416,8 @@ WaitForProcSignalBarrier(uint64 generation)
                                            5000,
                                            WAIT_EVENT_PROC_SIGNAL_BARRIER))
                ereport(LOG,
-                       (errmsg("still waiting for backend with PID %lu to accept ProcSignalBarrier",
-                               (unsigned long) slot->pss_pid)));
+                       (errmsg("still waiting for backend with PID %d to accept ProcSignalBarrier",
+                               (int) slot->pss_pid)));
            oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
        }
        ConditionVariableCancelSleep();