Commit 66fa6eba authored by Bruce Momjian's avatar Bruce Momjian

Add pgpid_t for use with pids.

parent 91d20ff7
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.2 2004/05/31 17:57:31 momjian Exp $ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.3 2004/06/01 01:28:03 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
int optreset; int optreset;
#endif #endif
/* PID can be negative for standalone backend */
typedef long pgpid_t;
#define _(x) gettext((x)) #define _(x) gettext((x))
...@@ -79,8 +81,8 @@ static void do_stop(void); ...@@ -79,8 +81,8 @@ static void do_stop(void);
static void do_restart(void); static void do_restart(void);
static void do_reload(void); static void do_reload(void);
static void do_status(void); static void do_status(void);
static void do_kill(pid_t pid); static void do_kill(pgpid_t pid);
static pid_t get_pgpid(void); static pgpid_t get_pgpid(void);
static char **readfile(char *path); static char **readfile(char *path);
static int start_postmaster(void); static int start_postmaster(void);
static bool test_postmaster_connection(void); static bool test_postmaster_connection(void);
...@@ -126,11 +128,11 @@ xstrdup(const char *s) ...@@ -126,11 +128,11 @@ xstrdup(const char *s)
static pid_t static pgpid_t
get_pgpid(void) get_pgpid(void)
{ {
FILE *pidf; FILE *pidf;
pid_t pid; pgpid_t pid;
pidf = fopen(pid_file, "r"); pidf = fopen(pid_file, "r");
if (pidf == NULL) if (pidf == NULL)
...@@ -144,7 +146,7 @@ get_pgpid(void) ...@@ -144,7 +146,7 @@ get_pgpid(void)
exit(1); exit(1);
} }
} }
fscanf(pidf, "%u", &pid); fscanf(pidf, "%ld", &pid);
fclose(pidf); fclose(pidf);
return pid; return pid;
} }
...@@ -323,8 +325,8 @@ test_postmaster_connection(void) ...@@ -323,8 +325,8 @@ test_postmaster_connection(void)
static void static void
do_start(void) do_start(void)
{ {
pid_t pid; pgpid_t pid;
pid_t old_pid = 0; pgpid_t old_pid = 0;
char *optline = NULL; char *optline = NULL;
if (ctl_command != RESTART_COMMAND) if (ctl_command != RESTART_COMMAND)
...@@ -457,7 +459,7 @@ static void ...@@ -457,7 +459,7 @@ static void
do_stop(void) do_stop(void)
{ {
int cnt; int cnt;
pid_t pid; pgpid_t pid;
pid = get_pgpid(); pid = get_pgpid();
...@@ -472,14 +474,14 @@ do_stop(void) ...@@ -472,14 +474,14 @@ do_stop(void)
pid = -pid; pid = -pid;
fprintf(stderr, fprintf(stderr,
_("%s: cannot stop postmaster; " _("%s: cannot stop postmaster; "
"postgres is running (PID: %u)\n"), "postgres is running (PID: %ld)\n"),
progname, pid); progname, pid);
exit(1); exit(1);
} }
if (kill(pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
fprintf(stderr, _("stop signal failed (PID: %u): %s\n"), pid, fprintf(stderr, _("stop signal failed (PID: %ld): %s\n"), pid,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
...@@ -537,7 +539,7 @@ static void ...@@ -537,7 +539,7 @@ static void
do_restart(void) do_restart(void)
{ {
int cnt; int cnt;
pid_t pid; pgpid_t pid;
pid = get_pgpid(); pid = get_pgpid();
...@@ -553,15 +555,15 @@ do_restart(void) ...@@ -553,15 +555,15 @@ do_restart(void)
pid = -pid; pid = -pid;
fprintf(stderr, fprintf(stderr,
_("%s: cannot restart postmaster; " _("%s: cannot restart postmaster; "
"postgres is running (PID: %u)\n"), "postgres is running (PID: %ld)\n"),
progname, pid); progname, pid);
fprintf(stderr, _("Please terminate postgres and try again.\n")); fprintf(stderr, _("Please terminate postgres and try again.\n"));
exit(1); exit(1);
} }
if (kill(pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
fprintf(stderr, _("stop signal failed (PID: %u): %s\n"), pid, fprintf(stderr, _("stop signal failed (PID: %ld): %s\n"), pid,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
...@@ -609,7 +611,7 @@ do_restart(void) ...@@ -609,7 +611,7 @@ do_restart(void)
static void static void
do_reload(void) do_reload(void)
{ {
pid_t pid; pgpid_t pid;
pid = get_pgpid(); pid = get_pgpid();
if (pid == 0) /* no pid file */ if (pid == 0) /* no pid file */
...@@ -623,15 +625,15 @@ do_reload(void) ...@@ -623,15 +625,15 @@ do_reload(void)
pid = -pid; pid = -pid;
fprintf(stderr, fprintf(stderr,
_("%s: cannot reload postmaster; " _("%s: cannot reload postmaster; "
"postgres is running (PID: %u)\n"), "postgres is running (PID: %ld)\n"),
progname, pid); progname, pid);
fprintf(stderr, _("Please terminate postgres and try again.\n")); fprintf(stderr, _("Please terminate postgres and try again.\n"));
exit(1); exit(1);
} }
if (kill(pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
fprintf(stderr, _("reload signal failed (PID: %u): %s\n"), pid, fprintf(stderr, _("reload signal failed (PID: %ld): %s\n"), pid,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
...@@ -647,7 +649,7 @@ do_reload(void) ...@@ -647,7 +649,7 @@ do_reload(void)
static void static void
do_status(void) do_status(void)
{ {
pid_t pid; pgpid_t pid;
pid = get_pgpid(); pid = get_pgpid();
if (pid == 0) /* no pid file */ if (pid == 0) /* no pid file */
...@@ -658,13 +660,13 @@ do_status(void) ...@@ -658,13 +660,13 @@ do_status(void)
else if (pid < 0) /* standalone backend */ else if (pid < 0) /* standalone backend */
{ {
pid = -pid; pid = -pid;
fprintf(stdout, _("%s: a standalone backend \"postgres\" is running (PID: %u)\n"), progname, pid); fprintf(stdout, _("%s: a standalone backend \"postgres\" is running (PID: %ld)\n"), progname, pid);
} }
else /* postmaster */ else /* postmaster */
{ {
char **optlines; char **optlines;
fprintf(stdout, _("%s: postmaster is running (PID: %u)\n"), progname, pid); fprintf(stdout, _("%s: postmaster is running (PID: %ld)\n"), progname, pid);
optlines = readfile(postopts_file); optlines = readfile(postopts_file);
if (optlines != NULL) if (optlines != NULL)
...@@ -676,11 +678,11 @@ do_status(void) ...@@ -676,11 +678,11 @@ do_status(void)
static void static void
do_kill(pid_t pid) do_kill(pgpid_t pid)
{ {
if (kill(pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
fprintf(stderr, _("signal %d failed (PID: %u): %s\n"), sig, pid, fprintf(stderr, _("signal %d failed (PID: %ld): %s\n"), sig, pid,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
...@@ -813,7 +815,7 @@ main(int argc, char **argv) ...@@ -813,7 +815,7 @@ main(int argc, char **argv)
int option_index; int option_index;
int c; int c;
int killproc = 0; pgpid_t killproc = 0;
#ifdef WIN32 #ifdef WIN32
setvbuf(stderr, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment