Re: pg_ctl start broken on windows

"Gary Doades" <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.win32
Message-ID <40C77D68.7337.13AAF9@localhost>
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.


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [email protected] so that your
      message can get through to the mailing list cleanly
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.