mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
On Windows, use COMSPEC to find the location of cmd.exe.
Historically, psql consulted COMSPEC to spawn a shell in its \! command, but we just invoked "cmd" when spawning shells in pg_ctl and pg_regress. It seems better to rely on the environment variable, if it's set, in all cases. It's debatable whether this is a bug fix or just a behavioral change, so no back-patch. Juan José Santamaría Flecha Discussion: https://postgr.es/m/16080-5d7f03222469f717@postgresql.org
This commit is contained in:
@ -513,13 +513,19 @@ start_postmaster(void)
|
|||||||
* "exec", so we don't get to find out the postmaster's PID immediately.
|
* "exec", so we don't get to find out the postmaster's PID immediately.
|
||||||
*/
|
*/
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
const char *comspec;
|
||||||
|
|
||||||
|
/* Find CMD.EXE location using COMSPEC, if it's set */
|
||||||
|
comspec = getenv("COMSPEC");
|
||||||
|
if (comspec == NULL)
|
||||||
|
comspec = "CMD";
|
||||||
|
|
||||||
if (log_file != NULL)
|
if (log_file != NULL)
|
||||||
snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
|
snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
|
||||||
exec_path, pgdata_opt, post_opts, DEVNULL, log_file);
|
comspec, exec_path, pgdata_opt, post_opts, DEVNULL, log_file);
|
||||||
else
|
else
|
||||||
snprintf(cmd, MAXPGPATH, "CMD /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
|
snprintf(cmd, MAXPGPATH, "\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
|
||||||
exec_path, pgdata_opt, post_opts, DEVNULL);
|
comspec, exec_path, pgdata_opt, post_opts, DEVNULL);
|
||||||
|
|
||||||
if (!CreateRestrictedProcess(cmd, &pi, false))
|
if (!CreateRestrictedProcess(cmd, &pi, false))
|
||||||
{
|
{
|
||||||
|
@ -1193,9 +1193,15 @@ spawn_process(const char *cmdline)
|
|||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
char *cmdline2;
|
char *cmdline2;
|
||||||
HANDLE restrictedToken;
|
HANDLE restrictedToken;
|
||||||
|
const char *comspec;
|
||||||
|
|
||||||
|
/* Find CMD.EXE location using COMSPEC, if it's set */
|
||||||
|
comspec = getenv("COMSPEC");
|
||||||
|
if (comspec == NULL)
|
||||||
|
comspec = "CMD";
|
||||||
|
|
||||||
memset(&pi, 0, sizeof(pi));
|
memset(&pi, 0, sizeof(pi));
|
||||||
cmdline2 = psprintf("cmd /c \"%s\"", cmdline);
|
cmdline2 = psprintf("\"%s\" /c \"%s\"", comspec, cmdline);
|
||||||
|
|
||||||
if ((restrictedToken =
|
if ((restrictedToken =
|
||||||
CreateRestrictedProcess(cmdline2, &pi)) == 0)
|
CreateRestrictedProcess(cmdline2, &pi)) == 0)
|
||||||
|
Reference in New Issue
Block a user