Re: [PATCHES] pg_ctl using START with paths needing quotes

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: pgsql-hackers-win32 <pgsql-hackers-win32(at)postgresql(dot)org>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [PATCHES] pg_ctl using START with paths needing quotes
Date: 2004-06-11 20:02:11
Message-ID: 40CA0FC3.5050207@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32 pgsql-patches

Bruce Momjian wrote:

>Tom Lane wrote:
>
>
>>Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>
>>
>>>Bruce Momjian wrote:
>>>
>>>
>>>>This applied patch changes the way pg_ctl starts on Win32.
>>>>
>>>>Using START, it is not possible to quote the executable name, who's
>>>>directory might have spaces:
>>>>
>>>>
>>>This is a really ugly hack (I take the blame since I gave Bruce the
>>>idea). There are a few things to note:
>>>
>>>
>>>. the .bat file should probably be created in the data dir - that's
>>>about the only place that we should be guaranteed we can write.
>>>
>>>
>>In that case, haven't we simply moved the spaces problem from the
>>executable directory to the data directory?
>>
>>
>
>Yep. That code is all gone now that we have the right fix, use:
>
> START "" "executable"
>
>
>

For the record, and in case we need to use it in future, here's what I
got working in pg_ctl.c for starting without any shell call required
(lacks error checking).

cheers

andrew

#ifdef WIN32

char exepath[MAXPGPATH];
STARTUPINFO si;
PROCESS_INFORMATION pi;
bool rval;
int null_fd, log_fd;
int save_stdin, save_stdout, save_stderr;

save_stdin = _dup(fileno(stdin));

ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);

null_fd = open("nul",O_RDONLY,0);
dup2(null_fd, fileno(stdin));
if (log_file != NULL)
{
save_stdout = _dup(fileno(stdout));
save_stderr = _dup(fileno(stderr));
log_fd = open(log_file,O_WRONLY|O_CREAT|O_APPEND,0700);
dup2(log_fd, fileno(stdout));
dup2(log_fd ,fileno(stderr));
}

snprintf(exepath,MAXPGPATH,"%s",postgres_path);
snprintf(cmd,MAXPGPATH,"\"%s\" %s",postgres_path,post_opts);
rval = CreateProcess(exepath,cmd,NULL,NULL,true,0,NULL,NULL,&si,&pi);
if (rval == 0)
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
dup2(save_stdin, fileno(stdin));
close(null_fd);
if (log_file != NULL)
{
dup2(save_stdout,fileno(stdout));
dup2(save_stderr,fileno(stderr));
close(log_fd);
}
return (rval == 0);

#else

In response to

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message pgsql 2004-06-11 20:37:08 Re: [pgsql-hackers-win32] Tablespaces
Previous Message Bruce Momjian 2004-06-11 18:36:40 Re: Fix for erroneous warning on Shutdown

Browse pgsql-patches by date

  From Date Subject
Next Message Manfred Spraul 2004-06-11 21:27:52 Re: Compiling libpq with VisualC
Previous Message Andreas Pflug 2004-06-11 19:05:57 Re: [PATCHES] serverlog function (log_destination file)