Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd534b9e

Browse files
committed
Have pg_ctl print pid and error on signal failure, per suggestion from Tom.
1 parentcbfa409 commitd534b9e

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 intwait_seconds = 60;
5959
staticboolsilence_echo= false;
6060
staticShutdownModeshutdown_mode=SMART_MODE;
6161
staticintsig=SIGTERM;/* default */
62-
staticintkillproc;
6362
staticCtlCommandctl_command=NO_COMMAND;
6463
staticchar*pg_data_opts=NULL;
6564
staticchar*pg_data=NULL;
@@ -80,8 +79,8 @@ static void do_stop(void);
8079
staticvoiddo_restart(void);
8180
staticvoiddo_reload(void);
8281
staticvoiddo_status(void);
83-
staticvoiddo_kill(void);
84-
staticlongget_pgpid(void);
82+
staticvoiddo_kill(pid_tpid);
83+
staticpid_tget_pgpid(void);
8584
staticchar**readfile(char*path);
8685
staticintstart_postmaster(void);
8786
staticbooltest_postmaster_connection(void);
@@ -127,11 +126,11 @@ xstrdup(const char *s)
127126

128127

129128

130-
staticlong
129+
staticpid_t
131130
get_pgpid(void)
132131
{
133132
FILE*pidf;
134-
longpid;
133+
pid_tpid;
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
returnpid;
151150
}
@@ -324,8 +323,8 @@ test_postmaster_connection(void)
324323
staticvoid
325324
do_start(void)
326325
{
327-
longpid;
328-
longold_pid=0;
326+
pid_tpid;
327+
pid_told_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
intcnt;
461-
longpid;
460+
pid_tpid;
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
intcnt;
540-
longpid;
540+
pid_tpid;
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
staticvoid
609610
do_reload(void)
610611
{
611-
longpid;
612+
pid_tpid;
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
staticvoid
646648
do_status(void)
647649
{
648-
longpid;
650+
pid_tpid;
649651

650652
pid=get_pgpid();
651653
if (pid==0)/* no pid file */
@@ -656,13 +658,13 @@ do_status(void)
656658
elseif (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
staticvoid
677-
do_kill(void)
679+
do_kill(pid_tpid)
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
intoption_index;
812815
intc;
816+
intkillproc=0;
813817

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp