Re: longjmp in psql considered harmful - Mailing list pgsql-hackers

From Tom Lane
Subject Re: longjmp in psql considered harmful
Date
Msg-id 14049.1150157641@sss.pgh.pa.us
Whole thread Raw
In response to Re: longjmp in psql considered harmful  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: longjmp in psql considered harmful  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
Martijn van Oosterhout <kleptog@svana.org> writes:
> But the effect would change still, even with readline enabled. If
> readline is compiled in and you press control-C, our handler is still
> called. Currently, we siglongjmp out of readline() and start again. If
> you only set a flag like proposed, we won't break out of the readline
> call. readline will clear any partial state, but that's it.

I had interpreted the readline documentation to mean that readline would
discard a partially typed line upon catching SIGINT.  Experimentation
shows that this is not so, at least not with the version of readline I
use here.  It does catch the signal and reset some internal state, but
the partially typed line is NOT discarded.  Grumble.

So I think this patch's basic approach is right: we need to set a flag
to allow the longjmp only when we are inside readline or fgets.  (I
looked a bit at the readline sources, and it does seem designed to block
signals when it's doing something it doesn't want interrupted, so we'll
assume it's doing it correctly.)

I'll work on reviewing and applying the patch.  I don't much like the
side-effects on the /scripts directory though ... there must be a better
way than that.  Is it sane to declare the flag variable in print.c?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCHES] Non-transactional pg_class, try 2
Next
From: Bruce Momjian
Date:
Subject: Re: CSV mode option for pg_dump