Re: BUG #10794: psql sometimes ignores .psqlrc

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #10794: psql sometimes ignores .psqlrc
Date: 2014-07-16 01:51:39
Message-ID: 7716.1405475499@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Marko Tiikkaja <marko(at)joh(dot)to> writes:
> On 6/28/14, 11:13 PM, marko(at)joh(dot)to wrote:
>> If I press ctrl-C while psql is prompting for a password but then log in
>> (either because I used -W and the server isn't expecting a password or if I
>> subsequently typed in the correct password), .psqlrc isn't processed. This
>> seems quite dangerous if the user is e.g. assuming a specific value for
>> AUTOCOMMIT.

> (seeing that back branch releases are upcoming..) Ping?

I can reproduce that in 9.3, but not in 9.4/HEAD: now, if you control-C at
the password prompt, the program just exits instantly. That's evidently a
result of commit 9099e4afe, which postponed the installation of the SIGINT
handler till after the password prompt. What is happening in the earlier
branches is that the SIGINT handler is setting cancel_pressed, which
doesn't affect collection of the password, but which the main loop then
takes as an indication that you wanted to abandon processing of the script
file (ie, .psqlrc).

There's a bit of a race condition here, in that if you press control-C
just *after* connection setup, it will still allow psql to start up after
having not processed the .psqlrc file. I think though that we'd be ill
advised to try to prevent that by postponing control-C setup even further;
what if the .psqlrc file is broken and initiates some long-running
operation?

So I'm satisfied with the behavior of HEAD in this area. There's a case
to be made for back-patching commit 9099e4afe into older branches, but
I'm not sure if that'd be a good idea or not. People might be depending
on the old behavior.

A different line of thought would be to reset cancel_pressed before
starting the processing of any script file, so that you actually have to
press control-C *during* the processing of a file to cancel it. That's
just narrowing the race condition window some more, but it might be
worth doing.

In any case, I'm disinclined to mess with this in the back branches ...

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Stephen Frost 2014-07-16 02:05:14 Re: BUG #10794: psql sometimes ignores .psqlrc
Previous Message jeff 2014-07-16 00:16:32 BUG #10972: string_agg function incorrectly concatenating varying delimiter