4
4
*
5
5
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
6
6
*
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 $
8
8
*
9
9
*-------------------------------------------------------------------------
10
10
*/
@@ -66,7 +66,7 @@ typedef enum
66
66
static bool do_wait = false;
67
67
static bool wait_set = false;
68
68
static int wait_seconds = 60 ;
69
- static bool silence_echo = false;
69
+ static bool silent_mode = false;
70
70
static ShutdownMode shutdown_mode = SMART_MODE ;
71
71
static int sig = SIGTERM ; /* default */
72
72
static CtlCommand ctl_command = NO_COMMAND ;
@@ -92,25 +92,26 @@ static void do_advice(void);
92
92
static void do_help (void );
93
93
static void set_mode (char * modeopt );
94
94
static void set_sig (char * signame );
95
- static void do_start ();
95
+ static void do_start (void );
96
96
static void do_stop (void );
97
97
static void do_restart (void );
98
98
static void do_reload (void );
99
99
static void do_status (void );
100
100
static void do_kill (pgpid_t pid );
101
+ static void print_msg (const char * msg );
101
102
102
103
#if defined(WIN32 ) || defined(__CYGWIN__ )
103
104
static bool pgwin32_IsInstalled (SC_HANDLE );
104
105
static char * pgwin32_CommandLine (bool );
105
- static void pgwin32_doRegister ();
106
- static void pgwin32_doUnregister ();
106
+ static void pgwin32_doRegister (void );
107
+ static void pgwin32_doUnregister (void );
107
108
static void pgwin32_SetServiceStatus (DWORD );
108
109
static void WINAPI pgwin32_ServiceHandler (DWORD );
109
110
static void WINAPI pgwin32_ServiceMain (DWORD , LPTSTR * );
110
- static void pgwin32_doRunAsService ();
111
+ static void pgwin32_doRunAsService (void );
111
112
#endif
112
113
static pgpid_t get_pgpid (void );
113
- static char * * readfile (char * path );
114
+ static char * * readfile (const char * path );
114
115
static int start_postmaster (void );
115
116
static bool test_postmaster_connection (void );
116
117
@@ -201,7 +202,6 @@ xmalloc(size_t size)
201
202
}
202
203
203
204
204
-
205
205
static char *
206
206
xstrdup (const char * s )
207
207
{
@@ -216,7 +216,19 @@ xstrdup(const char *s)
216
216
return result ;
217
217
}
218
218
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
+ static void
224
+ print_msg (const char * msg )
225
+ {
226
+ if (!silent_mode )
227
+ {
228
+ fputs (msg , stdout );
229
+ fflush (stdout );
230
+ }
231
+ }
220
232
221
233
static pgpid_t
222
234
get_pgpid (void )
@@ -247,7 +259,7 @@ get_pgpid(void)
247
259
* get the lines from a text file - return NULL if file can't be opened
248
260
*/
249
261
static char * *
250
- readfile (char * path )
262
+ readfile (const char * path )
251
263
{
252
264
FILE * infile ;
253
265
int maxlength = 0 ,
@@ -281,7 +293,6 @@ readfile(char *path)
281
293
maxlength = linelen ;
282
294
283
295
/* set up the result and the line buffer */
284
-
285
296
result = (char * * ) xmalloc ((nlines + 1 ) * sizeof (char * ));
286
297
buffer = (char * ) xmalloc (maxlength + 1 );
287
298
@@ -429,11 +440,7 @@ test_postmaster_connection(void)
429
440
}
430
441
else
431
442
{
432
- if (!silence_echo )
433
- {
434
- printf ("." );
435
- fflush (stdout );
436
- }
443
+ print_msg ("." );
437
444
pg_usleep (1000000 ); /* 1 sec */
438
445
}
439
446
}
@@ -563,23 +570,18 @@ do_start(void)
563
570
564
571
if (do_wait )
565
572
{
566
- if (!silence_echo )
567
- {
568
- printf (_ ("waiting for postmaster to start..." ));
569
- fflush (stdout );
570
- }
573
+ print_msg (_ ("waiting for postmaster to start..." ));
571
574
572
575
if (test_postmaster_connection () == false)
573
576
printf (_ ("could not start postmaster\n" ));
574
- else if (! silence_echo )
575
- printf (_ ("done\npostmaster started\n" ));
577
+ else
578
+ print_msg (_ (" done\npostmaster started\n" ));
576
579
}
577
- else if (! silence_echo )
578
- printf (_ ("postmaster starting\n" ));
580
+ else
581
+ print_msg (_ ("postmaster starting\n" ));
579
582
}
580
583
581
584
582
-
583
585
static void
584
586
do_stop (void )
585
587
{
@@ -612,27 +614,18 @@ do_stop(void)
612
614
613
615
if (!do_wait )
614
616
{
615
- if (!silence_echo )
616
- printf (_ ("postmaster shutting down\n" ));
617
+ print_msg (_ ("postmaster shutting down\n" ));
617
618
return ;
618
619
}
619
620
else
620
621
{
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..." ));
626
623
627
624
for (cnt = 0 ; cnt < wait_seconds ; cnt ++ )
628
625
{
629
626
if ((pid = get_pgpid ()) != 0 )
630
627
{
631
- if (!silence_echo )
632
- {
633
- printf ("." );
634
- fflush (stdout );
635
- }
628
+ print_msg ("." );
636
629
pg_usleep (1000000 ); /* 1 sec */
637
630
}
638
631
else
@@ -641,14 +634,12 @@ do_stop(void)
641
634
642
635
if (pid != 0 ) /* pid file still exists */
643
636
{
644
- if (!silence_echo )
645
- printf (_ ("failed\n" ));
637
+ print_msg (_ (" failed\n" ));
646
638
647
639
write_stderr (_ ("%s: postmaster does not shut down\n" ), progname );
648
640
exit (1 );
649
641
}
650
- if (!silence_echo )
651
- printf (_ ("done\n" ));
642
+ print_msg (_ (" done\n" ));
652
643
653
644
printf (_ ("postmaster stopped\n" ));
654
645
}
@@ -691,23 +682,15 @@ do_restart(void)
691
682
exit (1 );
692
683
}
693
684
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..." ));
699
686
700
687
/* always wait for restart */
701
688
702
689
for (cnt = 0 ; cnt < wait_seconds ; cnt ++ )
703
690
{
704
691
if ((pid = get_pgpid ()) != 0 )
705
692
{
706
- if (!silence_echo )
707
- {
708
- printf ("." );
709
- fflush (stdout );
710
- }
693
+ print_msg ("." );
711
694
pg_usleep (1000000 ); /* 1 sec */
712
695
}
713
696
else
@@ -716,16 +699,13 @@ do_restart(void)
716
699
717
700
if (pid != 0 ) /* pid file still exists */
718
701
{
719
- if (!silence_echo )
720
- printf (_ (" failed\n" ));
702
+ print_msg (_ (" failed\n" ));
721
703
722
704
write_stderr (_ ("%s: postmaster does not shut down\n" ), progname );
723
705
exit (1 );
724
706
}
725
707
726
- if (!silence_echo )
727
- printf (_ ("done\n" ));
728
-
708
+ print_msg (_ (" done\n" ));
729
709
printf (_ ("postmaster stopped\n" ));
730
710
do_start ();
731
711
}
@@ -760,8 +740,7 @@ do_reload(void)
760
740
exit (1 );
761
741
}
762
742
763
- if (!silence_echo )
764
- fprintf (stdout , _ ("postmaster signaled\n" ));
743
+ print_msg (_ ("postmaster signaled\n" ));
765
744
}
766
745
767
746
/*
@@ -876,7 +855,7 @@ pgwin32_CommandLine(bool registration)
876
855
}
877
856
878
857
static void
879
- pgwin32_doRegister ()
858
+ pgwin32_doRegister (void )
880
859
{
881
860
SC_HANDLE hService ;
882
861
SC_HANDLE hSCM = OpenSCManager (NULL , NULL , SC_MANAGER_ALL_ACCESS );
@@ -908,7 +887,7 @@ pgwin32_doRegister()
908
887
}
909
888
910
889
static void
911
- pgwin32_doUnregister ()
890
+ pgwin32_doUnregister (void )
912
891
{
913
892
SC_HANDLE hService ;
914
893
SC_HANDLE hSCM = OpenSCManager (NULL , NULL , SC_MANAGER_ALL_ACCESS );
@@ -1060,7 +1039,7 @@ pgwin32_ServiceMain(DWORD argc, LPTSTR * argv)
1060
1039
}
1061
1040
1062
1041
static void
1063
- pgwin32_doRunAsService ()
1042
+ pgwin32_doRunAsService (void )
1064
1043
{
1065
1044
SERVICE_TABLE_ENTRY st [] = {{register_servicename , pgwin32_ServiceMain },
1066
1045
{NULL , NULL }};
@@ -1287,7 +1266,7 @@ main(int argc, char **argv)
1287
1266
register_password = xstrdup (optarg );
1288
1267
break ;
1289
1268
case 's' :
1290
- silence_echo = true;
1269
+ silent_mode = true;
1291
1270
break ;
1292
1271
case 'U' :
1293
1272
if (strchr (optarg , '\\' ))
0 commit comments