Re: longjmp in psql considered harmful

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: longjmp in psql considered harmful
Date: 2006-06-13 00:14:01
Message-ID: 14049.1150157641@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Martijn van Oosterhout <kleptog(at)svana(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2006-06-13 01:25:35 Re: CSV mode option for pg_dump
Previous Message Tom Lane 2006-06-12 23:15:14 Re: [PATCHES] Non-transactional pg_class, try 2