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

Commit8ff374c

Browse files
author
Neil Conway
committed
psql code cleanup:
- refactor a bunch of code to call a separate function print_msg() whichchecks whether "silent mode" is enabled before printing an errormessage.- rename "silence_mode" to "silent_mode", which IMHO makes more sense- make the error messages we emit in "waiting" mode more consistent; Ibelieve this fixes a recent error message regression
1 parentaa0d472 commit8ff374c

File tree

1 file changed

+42
-63
lines changed

1 file changed

+42
-63
lines changed

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.35 2004/10/13 10:35:05 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.36 2004/10/15 01:36:12 neilc Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -66,7 +66,7 @@ typedef enum
6666
staticbooldo_wait= false;
6767
staticboolwait_set= false;
6868
staticintwait_seconds=60;
69-
staticboolsilence_echo= false;
69+
staticboolsilent_mode= false;
7070
staticShutdownModeshutdown_mode=SMART_MODE;
7171
staticintsig=SIGTERM;/* default */
7272
staticCtlCommandctl_command=NO_COMMAND;
@@ -92,25 +92,26 @@ static void do_advice(void);
9292
staticvoiddo_help(void);
9393
staticvoidset_mode(char*modeopt);
9494
staticvoidset_sig(char*signame);
95-
staticvoiddo_start();
95+
staticvoiddo_start(void);
9696
staticvoiddo_stop(void);
9797
staticvoiddo_restart(void);
9898
staticvoiddo_reload(void);
9999
staticvoiddo_status(void);
100100
staticvoiddo_kill(pgpid_tpid);
101+
staticvoidprint_msg(constchar*msg);
101102

102103
#if defined(WIN32)|| defined(__CYGWIN__)
103104
staticboolpgwin32_IsInstalled(SC_HANDLE);
104105
staticchar*pgwin32_CommandLine(bool);
105-
staticvoidpgwin32_doRegister();
106-
staticvoidpgwin32_doUnregister();
106+
staticvoidpgwin32_doRegister(void);
107+
staticvoidpgwin32_doUnregister(void);
107108
staticvoidpgwin32_SetServiceStatus(DWORD);
108109
staticvoidWINAPIpgwin32_ServiceHandler(DWORD);
109110
staticvoidWINAPIpgwin32_ServiceMain(DWORD,LPTSTR*);
110-
staticvoidpgwin32_doRunAsService();
111+
staticvoidpgwin32_doRunAsService(void);
111112
#endif
112113
staticpgpid_tget_pgpid(void);
113-
staticchar**readfile(char*path);
114+
staticchar**readfile(constchar*path);
114115
staticintstart_postmaster(void);
115116
staticbooltest_postmaster_connection(void);
116117

@@ -201,7 +202,6 @@ xmalloc(size_t size)
201202
}
202203

203204

204-
205205
staticchar*
206206
xstrdup(constchar*s)
207207
{
@@ -216,7 +216,19 @@ xstrdup(const char *s)
216216
returnresult;
217217
}
218218

219-
219+
/*
220+
* Given an already-localized string, print it to stdout unless the
221+
* user has specified that no messages should be printed.
222+
*/
223+
staticvoid
224+
print_msg(constchar*msg)
225+
{
226+
if (!silent_mode)
227+
{
228+
fputs(msg,stdout);
229+
fflush(stdout);
230+
}
231+
}
220232

221233
staticpgpid_t
222234
get_pgpid(void)
@@ -247,7 +259,7 @@ get_pgpid(void)
247259
* get the lines from a text file - return NULL if file can't be opened
248260
*/
249261
staticchar**
250-
readfile(char*path)
262+
readfile(constchar*path)
251263
{
252264
FILE*infile;
253265
intmaxlength=0,
@@ -281,7 +293,6 @@ readfile(char *path)
281293
maxlength=linelen;
282294

283295
/* set up the result and the line buffer */
284-
285296
result= (char**)xmalloc((nlines+1)*sizeof(char*));
286297
buffer= (char*)xmalloc(maxlength+1);
287298

@@ -429,11 +440,7 @@ test_postmaster_connection(void)
429440
}
430441
else
431442
{
432-
if (!silence_echo)
433-
{
434-
printf(".");
435-
fflush(stdout);
436-
}
443+
print_msg(".");
437444
pg_usleep(1000000);/* 1 sec */
438445
}
439446
}
@@ -563,23 +570,18 @@ do_start(void)
563570

564571
if (do_wait)
565572
{
566-
if (!silence_echo)
567-
{
568-
printf(_("waiting for postmaster to start..."));
569-
fflush(stdout);
570-
}
573+
print_msg(_("waiting for postmaster to start..."));
571574

572575
if (test_postmaster_connection()== false)
573576
printf(_("could not start postmaster\n"));
574-
elseif (!silence_echo)
575-
printf(_("done\npostmaster started\n"));
577+
else
578+
print_msg(_("done\npostmaster started\n"));
576579
}
577-
elseif (!silence_echo)
578-
printf(_("postmaster starting\n"));
580+
else
581+
print_msg(_("postmaster starting\n"));
579582
}
580583

581584

582-
583585
staticvoid
584586
do_stop(void)
585587
{
@@ -612,27 +614,18 @@ do_stop(void)
612614

613615
if (!do_wait)
614616
{
615-
if (!silence_echo)
616-
printf(_("postmaster shutting down\n"));
617+
print_msg(_("postmaster shutting down\n"));
617618
return;
618619
}
619620
else
620621
{
621-
if (!silence_echo)
622-
{
623-
printf(_("waiting for postmaster to shut down... "));
624-
fflush(stdout);
625-
}
622+
print_msg(_("waiting for postmaster to shut down..."));
626623

627624
for (cnt=0;cnt<wait_seconds;cnt++)
628625
{
629626
if ((pid=get_pgpid())!=0)
630627
{
631-
if (!silence_echo)
632-
{
633-
printf(".");
634-
fflush(stdout);
635-
}
628+
print_msg(".");
636629
pg_usleep(1000000);/* 1 sec */
637630
}
638631
else
@@ -641,14 +634,12 @@ do_stop(void)
641634

642635
if (pid!=0)/* pid file still exists */
643636
{
644-
if (!silence_echo)
645-
printf(_("failed\n"));
637+
print_msg(_(" failed\n"));
646638

647639
write_stderr(_("%s: postmaster does not shut down\n"),progname);
648640
exit(1);
649641
}
650-
if (!silence_echo)
651-
printf(_("done\n"));
642+
print_msg(_(" done\n"));
652643

653644
printf(_("postmaster stopped\n"));
654645
}
@@ -691,23 +682,15 @@ do_restart(void)
691682
exit(1);
692683
}
693684

694-
if (!silence_echo)
695-
{
696-
printf(_("waiting for postmaster to shut down..."));
697-
fflush(stdout);
698-
}
685+
print_msg(_("waiting for postmaster to shut down..."));
699686

700687
/* always wait for restart */
701688

702689
for (cnt=0;cnt<wait_seconds;cnt++)
703690
{
704691
if ((pid=get_pgpid())!=0)
705692
{
706-
if (!silence_echo)
707-
{
708-
printf(".");
709-
fflush(stdout);
710-
}
693+
print_msg(".");
711694
pg_usleep(1000000);/* 1 sec */
712695
}
713696
else
@@ -716,16 +699,13 @@ do_restart(void)
716699

717700
if (pid!=0)/* pid file still exists */
718701
{
719-
if (!silence_echo)
720-
printf(_(" failed\n"));
702+
print_msg(_(" failed\n"));
721703

722704
write_stderr(_("%s: postmaster does not shut down\n"),progname);
723705
exit(1);
724706
}
725707

726-
if (!silence_echo)
727-
printf(_("done\n"));
728-
708+
print_msg(_(" done\n"));
729709
printf(_("postmaster stopped\n"));
730710
do_start();
731711
}
@@ -760,8 +740,7 @@ do_reload(void)
760740
exit(1);
761741
}
762742

763-
if (!silence_echo)
764-
fprintf(stdout,_("postmaster signaled\n"));
743+
print_msg(_("postmaster signaled\n"));
765744
}
766745

767746
/*
@@ -876,7 +855,7 @@ pgwin32_CommandLine(bool registration)
876855
}
877856

878857
staticvoid
879-
pgwin32_doRegister()
858+
pgwin32_doRegister(void)
880859
{
881860
SC_HANDLEhService;
882861
SC_HANDLEhSCM=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
@@ -908,7 +887,7 @@ pgwin32_doRegister()
908887
}
909888

910889
staticvoid
911-
pgwin32_doUnregister()
890+
pgwin32_doUnregister(void)
912891
{
913892
SC_HANDLEhService;
914893
SC_HANDLEhSCM=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
@@ -1060,7 +1039,7 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR * argv)
10601039
}
10611040

10621041
staticvoid
1063-
pgwin32_doRunAsService()
1042+
pgwin32_doRunAsService(void)
10641043
{
10651044
SERVICE_TABLE_ENTRYst[]= {{register_servicename,pgwin32_ServiceMain},
10661045
{NULL,NULL}};
@@ -1287,7 +1266,7 @@ main(int argc, char **argv)
12871266
register_password=xstrdup(optarg);
12881267
break;
12891268
case's':
1290-
silence_echo= true;
1269+
silent_mode= true;
12911270
break;
12921271
case'U':
12931272
if (strchr(optarg,'\\'))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp