public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-stable@sourceware.org
Subject: [PATCH 2.33 COMMITTED 6/6] linux: always update select timeout (BZ #27706)
Date: Tue, 13 Apr 2021 18:04:05 -0300	[thread overview]
Message-ID: <20210413210405.913196-6-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20210413210405.913196-1-adhemerval.zanella@linaro.org>

The timeout should be updated even on failure for time64 support.

Checked on i686-linux-gnu.

(cherry-pick from commit cedbf6d5f3f70ca911176de87d6e453eeab4b7a1)
---
 NEWS                             |  1 +
 misc/tst-select.c                | 30 ++++++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/select.c |  4 ++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 52d676f6c5..769aeb24b7 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,7 @@ The following bugs are resolved with this release:
   [27577] elf/ld.so --help doesn't work
   [27648] FAIL: misc/tst-select
   [27651] Performance regression after updating to 2.33
+  [27706] select fails to update timeout on error
 \f
 Version 2.33
 
diff --git a/misc/tst-select.c b/misc/tst-select.c
index 534105b500..52aa26651f 100644
--- a/misc/tst-select.c
+++ b/misc/tst-select.c
@@ -23,6 +23,7 @@
 #include <support/timespec.h>
 #include <support/xunistd.h>
 #include <support/xtime.h>
+#include <support/xsignal.h>
 
 struct child_args
 {
@@ -30,6 +31,12 @@ struct child_args
   struct timeval tmo;
 };
 
+static void
+alarm_handler (int signum)
+{
+  /* Do nothing.  */
+}
+
 static void
 do_test_child (void *clousure)
 {
@@ -59,6 +66,22 @@ do_test_child (void *clousure)
   xwrite (args->fds[1][1], "foo", 3);
 }
 
+static void
+do_test_child_alarm (void *clousure)
+{
+  struct sigaction act = { .sa_handler = alarm_handler };
+  xsigaction (SIGALRM, &act, NULL);
+  alarm (1);
+
+  struct timeval tv = { .tv_sec = 10, .tv_usec = 0 };
+  int r = select (0, NULL, NULL, NULL, &tv);
+  TEST_COMPARE (r, -1);
+  TEST_COMPARE (errno, EINTR);
+
+  if (support_select_modifies_timeout ())
+    TEST_VERIFY (tv.tv_sec < 10);
+}
+
 static int
 do_test (void)
 {
@@ -98,6 +121,13 @@ do_test (void)
   xclose (args.fds[0][0]);
   xclose (args.fds[1][1]);
 
+  {
+    struct support_capture_subprocess result;
+    result = support_capture_subprocess (do_test_child_alarm, NULL);
+    support_capture_subprocess_check (&result, "tst-select-child", 0,
+				      sc_allow_none);
+  }
+
   {
     fd_set rfds;
     FD_ZERO (&rfds);
diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c
index 3b67ff4476..dc16a816ed 100644
--- a/sysdeps/unix/sysv/linux/select.c
+++ b/sysdeps/unix/sysv/linux/select.c
@@ -107,7 +107,7 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
   r = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, pts32,
 		      NULL);
 # endif
-  if (r >= 0 && timeout != NULL)
+  if (timeout != NULL)
     *timeout = valid_timespec_to_timeval64 (ts32);
 #endif
 
@@ -128,7 +128,7 @@ __select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
       ptv64 = &tv64;
     }
   int r = __select64 (nfds, readfds, writefds, exceptfds, ptv64);
-  if (r >= 0 && timeout != NULL)
+  if (timeout != NULL)
     /* The remanining timeout will be always less the input TIMEOUT.  */
     *timeout = valid_timeval64_to_timeval (tv64);
   return r;
-- 
2.27.0


      parent reply	other threads:[~2021-04-13 21:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 21:04 [PATCH 2.33 COMMITTED 1/6] tst: Provide test for select Adhemerval Zanella
2021-04-13 21:04 ` [PATCH 2.33 COMMITTED 2/6] misc: Fix tst-select timeout handling (BZ#27648) Adhemerval Zanella
2021-04-13 21:04 ` [PATCH 2.33 COMMITTED 3/6] libsupport: Add support_select_modifies_timeout Adhemerval Zanella
2021-04-13 21:04 ` [PATCH 2.33 COMMITTED 4/6] libsupport: Add support_select_normalizes_timeout Adhemerval Zanella
2021-04-13 21:04 ` [PATCH 2.33 COMMITTED 5/6] linux: Normalize and return timeout on select (BZ #27651) Adhemerval Zanella
2021-04-13 21:04 ` Adhemerval Zanella [this message]

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=20210413210405.913196-6-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-stable@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).