Re: Question about Ctrl-C and less

From: mark(at)mark(dot)mielke(dot)cc
To: Kevin Brown <kevin(at)sysexperts(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Question about Ctrl-C and less
Date: 2005-10-21 00:11:14
Message-ID: 20051021001114.GA29877@mark.mielke.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mielke(dot)cc / markm(at)ncf(dot)ca / markm(at)nortel(dot)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 bind them...

http://mark.mielke.cc/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Fuhr 2005-10-21 01:37:43 New timezone data
Previous Message Tom Lane 2005-10-20 22:57:27 Re: 8.04 and RedHat/CentOS init script issue and sleep