Re: pg_ctl start broken on windows

From: "Gary Doades" <gpd(at)gpdnet(dot)co(dot)uk>
To: pgsql-hackers-win32 <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: pg_ctl start broken on windows
Date: 2004-06-09 20:13:12
Message-ID: 40C77D68.7337.13AAF9@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32

On 9 Jun 2004 at 15:43, Andrew Dunstan wrote:

>
> I don't see that it buys you much. But maybe you'd like to submit a
> patch? (What is there isn't a desktop window, e.g. we are starting from
> the service manager, as has been suggested for pg_ctl?)
>

It doesn't buy you anything except a few lines of code. I thought you
were looking for simplicity. I suggested this as a simple drop in
replacement for the system() call. I could do a patch, but by the time I
figured out where to put it etc, someone who knows the code well could
just drop this in.

Is it pg_ctl that is a service and this starts postmaster? If so then I
agree that you will probably need CreateProcess. This will give you
much more control over the created process anyway.

Here is a minimal example for CreateProcess

STARTUPINFO si;
PROCESS_INFORMATION pi;

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

// Start the child process.
if( !CreateProcess( "c:\\windows\system32\cmd.exe", // executable
"arg1 arg2 arg3", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
ErrorExit( "CreateProcess failed." );
}

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

where ZeroMemory is whatever convenient function you have for
clearing a block of memory.

You MUST close the process and thread handles afterwards to avoid
handle leaks. You could of course use (not close) the process handle in
pg_ctl (if it was the permanently running service) to monitor postmaster
for crashing out.

Regards,
Gary.

In response to

Responses

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Bruce Momjian 2004-06-10 02:42:43 Re: Re : Win32 binaries test / pg_dump problem
Previous Message Andrew Dunstan 2004-06-09 19:43:16 Re: pg_ctl start broken on windows