|
67 | 67 | #include "getaddrinfo.h"
|
68 | 68 | #include "getopt_long.h"
|
69 | 69 | #include "miscadmin.h"
|
| 70 | +#include "fe_utils/string_utils.h" |
70 | 71 |
|
71 | 72 |
|
72 | 73 | /* Define PG_FLUSH_DATA_WORKS if we have an implementation for pg_flush_data */
|
@@ -331,14 +332,6 @@ do { \
|
331 | 332 | output_failed = true, output_errno = errno; \
|
332 | 333 | } while (0)
|
333 | 334 |
|
334 |
| -#ifndef WIN32 |
335 |
| -#define QUOTE_PATH "" |
336 |
| -#define DIR_SEP "/" |
337 |
| -#else |
338 |
| -#define QUOTE_PATH "\"" |
339 |
| -#define DIR_SEP "\\" |
340 |
| -#endif |
341 |
| - |
342 | 335 | static char *
|
343 | 336 | escape_quotes(const char *src)
|
344 | 337 | {
|
@@ -3359,7 +3352,8 @@ main(int argc, char *argv[])
|
3359 | 3352 | int c;
|
3360 | 3353 | int option_index;
|
3361 | 3354 | char *effective_user;
|
3362 |
| - char bin_dir[MAXPGPATH]; |
| 3355 | + PQExpBuffer start_db_cmd; |
| 3356 | + char pg_ctl_path[MAXPGPATH]; |
3363 | 3357 |
|
3364 | 3358 | /*
|
3365 | 3359 | * Ensure that buffering behavior of stdout and stderr matches what it is
|
@@ -3587,14 +3581,33 @@ main(int argc, char *argv[])
|
3587 | 3581 | if (authwarning != NULL)
|
3588 | 3582 | fprintf(stderr, "%s", authwarning);
|
3589 | 3583 |
|
3590 |
| - /* Get directory specification used to start this executable */ |
3591 |
| - strlcpy(bin_dir, argv[0], sizeof(bin_dir)); |
3592 |
| - get_parent_directory(bin_dir); |
| 3584 | + /* |
| 3585 | + * Build up a shell command to tell the user how to start the server |
| 3586 | + */ |
| 3587 | + start_db_cmd = createPQExpBuffer(); |
| 3588 | + |
| 3589 | + /* Get directory specification used to start initdb ... */ |
| 3590 | + strlcpy(pg_ctl_path, argv[0], sizeof(pg_ctl_path)); |
| 3591 | + canonicalize_path(pg_ctl_path); |
| 3592 | + get_parent_directory(pg_ctl_path); |
| 3593 | + /* ... and tag on pg_ctl instead */ |
| 3594 | + join_path_components(pg_ctl_path, pg_ctl_path, "pg_ctl"); |
| 3595 | + |
| 3596 | + /* path to pg_ctl, properly quoted */ |
| 3597 | + appendShellString(start_db_cmd, pg_ctl_path); |
| 3598 | + |
| 3599 | + /* add -D switch, with properly quoted data directory */ |
| 3600 | + appendPQExpBufferStr(start_db_cmd, " -D "); |
| 3601 | + appendShellString(start_db_cmd, pgdata_native); |
| 3602 | + |
| 3603 | + /* add suggested -l switch and "start" command */ |
| 3604 | + appendPQExpBufferStr(start_db_cmd, " -l logfile start"); |
3593 | 3605 |
|
3594 | 3606 | printf(_("\nSuccess. You can now start the database server using:\n\n"
|
3595 |
| - " %s%s%spg_ctl%s -D %s%s%s -l logfile start\n\n"), |
3596 |
| - QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH, |
3597 |
| - QUOTE_PATH, pgdata_native, QUOTE_PATH); |
| 3607 | + " %s\n\n"), |
| 3608 | + start_db_cmd->data); |
| 3609 | + |
| 3610 | + destroyPQExpBuffer(start_db_cmd); |
3598 | 3611 |
|
3599 | 3612 | return 0;
|
3600 | 3613 | }
|
0 commit comments