All of lore.kernel.org
 help / color / mirror / Atom feed
* pselect semantics - no EINTR with pending signals
@ 2011-09-09 13:25 Maciek Borzecki
  2011-09-11 14:45 ` Ulrich Drepper
  0 siblings, 1 reply; 3+ messages in thread
From: Maciek Borzecki @ 2011-09-09 13:25 UTC (permalink / raw)
  To: linux-kernel

I'm running a deamon application, which listens on a number of
sockets, and occasionally spawns gzip to compress some data. It does
happen so, that pselect is used for mutliplexing IO. It also doest
happen so that on one of the fds there is always data to be read (just
a peculiarity of the application, a lot of clients are constantly
writing to a datagram socket and once the daemon is started there is
always data to be read).
That's more less how the code goes:
int main(..)
{
    sigset_t blockset;
    sigset_t oldset;
    ...
    signal(SIGCHLD, ...);
    sigemptyset(&blockset);
    sigaddset(&blockset, SIGCHLD);
    sigprocmask(SIG_SETMASK, &blockset, &oldset);
    ...

    while (1)
    {
        int ret = pselect(maxfd, fdset, NULL, NULL, NULL, &oldset);
        /* ret is always > 0 */

        {
            sigset_t pendset;
            sigpending(&pendset);
            /* apparenty SIGCHLD is present in pending set */
        }
    }
}

What happens is that once a child is spawned, and exists emitting a
SIGCHLD, the signal remains in the pending set. It can only be
determined that the signal was raised by looking at the pending mask.
It is also the case, that SIGCHLD is present in pending set before
entering pselect at some point. However none of the signal handlers
are called.
I looked 2.6.39 do_pselect and it seems that the signal handlers would
only be delivered once core_sys_select returns ERESTARTNOHAND, however
since there is always something to be read on the fds, core_sys_select
always returns value > 0. In that case set_restore_sigmask is never
called, and TIF_SIGPENDING is never set.
So it seems that there is no chance of having the signals delivered
unless pselect blocks waiting for I/O

Now, I'm not sure about the semantics of pselect. I'm not saying that
the current version is right or wrong, but raising a question if this
is really expected (and it did happen to be quite unexpected for me).

--
Maciek Borzecki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pselect semantics - no EINTR with pending signals
  2011-09-09 13:25 pselect semantics - no EINTR with pending signals Maciek Borzecki
@ 2011-09-11 14:45 ` Ulrich Drepper
  2011-09-12  8:47   ` Maciek Borzecki
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Drepper @ 2011-09-11 14:45 UTC (permalink / raw)
  To: Maciek Borzecki; +Cc: linux-kernel

On Fri, Sep 9, 2011 at 09:25, Maciek Borzecki <maciek.borzecki@gmail.com> wrote:
> Now, I'm not sure about the semantics of pselect. I'm not saying that
> the current version is right or wrong, but raising a question if this
> is really expected (and it did happen to be quite unexpected for me).

The standard says

       If  sigmask  is not a null pointer, then the pselect() function
shall replace the signal mask of the
       process by the set of signals pointed to by sigmask before
examining  the  descriptors,  and  shall
       restore the signal mask of the process before returning.

The way I read this the kernel does have to give the signal a chance
to be delivered even if there are file descriptor ready for I/O.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pselect semantics - no EINTR with pending signals
  2011-09-11 14:45 ` Ulrich Drepper
@ 2011-09-12  8:47   ` Maciek Borzecki
  0 siblings, 0 replies; 3+ messages in thread
From: Maciek Borzecki @ 2011-09-12  8:47 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: linux-kernel

On Sun, Sep 11, 2011 at 4:45 PM, Ulrich Drepper <drepper@gmail.com> wrote:
> On Fri, Sep 9, 2011 at 09:25, Maciek Borzecki <maciek.borzecki@gmail.com> wrote:
>> Now, I'm not sure about the semantics of pselect. I'm not saying that
>> the current version is right or wrong, but raising a question if this
>> is really expected (and it did happen to be quite unexpected for me).
>
> The standard says
>
>       If  sigmask  is not a null pointer, then the pselect() function
> shall replace the signal mask of the
>       process by the set of signals pointed to by sigmask before
> examining  the  descriptors,  and  shall
>       restore the signal mask of the process before returning.
>
> The way I read this the kernel does have to give the signal a chance
> to be delivered even if there are file descriptor ready for I/O.
I do agree, otherwise the signal delivery gating functionality of
pselect is not really useful.

I'd submit a patch, provided that current behavior is considered
incorrect. Hopefully userspace would not be affected to the degree
that things would get broken.

--
Maciek Borzecki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-12  8:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 13:25 pselect semantics - no EINTR with pending signals Maciek Borzecki
2011-09-11 14:45 ` Ulrich Drepper
2011-09-12  8:47   ` Maciek Borzecki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.