Bug 219676 - pselect6 syscall broken
pselect6 syscall broken
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: kernel (Show other bugs)
6
All Linux
medium Severity medium
: ---
: ---
Assigned To: Kernel Maintainer List
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-12-14 13:29 EST by Jakub Jelinek
Modified: 2007-11-30 17:11 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-12-14 13:48:47 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jakub Jelinek 2006-12-14 13:29:49 EST
2.6.18-1.2726.fc6 x86_64, 2.6.18-1.2798.fc6 ppc64.
glibc tst-pselect.c test often fails, both when using pure userland (racy) implementation (which is to be expected), but also when using pselect6 syscall.

#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/wait.h>


static volatile int handler_called;

static void
handler (int sig)
{
  handler_called = 1;
}

int
main (void)
{
  struct sigaction sa;
  sa.sa_handler = handler;
  sa.sa_flags = 0;
  sigemptyset (&sa.sa_mask);

  if (sigaction (SIGUSR1, &sa, NULL) != 0)
    {
      puts ("sigaction failed");
      return 1;
    }

  sa.sa_handler = SIG_IGN;
  sa.sa_flags = SA_NOCLDWAIT;

  if (sigaction (SIGCHLD, &sa, NULL) != 0)
    {
      puts ("2nd sigaction failed");
      return 1;
    }

  if (sigblock (SIGUSR1) != 0)
    {
      puts ("sigblock failed");
      return 1;
    }

  int fds[2][2];

  if (pipe (fds[0]) != 0 || pipe (fds[1]) != 0)
    {
      puts ("pipe failed");
      return 1;
    }

  fd_set rfds;
  FD_ZERO (&rfds);

  sigset_t ss;
  sigprocmask (SIG_SETMASK, NULL, &ss);
  sigdelset (&ss, SIGUSR1);

  struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };

  pid_t parent = getpid ();
  pid_t p = fork ();
  if (p == 0)
    {
      close (fds[0][1]);
      close (fds[1][0]);

      FD_SET (fds[0][0], &rfds);

      int e;
      do
        {
          if (getppid () != parent)
            exit (2);

          errno = 0;
          e = pselect (fds[0][0] + 1, &rfds, NULL, NULL, &to, &ss);
        }
      while (e == 0);

      if (e != -1)
        {
          puts ("child: pselect did not fail");
          return 0;
        }
      if (errno != EINTR)
        {
          puts ("child: pselect did not set errno to EINTR");
          return 0;
        }

      while (write (fds[1][1], "foo", 3) == -1 && errno == EINTR);

      exit (0);
    }

  close (fds[0][0]);
  close (fds[1][1]);

  FD_SET (fds[1][0], &rfds);

  kill (p, SIGUSR1);

  int e = pselect (fds[1][0] + 1, &rfds, NULL, NULL, NULL, &ss);
  if (e == -1)
    {
      puts ("parent: pselect failed");
      return 1;
    }
  if (e != 1)
    {
      puts ("parent: pselect did not report readable fd");
      return 1;
    }
  if (!FD_ISSET (fds[1][0], &rfds))
    {
      puts ("parent: pselect reports wrong fd");
      return 1;
    }

  return 0;
}

When run as while ./test; do echo -n .; done, it hangs quite soon.
handler_called is certainly 0 before entering the do ... while loop and
1 when it gets stuck, so the signal has been delivered, the only question is why
pselect6 has not returned -EINTR and instead succeeded.
Comment 1 Jakub Jelinek 2006-12-14 13:48:47 EST
Testcase bug apparently, sorry for false alarm.  sigblock (SIGUSR1) blocks
SIGINT and SIGILL (on x86_64), sigblock (sigmask (SIGUSR1)) should have been
called.

Note You need to log in before you can comment on or make changes to this bug.