#include "pqexpbuffer.h"
#endif
-/* PID can be negative for standalone backend */
-typedef long pgpid_t;
-
typedef enum
{
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;
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);
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);
}
}
-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)
exit(1);
}
}
- if (fscanf(pidf, "%ld", &pid) != 1)
+ if (fscanf(pidf, "%d", &pid) != 1)
{
/* Is the file empty? */
if (ftell(pidf) == 0 && feof(pidf))
exit(1);
}
fclose(pidf);
- return (pgpid_t) pid;
+ return (pid_t) pid;
}
* 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);
* 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;
numlines >= LOCK_FILE_LINE_PM_STATUS)
{
/* File is complete enough for us, parse it */
- pgpid_t pmpid;
+ pid_t pmpid;
time_t pmstart;
/*
{
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
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
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();
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, (int) postmasterPID, strerror(errno));
}
/*
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)
{
static void
do_stop(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
{
pid = -pid;
write_stderr(_("%s: cannot stop server; "
- "single-user server is running (PID: %ld)\n"),
- progname, pid);
+ "single-user server is running (PID: %d)\n"),
+ progname, (int) 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, (int) pid,
strerror(errno));
exit(1);
}
static void
do_restart(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
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"),
- progname, pid);
+ "single-user server is running (PID: %d)\n"),
+ progname, (int) 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, (int) pid,
strerror(errno));
exit(1);
}
}
else
{
- write_stderr(_("%s: old server process (PID: %ld) seems to be gone\n"),
- progname, pid);
+ write_stderr(_("%s: old server process (PID: %d) seems to be gone\n"),
+ progname, (int) pid);
write_stderr(_("starting server anyway\n"));
}
static void
do_reload(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
if (pid == 0) /* no pid file */
{
pid = -pid;
write_stderr(_("%s: cannot reload server; "
- "single-user server is running (PID: %ld)\n"),
- progname, pid);
+ "single-user server is running (PID: %d)\n"),
+ progname, (int) 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"),
- progname, pid, strerror(errno));
+ write_stderr(_("%s: could not send reload signal (PID: %d): %s\n"),
+ progname, (int) pid, strerror(errno));
exit(1);
}
do_promote(void)
{
FILE *prmfile;
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
{
pid = -pid;
write_stderr(_("%s: cannot promote server; "
- "single-user server is running (PID: %ld)\n"),
- progname, pid);
+ "single-user server is running (PID: %d)\n"),
+ progname, (int) pid);
exit(1);
}
}
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"),
- progname, pid, strerror(errno));
+ write_stderr(_("%s: could not send promote signal (PID: %d): %s\n"),
+ progname, (int) pid, strerror(errno));
if (unlink(promote_file) != 0)
write_stderr(_("%s: could not remove promote signal file \"%s\": %s\n"),
progname, promote_file, strerror(errno));
do_logrotate(void)
{
FILE *logrotatefile;
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(false);
{
pid = -pid;
write_stderr(_("%s: cannot rotate log file; "
- "single-user server is running (PID: %ld)\n"),
- progname, pid);
+ "single-user server is running (PID: %d)\n"),
+ progname, (int) pid);
exit(1);
}
}
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"),
- progname, pid, strerror(errno));
+ write_stderr(_("%s: could not send log rotation signal (PID: %d): %s\n"),
+ progname, (int) pid, strerror(errno));
if (unlink(logrotate_file) != 0)
write_stderr(_("%s: could not remove log rotation signal file \"%s\": %s\n"),
progname, logrotate_file, strerror(errno));
static void
do_status(void)
{
- pgpid_t pid;
+ pid_t pid;
pid = get_pgpid(true);
/* Is there a pid file? */
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"),
- progname, pid);
+ printf(_("%s: single-user server is running (PID: %d)\n"),
+ progname, (int) pid);
return;
}
}
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"),
- progname, pid);
+ printf(_("%s: server is running (PID: %d)\n"),
+ progname, (int) pid);
optlines = readfile(postopts_file, &numlines);
if (optlines != NULL)
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"),
- progname, sig, pid, strerror(errno));
+ write_stderr(_("%s: could not send signal %d (PID: %d): %s\n"),
+ progname, sig, (int) pid, strerror(errno));
exit(1);
}
}
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]);