From: "Daniel R. Kegel" <dank@alumni.caltech.edu>
To: lk@tantalophile.demon.co.uk
Cc: linux-kernel@vger.kernel.org, x@xman.org
Subject: Re: A signal fairy tale
Date: Thu, 28 Jun 2001 13:11:04 -0700 (PDT) [thread overview]
Message-ID: <200106282011.NAA21508@alumnus.caltech.edu> (raw)
Jamie wrote:
> Daniel R. Kegel wrote:
> > Christopher Smith <x@xman.org> wrote:
> > > Jamie Lokier <lk@tantalophile.demon.co.uk> wrote:
> > > > Btw, this functionality is already available using sigaction(). Just
> > > > search for a signal whose handler is SIG_DFL. If you then block that
> > > > signal before changing, checking the result, and unblocking the signal,
> > > > you can avoid race conditions too. (This is what my programs do).
> > >
> > > It's more than whether a signal is blocked or not, unfortunately. Lots of
> > > applications will invoke sigwaitinfo() on whatever the current signal mask
> > > is, which means you can't rely on sigaction to solve your problems. :-(
> >
> > As Chris points out, allocating a signal by the scheme Jamie
> > describes is neccessary but not sufficient. The problem Chris
> > ran into is that he allocated a signal fair and square, only to find
> > the application picking it up via sigwaitinfo()!
>
> I check that the handler is not SIG_DFL, but perhaps my assumption that
> any sigwaitinfo() user of a signal would set SA_SIGINFO and set the
> handler to non-SIG_DFL is mistaken?
I think your assumption is correct. The problem is that the
application in question (Sun's JDK 1.4 beta) does something like this:
sigprocmask(0, NULL, &oldset);
sigwaitinfo(&oldset, &info);
So even though Chris did set the handler for his signal to non-SIG_DFL,
the application didn't care, and sucked all his signal notifications
away from him.
> > Yes, this is a bug in the application -- but it's interesting that this
> > bug only shows up when you try to integrate a new, well-behaved, library
> > into the app. It's a fragile part of the Unix API. sigopen() is
> > a way for libraries to defend themselves against misuse of sigwaitinfo()
> > by big applications over which you have no control.
> >
> > So sigopen() is a technological fix to a social problem, I guess.
>
> Requiring all libraries to use the sigopen() as you specified it just
> isn't going to work, because you would have to make big changes to the
> libraries.
I didn't mean to require any library to change at all. This is
an optional thing; a library can use this technique if it wants to
insulate itself from badly behaved applications.
> Sometimes you actually do need SIGRTxxx signals to be delivered using
> signal handlers!
No objection there, I agree.
> Also as it was specified, you are reduced to reading one type of signal
> at a time, or using select(). Often you wish to check several signals.
> For example, in my programs sigwaitinfo() calls check for SIGIO, SIGURG
> and SIGRTxxx at least. Therefore siginfo(), if implemented, should take
> a sigset_t, not a signal number.
I have no objection to sigopen() taking a sigset_t *.
> The problem of when you actually want to receive an allocated signal
> through a handler is, IMHO, best solved by permitting sigaction() and
> signal delivery on signals that have been opened with sigopen().
sigopen() essentially installs a special signal handler (say, SIG_OPEN).
If sigaction() can override that, it should probably close the file descriptor, too.
I can buy that, perhaps, even though it makes libraries using sigopen()
somewhat more vulnerable to poorly behaved applications. I think the
present application doesn't misbehave badly enough that it would try to
install a signal handler over Chris's.
> However, it would be ok to require a flag SA_SIGOPEN to sigaction() to
> prevent it from returning EBUSY.
That'd be ok.
Another issue someone raised:
> would read() on this fd require the kernel to copy every byte of the siginfo_t?
IMHO no; read() would leave undefined any bytes that would not have been set by
sigwaitinfo(). The kernel could set them to zero or leave them untouched,
as desired.
Another issue:
AFAIK, there's no 'read with a timeout' system call for file descriptors, so
if you needed the equivalent of sigtimedwait(),
you might end up doing a select on the sigopen fd, which is an extra
system call. (I wish Posix had invented sigopen() and readtimedwait() instead of
sigtimedwait...)
- Dan
next reply other threads:[~2001-06-28 20:11 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-28 20:11 Daniel R. Kegel [this message]
2001-06-29 8:31 ` Christopher Smith
[not found] <fa.d69j5vv.ej8irj@ifi.uio.no>
[not found] ` <fa.h2rpibv.87m5bp@ifi.uio.no>
2001-06-28 14:59 ` Dan Maas
2001-06-28 15:21 ` Alan Cox
2001-06-29 8:26 ` Christopher Smith
2001-06-29 11:56 ` Chris Wedgwood
2001-06-30 10:02 ` Jan Hudec
-- strict thread matches above, loose matches on Subject: below --
2001-06-28 3:04 Daniel R. Kegel
2001-06-28 14:46 ` Jamie Lokier
2001-06-28 2:57 Daniel R. Kegel
2001-06-29 8:19 ` Christopher Smith
2001-06-29 9:29 ` Dan Kegel
2001-06-29 18:46 ` Dan Kegel
2001-07-02 22:33 ` Christopher Smith
2001-06-28 2:49 Daniel R. Kegel
2001-06-29 8:18 ` Christopher Smith
2001-06-29 9:05 ` Dan Kegel
2001-06-26 12:54 Dan Kegel
2001-06-27 3:56 ` Christopher Smith
2001-06-27 6:21 ` Balbir Singh
2001-06-27 18:11 ` Christopher Smith
2001-06-28 3:28 ` Balbir Singh
2001-06-27 9:18 ` Jamie Lokier
2001-06-27 18:16 ` Christopher Smith
2001-06-28 12:58 ` John Fremlin
2001-06-28 16:21 ` Jamie Lokier
2001-06-29 8:22 ` Christopher Smith
2001-06-29 11:47 ` John Fremlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200106282011.NAA21508@alumnus.caltech.edu \
--to=dank@alumni.caltech.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=lk@tantalophile.demon.co.uk \
--cc=x@xman.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®