Re: Question about Ctrl-C and less - Mailing list pgsql-hackers

From mark@mark.mielke.cc
Subject Re: Question about Ctrl-C and less
Date
Msg-id 20051021001114.GA29877@mark.mielke.cc
Whole thread Raw
In response to Re: Question about Ctrl-C and less  (Kevin Brown <kevin@sysexperts.com>)
Responses Re: Question about Ctrl-C and less
Re: Question about Ctrl-C and less
List pgsql-hackers
On Thu, Oct 20, 2005 at 03:42:10PM -0700, Kevin Brown wrote:
> Martijn van Oosterhout wrote:
> > 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. 
> Yeah, I was thinking that you'd do the check for the flag and invoke a
> cleanup handler after the write() to the output file descriptor.  It's
> not clear that you'd need to do the check anyplace else.  It's been a
> while since I've messed with this stuff, but if I recall correctly,
> the write() will return immediately after receipt of a signal, and
> will indicate how much was actually written.  So receipt of a SIGINT
> should wind up being handled in a reasonably timely fashion.

> Additionally the normal SIGINT signal handler (the one that gets
> invoked when the pager is turned off) can be called from the cleanup
> handler in order to maintain the proper semantics.

I disagree that psql should make *any* assumptions about what SIGINT
means to the child process. Consider less again, and Control-C used
to abort a search. You are suggesting that Control-C should not only
abort the search, but should also cut off the input from less. Less
won't die. Less will just see a terminated input stream. What has been
gained from this? Is this intuitive behaviour?

If the pager does die in response to SIGINT, the write() will fail with
SIGPIPE. Completely clean, without any need for psql to pay attention
to SIGINT.

I think the only reasonable behaviour is to ignore SIGINT within the
parent, until the child exits. I don't see why other behaviours are
even being considered. To me, it points at a misunderstanding of the
problem.

Cheers,
mark

-- 
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada
 One ring to rule them all, one ring to find them, one ring to bring them all                      and in the darkness
bindthem...
 
                          http://mark.mielke.cc/



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 8.04 and RedHat/CentOS init script issue and sleep
Next
From: Michael Fuhr
Date:
Subject: New timezone data