*** a/src/bin/pg_ctl/pg_ctl.c --- b/src/bin/pg_ctl/pg_ctl.c *************** *** 1243,1248 **** pgwin32_CommandLine(bool registration) --- 1243,1249 ---- PQExpBuffer cmdLine = createPQExpBuffer(); char cmdPath[MAXPGPATH]; int ret; + char dbPath[MAXPGPATH]; if (registration) { *************** *** 1297,1303 **** pgwin32_CommandLine(bool registration) register_servicename); if (pg_config) ! appendPQExpBuffer(cmdLine, " -D \"%s\"", pg_config); if (registration && do_wait) appendPQExpBuffer(cmdLine, " -w"); --- 1298,1313 ---- register_servicename); if (pg_config) ! { ! if (find_my_abs_path(pg_config, dbPath) != 0) ! { ! write_stderr(_("%s: could not identify current directory\n"), ! progname); ! exit(1); ! } ! ! appendPQExpBuffer(cmdLine, " -D \"%s\"", dbPath); ! } if (registration && do_wait) appendPQExpBuffer(cmdLine, " -w"); *** a/src/common/exec.c --- b/src/common/exec.c *************** *** 586,591 **** set_pglocale_pgservice(const char *argv0, const char *app) --- 586,628 ---- } } + /* + * find_my_abs_path -- find an absolute path to a given file/path + * + * inpath is the input path for which absolute path required. + * retpath is the output area (must be of size MAXPGPATH) + * Returns 0 if OK, -1 if error. + */ + int + find_my_abs_path(char *inpath, char *retpath) + { + char cwd[MAXPGPATH]; + + /* + * Check if it is already absolute path. + */ + if (is_absolute_path(inpath)) + { + StrNCpy(retpath, inpath, MAXPGPATH); + } + else + { + if (!getcwd(cwd, MAXPGPATH)) + { + log_error(_("could not identify current directory: %s"), + strerror(errno)); + return -1; + } + + join_path_components(retpath, cwd, inpath); + canonicalize_path(retpath); + } + + /* use backslashes in path to avoid problems with some third-party tools */ + make_native_path(retpath); + return resolve_symlinks(retpath); + } + #ifdef WIN32 /* *** a/src/include/port.h --- b/src/include/port.h *************** *** 95,100 **** extern void set_pglocale_pgservice(const char *argv0, const char *app); --- 95,101 ---- extern int find_my_exec(const char *argv0, char *retpath); extern int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath); + extern int find_my_abs_path(char *inpath, char *retpath); /* Windows security token manipulation (in exec.c) */ #ifdef WIN32