*
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.35 2004/10/13 10:35:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.36 2004/10/15 01:36:12 neilc Exp $
*
*-------------------------------------------------------------------------
*/
static bool do_wait = false;
static bool wait_set = false;
static int wait_seconds = 60;
-static bool silence_echo = false;
+static bool silent_mode = false;
static ShutdownMode shutdown_mode = SMART_MODE;
static int sig = SIGTERM; /* default */
static CtlCommand ctl_command = NO_COMMAND;
static void do_help(void);
static void set_mode(char *modeopt);
static void set_sig(char *signame);
-static void do_start();
+static void do_start(void);
static void do_stop(void);
static void do_restart(void);
static void do_reload(void);
static void do_status(void);
static void do_kill(pgpid_t pid);
+static void print_msg(const char *msg);
#if defined(WIN32) || defined(__CYGWIN__)
static bool pgwin32_IsInstalled(SC_HANDLE);
static char *pgwin32_CommandLine(bool);
-static void pgwin32_doRegister();
-static void pgwin32_doUnregister();
+static void pgwin32_doRegister(void);
+static void pgwin32_doUnregister(void);
static void pgwin32_SetServiceStatus(DWORD);
static void WINAPI pgwin32_ServiceHandler(DWORD);
static void WINAPI pgwin32_ServiceMain(DWORD, LPTSTR *);
-static void pgwin32_doRunAsService();
+static void pgwin32_doRunAsService(void);
#endif
static pgpid_t get_pgpid(void);
-static char **readfile(char *path);
+static char **readfile(const char *path);
static int start_postmaster(void);
static bool test_postmaster_connection(void);
}
-
static char *
xstrdup(const char *s)
{
return result;
}
-
+/*
+ * Given an already-localized string, print it to stdout unless the
+ * user has specified that no messages should be printed.
+ */
+static void
+print_msg(const char *msg)
+{
+ if (!silent_mode)
+ {
+ fputs(msg, stdout);
+ fflush(stdout);
+ }
+}
static pgpid_t
get_pgpid(void)
* get the lines from a text file - return NULL if file can't be opened
*/
static char **
-readfile(char *path)
+readfile(const char *path)
{
FILE *infile;
int maxlength = 0,
maxlength = linelen;
/* set up the result and the line buffer */
-
result = (char **) xmalloc((nlines + 1) * sizeof(char *));
buffer = (char *) xmalloc(maxlength + 1);
}
else
{
- if (!silence_echo)
- {
- printf(".");
- fflush(stdout);
- }
+ print_msg(".");
pg_usleep(1000000); /* 1 sec */
}
}
if (do_wait)
{
- if (!silence_echo)
- {
- printf(_("waiting for postmaster to start..."));
- fflush(stdout);
- }
+ print_msg(_("waiting for postmaster to start..."));
if (test_postmaster_connection() == false)
printf(_("could not start postmaster\n"));
- else if (!silence_echo)
- printf(_("done\npostmaster started\n"));
+ else
+ print_msg(_(" done\npostmaster started\n"));
}
- else if (!silence_echo)
- printf(_("postmaster starting\n"));
+ else
+ print_msg(_("postmaster starting\n"));
}
-
static void
do_stop(void)
{
if (!do_wait)
{
- if (!silence_echo)
- printf(_("postmaster shutting down\n"));
+ print_msg(_("postmaster shutting down\n"));
return;
}
else
{
- if (!silence_echo)
- {
- printf(_("waiting for postmaster to shut down... "));
- fflush(stdout);
- }
+ print_msg(_("waiting for postmaster to shut down..."));
for (cnt = 0; cnt < wait_seconds; cnt++)
{
if ((pid = get_pgpid()) != 0)
{
- if (!silence_echo)
- {
- printf(".");
- fflush(stdout);
- }
+ print_msg(".");
pg_usleep(1000000); /* 1 sec */
}
else
if (pid != 0) /* pid file still exists */
{
- if (!silence_echo)
- printf(_("failed\n"));
+ print_msg(_(" failed\n"));
write_stderr(_("%s: postmaster does not shut down\n"), progname);
exit(1);
}
- if (!silence_echo)
- printf(_("done\n"));
+ print_msg(_(" done\n"));
printf(_("postmaster stopped\n"));
}
exit(1);
}
- if (!silence_echo)
- {
- printf(_("waiting for postmaster to shut down..."));
- fflush(stdout);
- }
+ print_msg(_("waiting for postmaster to shut down..."));
/* always wait for restart */
{
if ((pid = get_pgpid()) != 0)
{
- if (!silence_echo)
- {
- printf(".");
- fflush(stdout);
- }
+ print_msg(".");
pg_usleep(1000000); /* 1 sec */
}
else
if (pid != 0) /* pid file still exists */
{
- if (!silence_echo)
- printf(_(" failed\n"));
+ print_msg(_(" failed\n"));
write_stderr(_("%s: postmaster does not shut down\n"), progname);
exit(1);
}
- if (!silence_echo)
- printf(_("done\n"));
-
+ print_msg(_(" done\n"));
printf(_("postmaster stopped\n"));
do_start();
}
exit(1);
}
- if (!silence_echo)
- fprintf(stdout, _("postmaster signaled\n"));
+ print_msg(_("postmaster signaled\n"));
}
/*
}
static void
-pgwin32_doRegister()
+pgwin32_doRegister(void)
{
SC_HANDLE hService;
SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
}
static void
-pgwin32_doUnregister()
+pgwin32_doUnregister(void)
{
SC_HANDLE hService;
SC_HANDLE hSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
}
static void
-pgwin32_doRunAsService()
+pgwin32_doRunAsService(void)
{
SERVICE_TABLE_ENTRY st[] = {{register_servicename, pgwin32_ServiceMain},
{NULL, NULL}};
register_password = xstrdup(optarg);
break;
case 's':
- silence_echo = true;
+ silent_mode = true;
break;
case 'U':
if (strchr(optarg, '\\'))