Re: Question about Ctrl-C and less
От | Martijn van Oosterhout |
---|---|
Тема | Re: Question about Ctrl-C and less |
Дата | |
Msg-id | 20051019132924.GD5422@svana.org обсуждение исходный текст |
Ответ на | Re: Question about Ctrl-C and less (Kevin Brown <kevin@sysexperts.com>) |
Ответы |
Re: Question about Ctrl-C and less
(Kevin Brown <kevin@sysexperts.com>)
|
Список | pgsql-hackers |
On Wed, Oct 19, 2005 at 04:24:21AM -0700, Kevin Brown wrote: > It does? It looked to me like it was setting the signal handler to > SIG_IGN before doing the popen(), and resetting it to the internal > signal handler after doing the pclose(). Oops, you're right. It works because less sets it's own signal handler, as does more. Sure, the status is inherited but I doubt there's a pager out there that doesn't set its own signal handlers. Still, best do it properly. > If I were to take that approach, I'd do the check immediately after > writing to the pipe for sure, and possibly after reading from the > database handle. I'd have to look at the code to see what's going on > and thus where the best places to stick the checks are. But in > general, you want to put a check anywhere within the loop that is > immediately after a blocking operation such as a read or write. > However, that said... Well, the pager is only run after all the data has been collected from the server so none of this is an issue while the query is being processed. Send the cancel request and toss the data. Once we start the pager just check after each line is printed. > The semantics for handling SIGINT here should be pretty much the same > as they are when there's no pager at all (which I know works because I <snip> You can't do a pclose in a signal handler, it's not one of the "reeentrant safe" functions and could lead to deadlocks. The signal manpage documents the ones you can use. Just set a flag. Setting the descriptor to NULL is worse because then we have check before every output function. fprintf(NULL, ...) will segfault on most architechtures I wager. Also, the signal handler can't free the memory, there's way too many arrays. A flag allows the output functions to exit sanely. > If you're hitting SIGQUIT a lot then perhaps you need to assign it to > a different key. :-) I use SIGQUIT to get out of the situation you get currently when you press Ctrl-C to interrupt less. Somehow all the "q"s go to psql and all the Ctrl-Ds to less. SIGQUIT just kills them both from where I can clean the terminal up. So I will press SIGQUIT less once we fix up psql to not do stupid things on SIGINT. :) Have a nice day, -- Martijn van Oosterhout <kleptog@svana.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.
В списке pgsql-hackers по дате отправления: