Re: pg_ctl start broken on windows - Mailing list pgsql-hackers-win32

From Gary Doades
Subject Re: pg_ctl start broken on windows
Date
Msg-id 40C77D68.7337.13AAF9@localhost
Whole thread Raw
In response to Re: pg_ctl start broken on windows  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: pg_ctl start broken on windows  (Andrew Dunstan <andrew@dunslane.net>)
List 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.


pgsql-hackers-win32 by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: pg_ctl start broken on windows
Next
From: Bruce Momjian
Date:
Subject: Re: Re : Win32 binaries test / pg_dump problem