about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-03-31 13:53:34 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-04-12 18:38:37 -0300
commit9d7c5cc38e58fb0923e88901f87174a511b61552 (patch)
treebfd3d255e520814207a27679c8011ad71d71a5dd /misc
parent49a40ba18e2cb948259771317fe6ff6f5eb68683 (diff)
downloadglibc-9d7c5cc38e58fb0923e88901f87174a511b61552.tar.gz
glibc-9d7c5cc38e58fb0923e88901f87174a511b61552.tar.xz
glibc-9d7c5cc38e58fb0923e88901f87174a511b61552.zip
linux: Normalize and return timeout on select (BZ #27651)
The commit 2433d39b697, which added time64 support to select, changed
the function to use __NR_pselect6 (or __NR_pelect6_time64) on all
architectures.  However, on architectures where the symbol was
implemented with __NR_select the kernel normalizes the passed timeout
instead of return EINVAL.  For instance, the input timeval
{ 0, 5000000 } is interpreted as { 5, 0 }.

And as indicated by BZ #27651, this semantic seems to be expected
and changing it results in some performance issues (most likely
the program does not check the return code and keeps issuing
select with unormalized tv_usec argument).

To avoid a different semantic depending whether which syscall the
architecture used to issue, select now always normalize the timeout
input.  This is a slight change for some ABIs (for instance aarch64).

Checked on x86_64-linux-gnu and i686-linux-gnu.
Diffstat (limited to 'misc')
-rw-r--r--misc/tst-select.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/misc/tst-select.c b/misc/tst-select.c
index 5ad057cd51..534105b500 100644
--- a/misc/tst-select.c
+++ b/misc/tst-select.c
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <support/capture_subprocess.h>
 #include <support/check.h>
+#include <support/support.h>
 #include <support/timespec.h>
 #include <support/xunistd.h>
 #include <support/xtime.h>
@@ -47,6 +48,12 @@ do_test_child (void *clousure)
   int r = select (args->fds[0][0] + 1, &rfds, NULL, NULL, &args->tmo);
   TEST_COMPARE (r, 0);
 
+  if (support_select_modifies_timeout ())
+    {
+      TEST_COMPARE (args->tmo.tv_sec, 0);
+      TEST_COMPARE (args->tmo.tv_usec, 0);
+    }
+
   TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts);
 
   xwrite (args->fds[1][1], "foo", 3);
@@ -69,6 +76,16 @@ do_test (void)
 				      sc_allow_none);
   }
 
+  if (support_select_normalizes_timeout ())
+    {
+      /* This is handled as 1 second instead of failing with EINVAL.  */
+      args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 1000000 };
+      struct support_capture_subprocess result;
+      result = support_capture_subprocess (do_test_child, &args);
+      support_capture_subprocess_check (&result, "tst-select-child", 0,
+					sc_allow_none);
+    }
+
   /* Same as before, but simulating polling.  */
   args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 0 };
   {