From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 11 10:54:31 2025 Received: (at submit) by debbugs.gnu.org; 11 Jun 2025 14:54:31 +0000 Received: from localhost ([127.0.0.1]:50003 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPMqS-00021y-MG for submit@debbugs.gnu.org; Wed, 11 Jun 2025 10:54:30 -0400 Received: from lists.gnu.org ([2001:470:142::17]:35522) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uP5dh-0002k5-Ai for submit@debbugs.gnu.org; Tue, 10 Jun 2025 16:32:10 -0400 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 1uP5dX-00031q-IL for bug-guix@gnu.org; Tue, 10 Jun 2025 16:32:00 -0400 Received: from [2a03:9da0:11:108::2] (helo=hagen2.opopop.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uP5dV-0002U8-RH for bug-guix@gnu.org; Tue, 10 Jun 2025 16:31:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=opopop.net; s=202504; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=FyUmG4HeLuorT3qU2tMnfvrwJW/ubwrmg/eD/8gdHk4=; b=fIB5c/AyQVGzpjh9EVviaWr+gM rOxRaX73oc7p+I8OlT477+ofX43pfBn2M+0BvHDRJ4fPVmNfKuJQzbwlEZ+gSP/xoi7nTmRZ2r49F G1g/4aU++LMJygG2Qta0/rmG5zMFv43qR8Woz8f9DzJIOCBdtSRNZA2QtqvL4EUmOcvVFC9vpUWvW Pm25iqqz84F1VaF/y4+IZw4LRz1sUb9kA8UbhK/NQETz4SvlxvxG2ftKljfHmI4VVDGF5cW/IDQAI xSaKjOPwyM/aLSqt0Yu3zX5Gs9Nkj6ryw3tHsqj4UpdzztoNq/r/i+E8f7+g7+o2dKcZ0fOwE6BIZ QwqsksNQ==; Received: from localhost ([127.0.0.1] helo=hagen2) by hagen2 with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uP5dO-000F4N-3B for bug-guix@gnu.org; Tue, 10 Jun 2025 20:31:51 +0000 From: burban@opopop.net To: bug-guix@gnu.org Subject: shepherd: dangling file descriptor to /dev/console Date: Tue, 10 Jun 2025 20:31:51 +0000 Message-ID: <87sek7pcco.fsf@opopop.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a03:9da0:11:108::2 (failed) Received-SPF: pass client-ip=2a03:9da0:11:108::2; envelope-from=burban@opopop.net; helo=hagen2.opopop.net X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 11 Jun 2025 10:54:26 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) Hello, All shepherd children have an open file descriptor to /dev/console, probably because of the use of dup2 (and not dup3) in system.scm. The pb. disapears if I force that flag with that code before I define my services (context: shepherd used as init system on Debian): (port-for-each (lambda (x) (catch #t (lambda () (when (= (fcntl x F_GETFD) 0) (fcntl x F_SETFD FD_CLOEXEC) (format #t "FD_CLOEXEC flag set on port ~a (fd: ~a)\n" x (port->fdes x)))) (lambda (keys . args) (format #t "fcntl error for port ~a\n" x))) )) Sincerely. -- Bernard From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 13 18:53:34 2025 Received: (at 78757) by debbugs.gnu.org; 13 Jun 2025 22:53:34 +0000 Received: from localhost ([127.0.0.1]:53841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQDHB-0004WP-DY for submit@debbugs.gnu.org; Fri, 13 Jun 2025 18:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40928) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uQDH9-0004VI-Ch for 78757@debbugs.gnu.org; Fri, 13 Jun 2025 18:53:31 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQDH2-0003yR-N8; Fri, 13 Jun 2025 18:53:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=TKTlJxEfjGA49qgUG/bIb3O9GnoOKOwXvjvJUg0Kjr4=; b=jqbtysUZ1LDm8oiRvl7g wBCRaeKPkM6k/Vn4d9PuX9w7thQ5He9jMRUm5Md1cglcKSMh8RtEKfd/acoBJK9z7ZuRvh5s93Ee8 XoIOs3gU0iBOT3uo/D9SdZxmUosCzl+GXkXze5DEaAPln83QJ3zxScNL0nMjen6Irk6hIq02u4208 SIeA9hypDqJy6HOVaNMDOlK2Nd11+6VYfYKJr3MstDWRZQobB/+EA8wIT67kJMi9IpsFfmJDxL864 90UQVU+zDIwTFzvLwZ2zlpxzinzGOy1zwwceaAGOgsEBmu8JlvG0+8IPAL/dhXn+kVcAP8grTl3c6 tEwnLKZNEsD/nQ==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 78757@debbugs.gnu.org, burban@opopop.net Subject: Re: bug#78757: shepherd: dangling file descriptor to /dev/console In-Reply-To: <87sek7pcco.fsf@opopop.net> (burban's message of "Tue, 10 Jun 2025 20:31:51 +0000") References: <87sek7pcco.fsf@opopop.net> User-Agent: mu4e 1.12.11; emacs 29.4 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Sextidi 26 Prairial an 233 de la =?utf-8?Q?R=C3=A9vo?= =?utf-8?Q?lution=2C?= jour du Jasmin Date: Sat, 14 Jun 2025 00:47:56 +0200 Message-ID: <87zfeb5kdf.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78757 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi burban, burban--- via Bug reports for GNU Guix writes: > All shepherd children have an open file descriptor to /dev/console, > probably because of the use of dup2 (and not dup3) in system.scm. I checked the /proc/PID/fd directory of several of my system services on Guix System (nscd, guix-publish, ntpd, upower-daemon) and I don=E2=80=99t s= ee any file descriptor pointing to /dev/console, with version 1.0.5. You said you=E2=80=99re on Debian; which version of the Shepherd is it? I also don=E2=80=99t see any =E2=80=98dup2=E2=80=99 call in =E2=80=98system= .scm=E2=80=99; this takes place rather in =E2=80=98service.scm=E2=80=99. > The pb. disapears if I force that flag with that code before I define > my services (context: shepherd used as init system on Debian): > (port-for-each (lambda (x) > (catch #t > (lambda () > (when (=3D (fcntl x F_GETFD) 0) > (fcntl x F_SETFD FD_CLOEXEC) > (format #t "FD_CLOEXEC flag set on port ~a (fd: ~a)\n" x (port->= fdes x)))) > (lambda (keys . args) (format #t "fcntl error for port ~a\n" x))) > )) =E2=80=98shepherd=E2=80=99 marks all previously-opened FDs as O_CLOEXEC upf= ront=E2=80=94see =E2=80=98mark-as-close-on-exec=E2=80=99 in =E2=80=98shepherd.scm=E2=80=99. = Those opened later are opened with O_CLOEXEC, except for user code that explicitly omits the O_CLOEXEC flag. Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 15 02:58:22 2025 Received: (at 78757) by debbugs.gnu.org; 15 Jun 2025 06:58:22 +0000 Received: from localhost ([127.0.0.1]:52943 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQhJs-0005QT-0x for submit@debbugs.gnu.org; Sun, 15 Jun 2025 02:58:22 -0400 Received: from [2a03:9da0:11:108::2] (port=43756 helo=hagen2.opopop.net) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uQXOL-0005vk-UB for 78757@debbugs.gnu.org; Sat, 14 Jun 2025 16:22:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=opopop.net; s=202504; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=A1mzd0gbiAlCoVLQtsn6IlxYOECZ5N52cGwqEN76Z8U=; b=g0rFh9wDugR2AAjy5VTUqJav8e MPuVa+D8YAVnEIcU2UIG55nhIF8se8TLd75HoUhv6ld5+LAb72C8v8bc/YQ/NDJDihkPQDywj+l2P WreGsN1BEDrbobJo9oijW1uD9rRDnDVy5gq9jGK/oS5JNgQan01E7wBPXN+knjPxSDFSz5JwHSszp /KlnKG29qsmtlFzSg7OywSU2ovDsX//9YXhpRjxxDRyjm1GigeFxGj1U2e4PfZDj5KXxSA3wQhkmA M2yW+X2py3WeepkkBd+i3ZmeKCsvfGgQ7OcL96a2XWx7GXliUw7HZmTrCNuADsXRHGE8Ytn/mVtWm ZcrI5+aA==; Received: from localhost ([127.0.0.1] helo=hagen2) by hagen2 with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uQXOF-000GES-00; Sat, 14 Jun 2025 20:22:11 +0000 From: burban@opopop.net To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: bug#78757: shepherd: dangling file descriptor to /dev/console References: <87sek7pcco.fsf@opopop.net> <87zfeb5kdf.fsf@gnu.org> Date: Sat, 14 Jun 2025 20:22:11 +0000 In-Reply-To: <87zfeb5kdf.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Sat, 14 Jun 2025 00:47:56 +0200") Message-ID: <878qlugjkc.fsf@opopop.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hello, Ludovic Courtès writes: > Hi burban, > > burban--- via Bug reports for GNU Guix writes: > >> All shepherd children have an open file descriptor to /dev/console, >> probably because of the use of dup2 (and [...] Content analysis details: (1.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Debbugs-Envelope-To: 78757 X-Mailman-Approved-At: Sun, 15 Jun 2025 02:58:17 -0400 Cc: 78757@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) Hello, Ludovic Court=C3=A8s writes: > Hi burban, > > burban--- via Bug reports for GNU Guix writes: > >> All shepherd children have an open file descriptor to /dev/console, >> probably because of the use of dup2 (and not dup3) in system.scm. > > I checked the /proc/PID/fd directory of several of my system services on > Guix System (nscd, guix-publish, ntpd, upower-daemon) and I don=E2=80=99t= see > any file descriptor pointing to /dev/console, with version 1.0.5. > > You said you=E2=80=99re on Debian; which version of the Shepherd is it? Bookworm with my own shepherd package (1.0.0) and also Trixie with the official shepherd package (1.0.3). Without the CLOEXEC forcing below, I get this: # lsof |grep shepherd |grep /dev/console shepherd 1 root 0u CHR = 5,1 0t0 12 /dev/console shepherd 1 root 1u CHR = 5,1 0t0 12 /dev/console shepherd 1 root 2u CHR = 5,1 0t0 12 /dev/console shepherd 1 root 19w CHR = 5,1 0t0 12 /dev/console shepherd 1 183 shepherd root 0u CHR = 5,1 0t0 12 /dev/console shepherd 1 183 shepherd root 1u CHR = 5,1 0t0 12 /dev/console shepherd 1 183 shepherd root 2u CHR = 5,1 0t0 12 /dev/console shepherd 1 183 shepherd root 19w CHR = 5,1 0t0 12 /dev/console shepherd 1 251476 shepherd root 0u CHR = 5,1 0t0 12 /dev/console shepherd 1 251476 shepherd root 1u CHR = 5,1 0t0 12 /dev/console shepherd 1 251476 shepherd root 2u CHR = 5,1 0t0 12 /dev/console shepherd 1 251476 shepherd root 19w CHR = 5,1 0t0 12 /dev/console and fd 19 is duplicated for a lot of the children: # lsof |grep 19w systemd-u 211 root 19w CHR = 5,1 0t0 12 /dev/console getty 853 root 19w CHR = 5,1 0t0 12 /dev/console getty 856 root 19w CHR = 5,1 0t0 12 /dev/console getty 859 root 19w CHR = 5,1 0t0 12 /dev/console radvd 894 radvd 19w CHR = 5,1 0t0 12 /dev/console radvd 895 root 19w CHR = 5,1 0t0 12 /dev/console exim4 1001 Debian-exim 19w CHR = 5,1 0t0 12 /dev/console ntpd 1003 ntpsec 19w CHR = 5,1 0t0 12 /dev/console fwknopd 1005 root 19w CHR = 5,1 0t0 12 /dev/console dbus-daem 1006 messagebus 19w CHR = 5,1 0t0 12 /dev/console openvpn 1416 root 19w CHR = 5,1 0t0 12 /dev/console apache2 160524 root 19w CHR = 5,1 0t0 12 /dev/console php-fpm8. 160561 root 19w CHR = 5,1 0t0 12 /dev/console php-fpm8. 160562 www-data 19w CHR = 5,1 0t0 12 /dev/console php-fpm8. 160563 www-data 19w CHR = 5,1 0t0 12 /dev/console unbound 199459 unbound 19w CHR = 5,1 0t0 12 /dev/console postgres 214913 postgres 19w CHR = 5,1 0t0 12 /dev/console cron 230165 root 19w CHR = 5,1 0t0 12 /dev/console apache2 281804 www-data 19w CHR = 5,1 0t0 12 /dev/console apache2 281804 281805 apache2 www-data 19w CHR = 5,1 0t0 12 /dev/console And here the boot log when forcing CLOEXEC: 2025-06-13T11:32:51.657288+02:00 tanis [ 8.21 ] shepherd[1]: fcntl er= ror for port # 2025-06-13T11:32:51.657312+02:00 tanis [ 8.21 ] shepherd[1]: FD_CLOEX= EC flag set on port # (fd: 2) 2025-06-13T11:32:51.657336+02:00 tanis [ 8.21 ] shepherd[1]: FD_CLOEX= EC flag set on port # (fd: 1) 2025-06-13T11:32:51.657359+02:00 tanis [ 8.22 ] shepherd[1]: fcntl er= ror for port # 2025-06-13T11:32:51.657383+02:00 tanis [ 8.22 ] shepherd[1]: FD_CLOEX= EC flag set on port # (fd: 19) 2025-06-13T11:32:51.657408+02:00 tanis [ 8.22 ] shepherd[1]: fcntl er= ror for port # 2025-06-13T11:32:51.657432+02:00 tanis [ 8.22 ] shepherd[1]: FD_CLOEX= EC flag set on port # (fd: 0) 2025-06-13T11:32:51.657456+02:00 tanis [ 8.234859] shepherd[1]: GNU Shep= herd 1.0.3 (Guile 3.0.10, x86_64-pc-linux-gnu) 2025-06-13T11:32:51.657480+02:00 tanis [ 8.234924] shepherd[1]: Starting= service root... 2025-06-13T11:32:51.657503+02:00 tanis [ 8.235127] shepherd[1]: Service = root started. =20 > I also don=E2=80=99t see any =E2=80=98dup2=E2=80=99 call in =E2=80=98syst= em.scm=E2=80=99; this takes place > rather in =E2=80=98service.scm=E2=80=99. Oops, yes of course. >> The pb. disapears if I force that flag with that code before I define >> my services (context: shepherd used as init system on Debian): >> (port-for-each (lambda (x) >> (catch #t >> (lambda () >> (when (=3D (fcntl x F_GETFD) 0) >> (fcntl x F_SETFD FD_CLOEXEC) >> (format #t "FD_CLOEXEC flag set on port ~a (fd: ~a)\n" x (port-= >fdes x)))) >> (lambda (keys . args) (format #t "fcntl error for port ~a\n" x))) >> )) > > =E2=80=98shepherd=E2=80=99 marks all previously-opened FDs as O_CLOEXEC u= pfront=E2=80=94see > =E2=80=98mark-as-close-on-exec=E2=80=99 in =E2=80=98shepherd.scm=E2=80=99= . Those opened later are > opened with O_CLOEXEC, except for user code that explicitly omits the > O_CLOEXEC flag. Hmmm.... I have at one point (before the above (port-for-each ...) (define *s* (open-output-file "/proc/self/fd/1")) to have an early log output to (on ordinary PC) /dev/tty1. But maybe /dev/t= ty1 is a synonym for /dev/console. Let's test that: (fileno *s*) returns 19 indeed! Now all I have to do is (fcntl *s* F_SETFD FD_CLOEXEC) after creating *s*. So you can close that ticket. > > Thanks, > Ludo=E2=80=99. Regards. --=20 Bernard From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 16 09:37:23 2025 Received: (at 78757-done) by debbugs.gnu.org; 16 Jun 2025 13:37:23 +0000 Received: from localhost ([127.0.0.1]:44509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRA1Z-0007pK-Sv for submit@debbugs.gnu.org; Mon, 16 Jun 2025 09:37:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34540) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uRA1D-0007kd-Ib for 78757-done@debbugs.gnu.org; Mon, 16 Jun 2025 09:37:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uRA15-00084F-W6; Mon, 16 Jun 2025 09:36:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=zP45NBtxzKmHuyuk1zZIvXUDJnDvBCZAe0XGLcXT44s=; b=KtUAQTBEEAYFXdhtLVzM +R89EtKabZ0tRirxj2V3BykQV6enekEaNgkv/dbuDpPgb6pwLiVeddZkN1tZv1pjBUiB2Jiw71zCj 6eGcjiAB9EcqPW8NK3GtU3A2dciqYLkjh7/YjkGIRusowSvnptnCscEf0iE/2nAQ+ETOD4VXIttSG wc2IhpioDeoU2ylVkoM+UyAt139ZgauifAyTpVeY1wuxgioaZYIydGhvz1jfHQp2OELZ5u9DCUymv CQ5+xN/j21w1Em2fStCHT5VC+nuH0JH2Kv8g4ey6W6ACB1ZhjJHfZUZyrbvFjUtoNiKT8DfXATQIR KPE90DMrBqTn8Q==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: burban@opopop.net Subject: Re: bug#78757: shepherd: dangling file descriptor to /dev/console In-Reply-To: <878qlugjkc.fsf@opopop.net> (burban@opopop.net's message of "Sat, 14 Jun 2025 20:22:11 +0000") References: <87sek7pcco.fsf@opopop.net> <87zfeb5kdf.fsf@gnu.org> <878qlugjkc.fsf@opopop.net> User-Agent: mu4e 1.12.11; emacs 30.1 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Octidi 28 Prairial an 233 de la =?utf-8?Q?R=C3=A9vol?= =?utf-8?Q?ution=2C?= jour du Thym Date: Mon, 16 Jun 2025 15:35:19 +0200 Message-ID: <87ldprdd2g.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78757-done Cc: 78757-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, burban@opopop.net writes: >> =E2=80=98shepherd=E2=80=99 marks all previously-opened FDs as O_CLOEXEC = upfront=E2=80=94see >> =E2=80=98mark-as-close-on-exec=E2=80=99 in =E2=80=98shepherd.scm=E2=80= =99. Those opened later are >> opened with O_CLOEXEC, except for user code that explicitly omits the >> O_CLOEXEC flag. > > Hmmm.... I have at one point (before the above (port-for-each ...) > > (define *s* (open-output-file "/proc/self/fd/1")) > > to have an early log output to (on ordinary PC) /dev/tty1. But maybe /dev= /tty1 > is a synonym for /dev/console. Let's test that: > > (fileno *s*) returns 19 indeed! Now all I have to do is (fcntl *s* > F_SETFD FD_CLOEXEC) after creating *s*. Ah yes, it=E2=80=99s easy to shot oneself in the foot. ;-) To reduce the risks, =E2=80=98shepherd=E2=80=99 replaces =E2=80=98call-with= -input-file=E2=80=99 and =E2=80=98call-with-output-file=E2=80=99 with O_CLOEXEC variants (commit 47c693d51a991e9a3d5ed6e75760c61e329cc537) because it wouldn=E2=80=99t make = much sense to not have O_CLOEXEC for these. However, the other procedures are left unchanged because users might need it. > So you can close that ticket. Thanks, Ludo=E2=80=99.