From patchwork Wed Nov 22 20:15:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 840510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-87431-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="pfcidlGm"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yhtxK2NmWz9rxm for ; Thu, 23 Nov 2017 07:15:33 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= Av/bagfWibk6E62TYlN7XQXfvJH4c40JIw3Mwfocd3E/7VQBm+IJL1qpK4C4Zunm tefs9SeAI7EYjMEeuBuAY5xJEy7q5F2k6kp3XVV4k9rgm3WaUcJQV/KWgx8vJUNh agDBHmXmDU/ksTZNgUz731MkawsvomdTQiPr73aQRJI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=9jCnR2 7Jn1JESPxPOmxz+49lS4s=; b=pfcidlGmThaBvKjrOcksk4SXzt3FnRYHn1GSV/ rkpjszJsBK7AC54EPzuWUGG5B+yxepAXaCK/EGTJxo2BK/qNFyMhP+nBpa2ESPnb PF/JskaKqN95/mqy0CZxQlGvCFlEfg4mg3FH66mdduIdr02QcQSMpqIYWDuukV2t MECvI= Received: (qmail 94787 invoked by alias); 22 Nov 2017 20:15:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 94672 invoked by uid 89); 22 Nov 2017 20:15:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, KB_WAM_FROM_NAME_SINGLEWORD, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=1720, *set, sigs X-HELO: mx1.redhat.com Date: Wed, 22 Nov 2017 21:15:12 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] sigwait: Do not fail with EINTR and return error code [BZ #22478] User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20171122201512.7FF5E414F10CF@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) Since commit 8b0e795aaa445e9167aa07b282c5720b35342c07 Author: Adhemerval Zanella Date: Wed Nov 1 11:49:05 2017 -0200 Simplify Linux sig{timed}wait{info} implementations sigwait can fail with EINTR. Applications do not expect that, and the error code is not documented in POSIX or the manual pages. This commit restores the previous behavior by retrying the system call on EINTR. It also returns the error code, not -1, on the remaing errors. 2017-11-22 Florian Weimer [BZ #22478] * sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Retry on EINTR. Return error code, not -1. * signal/tst-sigwait-eintr.c: New file. * signal/Makefile (tests): Add tst-sigwait-eintr. Reviewed-by: Adhemerval Zanella diff --git a/signal/Makefile b/signal/Makefile index a6a1289437..c2dc719d70 100644 --- a/signal/Makefile +++ b/signal/Makefile @@ -45,8 +45,8 @@ routines := signal raise killpg \ allocrtsig sigtimedwait sigwaitinfo sigqueue \ sighold sigrelse sigignore sigset -tests := tst-signal tst-sigset tst-sigsimple tst-raise tst-sigset2 - +tests := tst-signal tst-sigset tst-sigsimple tst-raise tst-sigset2 \ + tst-sigwait-eintr \ include ../Rules diff --git a/signal/tst-sigwait-eintr.c b/signal/tst-sigwait-eintr.c new file mode 100644 index 0000000000..7149eb93c3 --- /dev/null +++ b/signal/tst-sigwait-eintr.c @@ -0,0 +1,85 @@ +/* Check that sigwait does not fail with EINTR (bug 22478). + Copyright (C) 2017 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 +#include +#include + +/* Handler for SIGUSR1. */ +static void +sigusr1_handler (int signo) +{ + TEST_VERIFY (signo == SIGUSR1); +} + +/* Spawn a subprocess to send two signals: First SIGUSR1, then + SIGUSR2. Return the PID of the process. */ +static pid_t +signal_sender (void) +{ + pid_t pid = xfork (); + if (pid == 0) + { + static const struct timespec delay = { 1, }; + if (nanosleep (&delay, NULL) != 0) + FAIL_EXIT1 ("nanosleep: %m"); + if (kill (getppid (), SIGUSR1) != 0) + FAIL_EXIT1 ("kill (SIGUSR1): %m"); + if (nanosleep (&delay, NULL) != 0) + FAIL_EXIT1 ("nanosleep: %m"); + if (kill (getppid (), SIGUSR2) != 0) + FAIL_EXIT1 ("kill (SIGUSR2): %m"); + _exit (0); + } + return pid; +} + +static int +do_test (void) +{ + if (signal (SIGUSR1, sigusr1_handler) == SIG_ERR) + FAIL_EXIT1 ("signal (SIGUSR1): %m\n"); + + sigset_t sigs; + sigemptyset (&sigs); + sigaddset (&sigs, SIGUSR2); + if (sigprocmask (SIG_BLOCK, &sigs, NULL) != 0) + FAIL_EXIT1 ("sigprocmask (SIGBLOCK, SIGUSR2): %m"); + pid_t pid = signal_sender (); + int signo = 0; + int ret = sigwait (&sigs, &signo); + if (ret != 0) + { + support_record_failure (); + errno = ret; + printf ("error: sigwait failed: %m (%d)\n", ret); + } + TEST_VERIFY (signo == SIGUSR2); + + int status; + xwaitpid (pid, &status, 0); + TEST_VERIFY (status == 0); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/sigwait.c b/sysdeps/unix/sysv/linux/sigwait.c index e6fb32a610..443c3ad8e1 100644 --- a/sysdeps/unix/sysv/linux/sigwait.c +++ b/sysdeps/unix/sysv/linux/sigwait.c @@ -17,13 +17,20 @@ #include #include +#include int __sigwait (const sigset_t *set, int *sig) { siginfo_t si; - if (__sigtimedwait (set, &si, 0) < 0) - return -1; + int ret; + do + ret = __sigtimedwait (set, &si, 0); + /* Applications do not expect sigwait to return with EINTR, and the + error code is not specified by POSIX. */ + while (ret < 0 && errno == EINTR); + if (ret < 0) + return errno; *sig = si.si_signo; return 0; }