From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 2E6E13858028 for ; Wed, 7 Apr 2021 14:19:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2E6E13858028 Received: by mail-qt1-x82a.google.com with SMTP id g24so13827266qts.6 for ; Wed, 07 Apr 2021 07:19:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WoE71JI+oK2ZUQwbpXfF5Igowe6kRFa+b5frIhsECTI=; b=cm+DP4UjNm6Fjs2JLkRSdCjQQH0sC5KY4MRIproVeDznOPlk/ayfAwhkTaA0V/bM2k sBLG736Lp9/QUMrdr+O9qdW4FdYEV4bUBZR2WAPU8+YQsOAa1imLZz0LqwfRTJYePc7J dVDi6OrsyQgj8sgcMV/ghbio3U/kuQPuFRQ+EFDq9dajbWFxFlaCGCGNyu2xcjlec0r1 uIzqbZ1vngFcMPoTR05Kce5vBMx12jQPJiQS2PyNUlcD18dptEOEK97pPKjDlsglGx09 OJMxNbfJSc7yfeEgmSkkXRalmbY041NqJvojXFB3UEiy11gqMvmS8Wj2YsDWMtY3z7IQ utdw== X-Gm-Message-State: AOAM533hUzd9X2UlDIpbiR3UkAJFzujMXj2sHs1ecCsb2X7bABFnlY81 KBezsihLjl+ChWRrGYeBku7nxgy/qKHE7wEl X-Google-Smtp-Source: ABdhPJwqz5VDfrmqpxmAU9+sRpSU2HUyv+sdzcuNGb/rQi67WnN5HNaMhGZKpcISWp7fYCkPQ86wUw== X-Received: by 2002:ac8:59d4:: with SMTP id f20mr2878005qtf.222.1617805161497; Wed, 07 Apr 2021 07:19:21 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id k28sm18718882qki.101.2021.04.07.07.19.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Apr 2021 07:19:21 -0700 (PDT) Subject: Re: [PATCH] linux: always update select timeout (bug 27706) To: Andreas Schwab , Adhemerval Zanella via Libc-alpha References: From: Adhemerval Zanella Message-ID: <4e290ef6-cd2b-56bc-7472-755d38d5e1ca@linaro.org> Date: Wed, 7 Apr 2021 11:19:19 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Apr 2021 14:19:25 -0000 On 07/04/2021 10:04, Andreas Schwab wrote: > When select returns, sucessfully or not, the timeout argument should > always be updated with the remaining timeout value. Due to a use of the > wrong function for conversion, that never happend for configurations that > support 64-bit time_t. For other configurations, the timeout was only > updated on sucessful return. Could we the other select fix [1] revised as well? With that I can add the timeout tests on the generic tests instead of add as Linux specific. https://patchwork.sourceware.org/project/glibc/patch/20210331175610.3002618-1-adhemerval.zanella@linaro.org/ ? > --- > sysdeps/unix/sysv/linux/Makefile | 2 +- > sysdeps/unix/sysv/linux/select.c | 6 +- > .../sysv/linux/tst-select-update-timeout.c | 55 +++++++++++++++++++ > 3 files changed, 59 insertions(+), 4 deletions(-) > create mode 100644 sysdeps/unix/sysv/linux/tst-select-update-timeout.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index 303fa297bc..e8524e0483 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -109,7 +109,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ > tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux \ > tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes \ > tst-clock_adjtime tst-adjtimex tst-ntp_adjtime tst-ntp_gettime \ > - tst-ntp_gettimex tst-sigtimedwait > + tst-ntp_gettimex tst-sigtimedwait tst-select-update-timeout > > # Test for the symbol version of fcntl that was replaced in glibc 2.28. > ifeq ($(have-GLIBC_2.27)$(build-shared),yesyes) > diff --git a/sysdeps/unix/sysv/linux/select.c b/sysdeps/unix/sysv/linux/select.c > index 415aa87d3c..ad3e0ec634 100644 > --- a/sysdeps/unix/sysv/linux/select.c > +++ b/sysdeps/unix/sysv/linux/select.c > @@ -55,7 +55,7 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, > if (r == 0 || errno != ENOSYS) > { > if (timeout != NULL) > - TIMEVAL_TO_TIMESPEC (timeout, &ts64); > + TIMESPEC_TO_TIMEVAL (timeout, &ts64); > return r; > } > > @@ -84,7 +84,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 > > @@ -105,7 +105,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; > diff --git a/sysdeps/unix/sysv/linux/tst-select-update-timeout.c b/sysdeps/unix/sysv/linux/tst-select-update-timeout.c > new file mode 100644 > index 0000000000..454d4e3ada > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-select-update-timeout.c > @@ -0,0 +1,55 @@ > +/* Test for select timeout updated after return. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > + > +static void > +alarm_handler (int signum) > +{ > + /* Do nothing. */ > +} > + > +static int > +do_test (void) > +{ > + /* When select returns, successfully or not, the timeout argument should > + be updated with the remaining timeout value. */ > + > + struct timeval tv = { .tv_sec = 1 }; > + int r = select (0, NULL, NULL, NULL, &tv); > + TEST_COMPARE (r, 0); > + TEST_COMPARE (tv.tv_sec, 0); > + > + struct sigaction act = { .sa_handler = alarm_handler }; > + xsigaction (SIGALRM, &act, NULL); > + alarm (2); > + > + tv.tv_sec = 10; > + r = select (0, NULL, NULL, NULL, &tv); > + TEST_COMPARE (r, -1); > + TEST_COMPARE (errno, EINTR); > + TEST_VERIFY (tv.tv_sec < 10); > + > + return 0; > +} > + > +#include >