From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.bugs Subject: bug#30368: =?UTF-8?Q?=E2=80=98select=E2=80=99?= returns non-empty sets upon EINTR or EAGAIN Date: Tue, 06 Feb 2018 11:39:30 +0100 Message-ID: <87y3k67671.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1517913526 28204 195.159.176.226 (6 Feb 2018 10:38:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 6 Feb 2018 10:38:46 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) To: 30368@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Feb 06 11:38:41 2018 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ej0dn-0005Zd-Ee for guile-bugs@m.gmane.org; Tue, 06 Feb 2018 11:38:19 +0100 Original-Received: from localhost ([::1]:53211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej0fm-0002B8-T3 for guile-bugs@m.gmane.org; Tue, 06 Feb 2018 05:40:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej0fX-00025C-TS for bug-guile@gnu.org; Tue, 06 Feb 2018 05:40:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej0fS-0001Kw-Vv for bug-guile@gnu.org; Tue, 06 Feb 2018 05:40:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ej0fS-0001Kh-Rc for bug-guile@gnu.org; Tue, 06 Feb 2018 05:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ej0fS-0006Et-EO for bug-guile@gnu.org; Tue, 06 Feb 2018 05:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 06 Feb 2018 10:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30368 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.151791358723951 (code B ref -1); Tue, 06 Feb 2018 10:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Feb 2018 10:39:47 +0000 Original-Received: from localhost ([127.0.0.1]:59565 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ej0fC-0006EE-W1 for submit@debbugs.gnu.org; Tue, 06 Feb 2018 05:39:47 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:58151) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ej0fB-0006E0-HN for submit@debbugs.gnu.org; Tue, 06 Feb 2018 05:39:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej0f5-00012f-6c for submit@debbugs.gnu.org; Tue, 06 Feb 2018 05:39:40 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:56762) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej0f5-00012Y-2g for submit@debbugs.gnu.org; Tue, 06 Feb 2018 05:39:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej0f3-0001kb-Tm for bug-guile@gnu.org; Tue, 06 Feb 2018 05:39:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej0ey-0000yu-WD for bug-guile@gnu.org; Tue, 06 Feb 2018 05:39:37 -0500 Original-Received: from hera.aquilenet.fr ([2a0c:e300::1]:33734) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej0ey-0000yI-Na for bug-guile@gnu.org; Tue, 06 Feb 2018 05:39:32 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 369589EF4 for ; Tue, 6 Feb 2018 11:39:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Original-Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NUI8GNhcuEBr for ; Tue, 6 Feb 2018 11:39:30 +0100 (CET) Original-Received: from ribbon (unknown [193.50.110.200]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 7A5CC6FF0 for ; Tue, 6 Feb 2018 11:39:30 +0100 (CET) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 =?UTF-8?Q?Pluvi=C3=B4se?= an 226 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8998 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, As of Guile 2.2.3, the Scheme-level =E2=80=98select=E2=80=99 can return non= -empty sets when the C-level =E2=80=98select=E2=80=99 returns EINTR or EAGAIN. The pro= gram below illustrates this: --8<---------------cut here---------------start------------->8--- (use-modules (ice-9 match)) (sigaction SIGINT (lambda args (pk 'signal! args))) (let ((target (getpid))) (match (primitive-fork) ((? zero?) (sleep 4) (kill target SIGINT) (primitive-exit 0)) (_ #t))) (match (select (list (current-input-port)) '() '()) (((port) () ()) (pk 'reading-from port) (read-char port)) (lst (pk 'done lst))) --8<---------------cut here---------------end--------------->8--- On 2.2.3, it prints: --8<---------------cut here---------------start------------->8--- $ guile select.scm ;;; (signal! (2)) ;;; (reading-from #) --8<---------------cut here---------------end--------------->8--- >From there on it=E2=80=99s stuck in a read(0, =E2=80=A6) call. The attached patch fixes it by clearing the returned FD sets on EINTR/EAGAIN. (Besides it seems that select(2) never returns EAGAIN.) I=E2=80=99m not sure how to write a test for this; the one above is timing-sensitive, which wouldn=E2=80=99t be great. Thoughts? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/libguile/filesys.c b/libguile/filesys.c index e39dc4a0d..05dd2bd16 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1,5 +1,5 @@ /* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2006, - * 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017 Free Software Foundation, Inc. + * 2009, 2010, 2011, 2012, 2013, 2014, 2016, 2017, 2018 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -900,10 +900,20 @@ SCM_DEFINE (scm_select, "select", 3, 2, 0, int rv = scm_std_select (max_fd + 1, &read_set, &write_set, &except_set, time_ptr); - /* Let EINTR / EAGAIN cause a return to the user and let them loop - to run any asyncs that might be pending. */ - if (rv < 0 && errno != EINTR && errno != EAGAIN) - SCM_SYSERROR; + if (rv < 0) + { + /* Let EINTR / EAGAIN cause a return to the user and let them + loop to run any asyncs that might be pending. */ + if (errno != EINTR && errno != EAGAIN) + SCM_SYSERROR; + else + { + /* Return empty sets. */ + FD_ZERO (&read_set); + FD_ZERO (&write_set); + FD_ZERO (&except_set); + } + } } return scm_list_3 (retrieve_select_type (&read_set, read_ports_ready, reads), --=-=-=--