From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Omar Polo Newsgroups: gmane.lisp.guile.bugs Subject: bug#61095: possible misuse of posix_spawn API on non-linux OSes Date: Fri, 27 Jan 2023 13:25:09 +0100 Message-ID: <3F1FNOS0VFO9X.356V67A0RSKPT@venera> References: <26OIN3L5D4V9L.2M0KM95K0YSNM@venera> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10320"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mblaze/1.2 To: 61095@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Fri Jan 27 13:26:25 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLNoH-0002Rq-LP for guile-bugs@m.gmane-mx.org; Fri, 27 Jan 2023 13:26:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLNnv-0005YT-OF; Fri, 27 Jan 2023 07:26:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLNnu-0005YL-ER for bug-guile@gnu.org; Fri, 27 Jan 2023 07:26:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLNnu-000334-65 for bug-guile@gnu.org; Fri, 27 Jan 2023 07:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pLNnu-0005AD-1S for bug-guile@gnu.org; Fri, 27 Jan 2023 07:26:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <26OIN3L5D4V9L.2M0KM95K0YSNM@venera> Resent-From: Omar Polo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 27 Jan 2023 12:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61095 X-GNU-PR-Package: guile Original-Received: via spool by 61095-submit@debbugs.gnu.org id=B61095.167482232419798 (code B ref 61095); Fri, 27 Jan 2023 12:26:02 +0000 Original-Received: (at 61095) by debbugs.gnu.org; 27 Jan 2023 12:25:24 +0000 Original-Received: from localhost ([127.0.0.1]:36873 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLNnI-00059G-FL for submit@debbugs.gnu.org; Fri, 27 Jan 2023 07:25:24 -0500 Original-Received: from mail.omarpolo.com ([144.91.116.244]:51648) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pLNnD-00058r-D8 for 61095@debbugs.gnu.org; Fri, 27 Jan 2023 07:25:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omarpolo.com; s=20200327; t=1674822312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc; bh=1tTA1Blv5lTEElPHbeaYQkKqMLDTk3GoVPQX6uQYHhw=; b=sJf7sdj8SfmV0MtW0pdyJ3bYIluTGcMt2tiJjn9kLT2ebohUZpJUg17alTQuTLEvlJPuZK AV8Xlmlbjzk/842qFjktHILIgHreN04wsFM0gazxyqZWbKpv6SKPt6IWCB3E9fKnfHqd0B 4Og/wwFew/nmml5PIbNFEIdizu23XYI= Original-Received: from localhost (host-82-61-20-176.retail.telecomitalia.it [82.61.20.176]) by mail.omarpolo.com (OpenSMTPD) with ESMTPSA id 12903135 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <61095@debbugs.gnu.org>; Fri, 27 Jan 2023 13:25:12 +0100 (CET) Original-Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id d6c3c8f5 for <61095@debbugs.gnu.org>; Fri, 27 Jan 2023 13:25:09 +0100 (CET) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10543 Archived-At: Actually I can avoid the EBADF by checking that the fd is 'live' with something like fstat: [[[ Index: libguile/posix.c --- libguile/posix.c.orig +++ libguile/posix.c @@ -1325,8 +1325,12 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0, static void close_inherited_fds_slow (posix_spawn_file_actions_t *actions, int max_fd) { - while (--max_fd > 2) - posix_spawn_file_actions_addclose (actions, max_fd); + struct stat sb; + max_fd = getdtablecount(); + while (--max_fd > 2) { + if (fstat(max_fd, &sb) != -1) + posix_spawn_file_actions_addclose (actions, max_fd); + } } static void ]]] The regress passes and while this workaround may be temporarly acceptable I -personally- don't like it much. There's a reason guile can't set CLOEXEC for all the file descriptors > 2 obtained via open, socket, pipe, ... like perl -for example- does?