Re: PostgreSQL in Windows console and Ctrl-C

From: Haribabu Kommi <kommi(dot)haribabu(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Christian Ullrich <chris(at)chrullrich(dot)net>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PostgreSQL in Windows console and Ctrl-C
Date: 2014-04-11 01:58:58
Message-ID: CAJrrPGduxVBhWqb2h8BmZiwXwVM4J5KPPQR5RE2gxD+gT4z_Zw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 11, 2014 at 7:44 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
> Can someone with Windows expertise comment on whether this should be
> applied?

I tested the same in windows and it is working as specified.
The same background running server can be closed with ctrl+break command.

> ---------------------------------------------------------------------------
>
> On Tue, Jan 7, 2014 at 12:44:33PM +0100, Christian Ullrich wrote:
>> Hello all,
>>
>> when pg_ctl start is used to run PostgreSQL in a console window on
>> Windows, it runs in the background (it is terminated by closing the
>> window, but that is probably inevitable). There is one problem,
>> however: The first Ctrl-C in that window, no matter in which
>> situation, will cause the background postmaster to exit. If you,
>> say, ping something, and press Ctrl-C to stop ping, you probably
>> don't want the database to go away, too.
>>
>> The reason is that Windows delivers the Ctrl-C event to all
>> processes using that console, not just to the foreground one.
>>
>> Here's a patch to fix that. "pg_ctl stop" still works, and it has no
>> effect when running as a service, so it should be safe. It starts
>> the postmaster in a new process group (similar to calling setpgrp()
>> after fork()) that does not receive Ctrl-C events from the console
>> window.
>>
>> --
>> Christian
>
>> diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
>> new file mode 100644
>> index 50d4586..89a9544
>> *** a/src/bin/pg_ctl/pg_ctl.c
>> --- b/src/bin/pg_ctl/pg_ctl.c
>> *************** CreateRestrictedProcess(char *cmd, PROCE
>> *** 1561,1566 ****
>> --- 1561,1567 ----
>> HANDLE restrictedToken;
>> SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
>> SID_AND_ATTRIBUTES dropSids[2];
>> + DWORD flags;
>>
>> /* Functions loaded dynamically */
>> __CreateRestrictedToken _CreateRestrictedToken = NULL;
>> *************** CreateRestrictedProcess(char *cmd, PROCE
>> *** 1636,1642 ****
>> AddUserToTokenDacl(restrictedToken);
>> #endif
>>
>> ! r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo);
>>
>> Kernel32Handle = LoadLibrary("KERNEL32.DLL");
>> if (Kernel32Handle != NULL)
>> --- 1637,1650 ----
>> AddUserToTokenDacl(restrictedToken);
>> #endif
>>
>> ! flags = CREATE_SUSPENDED;
>> !
>> ! /* Protect console process from Ctrl-C */
>> ! if (!as_service) {
>> ! flags |= CREATE_NEW_PROCESS_GROUP;
>> ! }
>> !
>> ! r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, flags, NULL, NULL, &si, processInfo);
>>
>> Kernel32Handle = LoadLibrary("KERNEL32.DLL");
>> if (Kernel32Handle != NULL)

Regards,
Hari Babu
Fujitsu Australia

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2014-04-11 02:12:54 Re: PostgreSQL in Windows console and Ctrl-C
Previous Message Sachin D. Kotwal 2014-04-11 01:38:27 Re: WAL replay bugs