Skip to content

Commit d534b9e

Browse files
committed
Have pg_ctl print pid and error on signal failure, per suggestion from Tom.
1 parent cbfa409 commit d534b9e

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.1 2004/05/27 03:37:55 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.2 2004/05/31 17:57:31 momjian Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -59,7 +59,6 @@ static int wait_seconds = 60;
5959
static bool silence_echo = false;
6060
static ShutdownMode shutdown_mode = SMART_MODE;
6161
static int sig = SIGTERM; /* default */
62-
static int killproc;
6362
static CtlCommand ctl_command = NO_COMMAND;
6463
static char *pg_data_opts = NULL;
6564
static char *pg_data = NULL;
@@ -80,8 +79,8 @@ static void do_stop(void);
8079
static void do_restart(void);
8180
static void do_reload(void);
8281
static void do_status(void);
83-
static void do_kill(void);
84-
static long get_pgpid(void);
82+
static void do_kill(pid_t pid);
83+
static pid_t get_pgpid(void);
8584
static char **readfile(char *path);
8685
static int start_postmaster(void);
8786
static bool test_postmaster_connection(void);
@@ -127,11 +126,11 @@ xstrdup(const char *s)
127126

128127

129128

130-
static long
129+
static pid_t
131130
get_pgpid(void)
132131
{
133132
FILE *pidf;
134-
long pid;
133+
pid_t pid;
135134

136135
pidf = fopen(pid_file, "r");
137136
if (pidf == NULL)
@@ -145,7 +144,7 @@ get_pgpid(void)
145144
exit(1);
146145
}
147146
}
148-
fscanf(pidf, "%ld", &pid);
147+
fscanf(pidf, "%u", &pid);
149148
fclose(pidf);
150149
return pid;
151150
}
@@ -324,8 +323,8 @@ test_postmaster_connection(void)
324323
static void
325324
do_start(void)
326325
{
327-
long pid;
328-
long old_pid = 0;
326+
pid_t pid;
327+
pid_t old_pid = 0;
329328
char *optline = NULL;
330329

331330
if (ctl_command != RESTART_COMMAND)
@@ -458,7 +457,7 @@ static void
458457
do_stop(void)
459458
{
460459
int cnt;
461-
long pid;
460+
pid_t pid;
462461

463462
pid = get_pgpid();
464463

@@ -473,14 +472,15 @@ do_stop(void)
473472
pid = -pid;
474473
fprintf(stderr,
475474
_("%s: cannot stop postmaster; "
476-
"postgres is running (PID: %ld)\n"),
475+
"postgres is running (PID: %u)\n"),
477476
progname, pid);
478477
exit(1);
479478
}
480479

481-
if (kill((pid_t) pid, sig) != 0)
480+
if (kill(pid, sig) != 0)
482481
{
483-
fprintf(stderr, _("stop signal failed\n"));
482+
fprintf(stderr, _("stop signal failed (PID: %u): %s\n"), pid,
483+
strerror(errno));
484484
exit(1);
485485
}
486486

@@ -537,7 +537,7 @@ static void
537537
do_restart(void)
538538
{
539539
int cnt;
540-
long pid;
540+
pid_t pid;
541541

542542
pid = get_pgpid();
543543

@@ -553,15 +553,16 @@ do_restart(void)
553553
pid = -pid;
554554
fprintf(stderr,
555555
_("%s: cannot restart postmaster; "
556-
"postgres is running (PID: %ld)\n"),
556+
"postgres is running (PID: %u)\n"),
557557
progname, pid);
558558
fprintf(stderr, _("Please terminate postgres and try again.\n"));
559559
exit(1);
560560
}
561561

562-
if (kill((pid_t) pid, sig) != 0)
562+
if (kill(pid, sig) != 0)
563563
{
564-
fprintf(stderr, _("stop signal failed\n"));
564+
fprintf(stderr, _("stop signal failed (PID: %u): %s\n"), pid,
565+
strerror(errno));
565566
exit(1);
566567
}
567568

@@ -608,7 +609,7 @@ do_restart(void)
608609
static void
609610
do_reload(void)
610611
{
611-
long pid;
612+
pid_t pid;
612613

613614
pid = get_pgpid();
614615
if (pid == 0) /* no pid file */
@@ -622,15 +623,16 @@ do_reload(void)
622623
pid = -pid;
623624
fprintf(stderr,
624625
_("%s: cannot reload postmaster; "
625-
"postgres is running (PID: %ld)\n"),
626+
"postgres is running (PID: %u)\n"),
626627
progname, pid);
627628
fprintf(stderr, _("Please terminate postgres and try again.\n"));
628629
exit(1);
629630
}
630631

631-
if (kill((pid_t) pid, sig) != 0)
632+
if (kill(pid, sig) != 0)
632633
{
633-
fprintf(stderr, _("reload signal failed\n"));
634+
fprintf(stderr, _("reload signal failed (PID: %u): %s\n"), pid,
635+
strerror(errno));
634636
exit(1);
635637
}
636638

@@ -645,7 +647,7 @@ do_reload(void)
645647
static void
646648
do_status(void)
647649
{
648-
long pid;
650+
pid_t pid;
649651

650652
pid = get_pgpid();
651653
if (pid == 0) /* no pid file */
@@ -656,13 +658,13 @@ do_status(void)
656658
else if (pid < 0) /* standalone backend */
657659
{
658660
pid = -pid;
659-
fprintf(stdout, _("%s: a standalone backend \"postgres\" is running (PID: %ld)\n"), progname, pid);
661+
fprintf(stdout, _("%s: a standalone backend \"postgres\" is running (PID: %u)\n"), progname, pid);
660662
}
661663
else /* postmaster */
662664
{
663665
char **optlines;
664666

665-
fprintf(stdout, _("%s: postmaster is running (PID: %ld)\n"), progname, pid);
667+
fprintf(stdout, _("%s: postmaster is running (PID: %u)\n"), progname, pid);
666668

667669
optlines = readfile(postopts_file);
668670
if (optlines != NULL)
@@ -674,11 +676,12 @@ do_status(void)
674676

675677

676678
static void
677-
do_kill(void)
679+
do_kill(pid_t pid)
678680
{
679-
if (kill(killproc, sig) != 0)
681+
if (kill(pid, sig) != 0)
680682
{
681-
fprintf(stderr, _("signal %d failed\n"), sig);
683+
fprintf(stderr, _("signal %d failed (PID: %u): %s\n"), sig, pid,
684+
strerror(errno));
682685
exit(1);
683686
}
684687
}
@@ -810,6 +813,7 @@ main(int argc, char **argv)
810813

811814
int option_index;
812815
int c;
816+
int killproc = 0;
813817

814818
#ifdef WIN32
815819
setvbuf(stderr, NULL, _IONBF, 0);
@@ -1005,7 +1009,7 @@ main(int argc, char **argv)
10051009
do_reload();
10061010
break;
10071011
case KILL_COMMAND:
1008-
do_kill();
1012+
do_kill(killproc);
10091013
break;
10101014
default:
10111015
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy