I wanted to propose the attached patch to get rid of the custom pgpid_t
typedef in pg_ctl. Since we liberally use pid_t elsewhere, this seemed
plausible.
However, this patch fails the CompilerWarnings job on Cirrus, because
apparently under mingw, pid_t is "volatile long long int", so all the
printf placeholders mismatch. However, we print pid_t as %d in a lot of
other places, so I'm confused why this fails here.
Also, googling around a bit about this, it seems that mingw might have
changed the pid_t from long long int to int some time ago. Maybe that's
how the pgpid_t came about to begin with. The Cirrus job uses a
cross-compilation environment. I wonder how up to date that is compared
to say the native mingw installations used on the build farm.
Any clues?
From 11aed64ddb6e5615c15e18b05825545ce66ed951 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Tue, 4 Oct 2022 08:12:31 +0200
Subject: [PATCH] Remove pgpid_t type, use pid_t instead
It's unclear why a separate type would be needed here. We use plain
pid_t everywhere else.
Reverts 66fa6eba5a61be740a6c07de92c42221fae79e9c.
---
src/bin/pg_ctl/pg_ctl.c | 111 +++++++++++++++----------------
src/tools/pgindent/typedefs.list | 1 -
2 files changed, 54 insertions(+), 58 deletions(-)
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 9291c61d000f..a7fb4a9b330b 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -33,9 +33,6 @@
#include "pqexpbuffer.h"
#endif
-/* PID can be negative for standalone backend */
-typedef long pgpid_t;
-
typedef enum
{
@@ -103,7 +100,7 @@ static char backup_file[MAXPGPATH];
static char promote_file[MAXPGPATH];
static char logrotate_file[MAXPGPATH];
-static volatile pgpid_t postmasterPID = -1;
+static volatile pid_t postmasterPID = -1;
#ifdef WIN32
static DWORD pgctl_start_type = SERVICE_AUTO_START;
@@ -129,7 +126,7 @@ static void do_reload(void);
static void do_status(void);
static void do_promote(void);
static void do_logrotate(void);
-static void do_kill(pgpid_t pid);
+static void do_kill(pid_t pid);
static void print_msg(const char *msg);
static void adjust_data_dir(void);
@@ -147,13 +144,13 @@ static int CreateRestrictedProcess(char *cmd,
PROCESS_INFORMATION *processInfo,
static PTOKEN_PRIVILEGES GetPrivilegesToDelete(HANDLE hToken);
#endif
-static pgpid_t get_pgpid(bool is_status_request);
+static pid_t get_pgpid(bool is_status_request);
static char **readfile(const char *path, int *numlines);
static void free_readfile(char **optlines);
-static pgpid_t start_postmaster(void);
+static pid_t start_postmaster(void);
static void read_post_opts(void);
-static WaitPMResult wait_for_postmaster_start(pgpid_t pm_pid, bool
do_checkpoint);
+static WaitPMResult wait_for_postmaster_start(pid_t pm_pid, bool
do_checkpoint);
static bool wait_for_postmaster_stop(void);
static bool wait_for_postmaster_promote(void);
static bool postmaster_is_alive(pid_t pid);
@@ -245,11 +242,11 @@ print_msg(const char *msg)
}
}
-static pgpid_t
+static pid_t
get_pgpid(bool is_status_request)
{
FILE *pidf;
- long pid;
+ int pid;
struct stat statbuf;
if (stat(pg_data, &statbuf) != 0)
@@ -289,7 +286,7 @@ get_pgpid(bool is_status_request)
exit(1);
}
}
- if (fscanf(pidf, "%ld", &pid) != 1)
+ if (fscanf(pidf, "%d", &pid) != 1)
{
/* Is the file empty? */
if (ftell(pidf) == 0 && feof(pidf))
@@ -301,7 +298,7 @@ get_pgpid(bool is_status_request)
exit(1);
}
fclose(pidf);
- return (pgpid_t) pid;
+ return (pid_t) pid;
}
@@ -439,13 +436,13 @@ free_readfile(char **optlines)
* On Windows, we also save aside a handle to the shell process in
* "postmasterProcess", which the caller should close when done with it.
*/
-static pgpid_t
+static pid_t
start_postmaster(void)
{
char *cmd;
#ifndef WIN32
- pgpid_t pm_pid;
+ pid_t pm_pid;
/* Flush stdio channels just before fork, to avoid double-output
problems */
fflush(NULL);
@@ -593,7 +590,7 @@ start_postmaster(void)
* manager checkpoint, it's got nothing to do with database checkpoints!!
*/
static WaitPMResult
-wait_for_postmaster_start(pgpid_t pm_pid, bool do_checkpoint)
+wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint)
{
int i;
@@ -610,7 +607,7 @@ wait_for_postmaster_start(pgpid_t pm_pid, bool
do_checkpoint)
numlines >= LOCK_FILE_LINE_PM_STATUS)
{
/* File is complete enough for us, parse it */
- pgpid_t pmpid;
+ pid_t pmpid;
time_t pmstart;
/*
@@ -665,7 +662,7 @@ wait_for_postmaster_start(pgpid_t pm_pid, bool
do_checkpoint)
{
int exitstatus;
- if (waitpid((pid_t) pm_pid, &exitstatus, WNOHANG) ==
(pid_t) pm_pid)
+ if (waitpid(pm_pid, &exitstatus, WNOHANG) == pm_pid)
return POSTMASTER_FAILED;
}
#else
@@ -716,12 +713,12 @@ wait_for_postmaster_stop(void)
for (cnt = 0; cnt < wait_seconds * WAITS_PER_SEC; cnt++)
{
- pgpid_t pid;
+ pid_t pid;
if ((pid = get_pgpid(false)) == 0)
return true; /* pid file is gone */
- if (kill((pid_t) pid, 0) != 0)
+ if (kill(pid, 0) != 0)
{
/*
* Postmaster seems to have died. Check the pid file
once more to
@@ -753,12 +750,12 @@ wait_for_postmaster_promote(void)
for (cnt = 0; cnt < wait_seconds * WAITS_PER_SEC; cnt++)
{
- pgpid_t pid;
+ pid_t pid;
DBState state;
if ((pid = get_pgpid(false)) == 0)
return false; /* pid file is gone */
- if (kill((pid_t) pid, 0) != 0)
+ if (kill(pid, 0) != 0)
return false; /* postmaster died */
state = get_control_dbstate();
@@ -855,8 +852,8 @@ trap_sigint_during_startup(SIGNAL_ARGS)
if (postmasterPID != -1)
{
if (kill(postmasterPID, SIGINT) != 0)
- write_stderr(_("%s: could not send stop signal (PID:
%ld): %s\n"),
- progname, (pgpid_t)
postmasterPID, strerror(errno));
+ write_stderr(_("%s: could not send stop signal (PID:
%d): %s\n"),
+ progname, postmasterPID,
strerror(errno));
}
/*
@@ -926,8 +923,8 @@ do_init(void)
static void
do_start(void)
{
- pgpid_t old_pid = 0;
- pgpid_t pm_pid;
+ pid_t old_pid = 0;
+ pid_t pm_pid;
if (ctl_command != RESTART_COMMAND)
{
@@ -1018,7 +1015,7 @@ do_start(void)
static void
do_stop(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
@@ -1032,14 +1029,14 @@ do_stop(void)
{
pid = -pid;
write_stderr(_("%s: cannot stop server; "
- "single-user server is running (PID:
%ld)\n"),
+ "single-user server is running (PID:
%d)\n"),
progname, pid);
exit(1);
}
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send stop signal (PID: %ld):
%s\n"), progname, pid,
+ write_stderr(_("%s: could not send stop signal (PID: %d):
%s\n"), progname, pid,
strerror(errno));
exit(1);
}
@@ -1077,7 +1074,7 @@ do_stop(void)
static void
do_restart(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
@@ -1093,21 +1090,21 @@ do_restart(void)
else if (pid < 0) /* standalone backend, not
postmaster */
{
pid = -pid;
- if (postmaster_is_alive((pid_t) pid))
+ if (postmaster_is_alive(pid))
{
write_stderr(_("%s: cannot restart server; "
- "single-user server is
running (PID: %ld)\n"),
+ "single-user server is
running (PID: %d)\n"),
progname, pid);
write_stderr(_("Please terminate the single-user server
and try again.\n"));
exit(1);
}
}
- if (postmaster_is_alive((pid_t) pid))
+ if (postmaster_is_alive(pid))
{
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send stop signal (PID:
%ld): %s\n"), progname, pid,
+ write_stderr(_("%s: could not send stop signal (PID:
%d): %s\n"), progname, pid,
strerror(errno));
exit(1);
}
@@ -1131,7 +1128,7 @@ do_restart(void)
}
else
{
- write_stderr(_("%s: old server process (PID: %ld) seems to be
gone\n"),
+ write_stderr(_("%s: old server process (PID: %d) seems to be
gone\n"),
progname, pid);
write_stderr(_("starting server anyway\n"));
}
@@ -1142,7 +1139,7 @@ do_restart(void)
static void
do_reload(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
if (pid == 0) /* no pid file */
@@ -1155,15 +1152,15 @@ do_reload(void)
{
pid = -pid;
write_stderr(_("%s: cannot reload server; "
- "single-user server is running (PID:
%ld)\n"),
+ "single-user server is running (PID:
%d)\n"),
progname, pid);
write_stderr(_("Please terminate the single-user server and try
again.\n"));
exit(1);
}
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send reload signal (PID: %ld):
%s\n"),
+ write_stderr(_("%s: could not send reload signal (PID: %d):
%s\n"),
progname, pid, strerror(errno));
exit(1);
}
@@ -1180,7 +1177,7 @@ static void
do_promote(void)
{
FILE *prmfile;
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
@@ -1194,7 +1191,7 @@ do_promote(void)
{
pid = -pid;
write_stderr(_("%s: cannot promote server; "
- "single-user server is running (PID:
%ld)\n"),
+ "single-user server is running (PID:
%d)\n"),
progname, pid);
exit(1);
}
@@ -1223,9 +1220,9 @@ do_promote(void)
}
sig = SIGUSR1;
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send promote signal (PID: %ld):
%s\n"),
+ write_stderr(_("%s: could not send promote signal (PID: %d):
%s\n"),
progname, pid, strerror(errno));
if (unlink(promote_file) != 0)
write_stderr(_("%s: could not remove promote signal
file \"%s\": %s\n"),
@@ -1261,7 +1258,7 @@ static void
do_logrotate(void)
{
FILE *logrotatefile;
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
@@ -1275,7 +1272,7 @@ do_logrotate(void)
{
pid = -pid;
write_stderr(_("%s: cannot rotate log file; "
- "single-user server is running (PID:
%ld)\n"),
+ "single-user server is running (PID:
%d)\n"),
progname, pid);
exit(1);
}
@@ -1296,9 +1293,9 @@ do_logrotate(void)
}
sig = SIGUSR1;
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send log rotation signal (PID:
%ld): %s\n"),
+ write_stderr(_("%s: could not send log rotation signal (PID:
%d): %s\n"),
progname, pid, strerror(errno));
if (unlink(logrotate_file) != 0)
write_stderr(_("%s: could not remove log rotation
signal file \"%s\": %s\n"),
@@ -1341,7 +1338,7 @@ postmaster_is_alive(pid_t pid)
static void
do_status(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(true);
/* Is there a pid file? */
@@ -1351,9 +1348,9 @@ do_status(void)
if (pid < 0)
{
pid = -pid;
- if (postmaster_is_alive((pid_t) pid))
+ if (postmaster_is_alive(pid))
{
- printf(_("%s: single-user server is running
(PID: %ld)\n"),
+ printf(_("%s: single-user server is running
(PID: %d)\n"),
progname, pid);
return;
}
@@ -1361,13 +1358,13 @@ do_status(void)
else
/* must be a postmaster */
{
- if (postmaster_is_alive((pid_t) pid))
+ if (postmaster_is_alive(pid))
{
char **optlines;
char **curr_line;
int numlines;
- printf(_("%s: server is running (PID: %ld)\n"),
+ printf(_("%s: server is running (PID: %d)\n"),
progname, pid);
optlines = readfile(postopts_file, &numlines);
@@ -1396,11 +1393,11 @@ do_status(void)
static void
-do_kill(pgpid_t pid)
+do_kill(pid_t pid)
{
- if (kill((pid_t) pid, sig) != 0)
+ if (kill(pid, sig) != 0)
{
- write_stderr(_("%s: could not send signal %d (PID: %ld): %s\n"),
+ write_stderr(_("%s: could not send signal %d (PID: %d): %s\n"),
progname, sig, pid, strerror(errno));
exit(1);
}
@@ -2214,7 +2211,7 @@ main(int argc, char **argv)
char *env_wait;
int option_index;
int c;
- pgpid_t killproc = 0;
+ pid_t killproc = 0;
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 97c9bc186157..3e8cead90f48 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -3513,7 +3513,6 @@ pg_wc_probefunc
pg_wchar
pg_wchar_tbl
pgp_armor_headers_state
-pgpid_t
pgsocket
pgsql_thing_t
pgssEntry
--
2.37.3