Question about Ctrl-C and less

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Question about Ctrl-C and less
Date: 2005-10-16 13:25:49
Message-ID: 20051016132547.GD5779@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This behaviour has been around so long that I've gotten used to it but
I've always considered it a bug. Yet it has never been fixed so I'm
going to ask if anybody else has issues with this behaviour.

Reproducing it is easy:

1. Set PAGER=less
2. Start psql
3. Type: \df
4. When output appears, hit Control-C

Now watch as both psql and less try to read your characters, each
getting about half and getting very confused. Even if you manage to get
one of the two to quit, your terminal is still left in a scrambled
state, generally requiring a soft-reset on the terminal.

The fix is easy: where currently the code with popen/pclose ignores
SIGPIPE, tell it to also ignore SIGINT and restore the normal signal
handler on quit. This is almost in line with the system() function
which blocks SIGQUIT and SIGINT while the subprocess is running.

This problem has been around for ever yet obviously not everybody runs
into it all the time like I do. Would patch to fix this be accepted or
is there a reason why not?

Actually, I'm somewhat in favour if getting rid of the longjmp from the
signal handler and instead setting a flag to be checked at strategic
points in the code to abort whatever it is doing. The current way leaks
memory like crazy. If you're worried about infinite loops there's
always SIGQUIT.

Thanks in advance,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Hallgren 2005-10-16 15:23:20 Advice needed concerning Win32 signals
Previous Message Martijn van Oosterhout 2005-10-16 12:56:42 Re: PostgreSQL roadmap for 8.2 and beyond.