From c405c4a942c861a720662035983dca237fb92527 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 10 Oct 2022 10:07:14 +0200 Subject: [PATCH v2 2/3] Standardize format for printing PIDs 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.) --- contrib/pg_prewarm/autoprewarm.c | 20 ++++++++++---------- src/backend/postmaster/bgworker.c | 4 ++-- src/backend/storage/ipc/procsignal.c | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c index c8d673a20e36..1843b1862e57 100644 --- a/contrib/pg_prewarm/autoprewarm.c +++ b/contrib/pg_prewarm/autoprewarm.c @@ -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(); diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 8dd7d64630c4..0d72de24b02b 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -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; } diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c index 21a9fc0fdd2e..7767657f2713 100644 --- a/src/backend/storage/ipc/procsignal.c +++ b/src/backend/storage/ipc/procsignal.c @@ -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(); -- 2.37.3