From unknown Sat Aug 09 13:18:38 2025 X-Loop: help-debbugs@gnu.org Subject: bug#73589: system* does not honor SIGINT restoration in child Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 01 Oct 2024 20:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73589 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 73589@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17278158788446 (code B ref -1); Tue, 01 Oct 2024 20:52:01 +0000 Received: (at submit) by debbugs.gnu.org; 1 Oct 2024 20:51:18 +0000 Received: from localhost ([127.0.0.1]:53621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svjq2-0002C9-Ae for submit@debbugs.gnu.org; Tue, 01 Oct 2024 16:51:18 -0400 Received: from lists.gnu.org ([209.51.188.17]:38838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svjpz-0002C0-LW for submit@debbugs.gnu.org; Tue, 01 Oct 2024 16:51:16 -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 1svjpy-0008JB-9D for bug-guile@gnu.org; Tue, 01 Oct 2024 16:51:14 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svjpv-0001TF-TA for bug-guile@gnu.org; Tue, 01 Oct 2024 16:51:14 -0400 Received: from localhost (157-208-8-209.mc.derytele.com [157.208.8.209]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 491Kp3rl122280 for ; Tue, 1 Oct 2024 16:51:07 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 491Kp3rl122280 From: Olivier Dion Date: Tue, 01 Oct 2024 16:51:03 -0400 Message-ID: <87jzer7djc.fsf@laura> MIME-Version: 1.0 Content-Type: text/plain X-Poly-FromMTA: (157-208-8-209.mc.derytele.com [157.208.8.209]) at Tue, 1 Oct 2024 20:51:03 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) 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: -2.3 (--) Hi, Given the following C program: --8<---------------cut here---------------start------------->8--- #include #include int main(void) { struct sigaction act; sigaction(SIGINT, NULL, &act); printf("%p %p %p\n", act.sa_handler, SIG_IGN, SIG_DFL); } --8<---------------cut here---------------end--------------->8--- and its ouput from various executions: 1) $ ./a.out => (nil) 0x1 (nil) 2) $ guile -c '(system "./a.out")' => (nil) 0x1 (nil) 3) $ guile -c '(system* "./a.out")' => 0x1 0x1 (nil) We can see that 3) does not honor restoration of `SIGINT' to `SIG_DFL' like `system(3)' does. This seems to be because of the following sigaction before the creation of the process: --8<---------------cut here---------------start------------->8--- 1697 scm_dynwind_sigaction (SIGINT, 1698 scm_from_uintptr_t ((uintptr_t) SIG_IGN), 1699 SCM_UNDEFINED); 1700 #ifdef SIGQUIT 1701 scm_dynwind_sigaction (SIGQUIT, 1702 scm_from_uintptr_t ((uintptr_t) SIG_IGN), 1703 SCM_UNDEFINED); 1704 #endif 1705 1706 err = piped_process (&pid, prog, args, 1707 SCM_UNDEFINED, SCM_UNDEFINED); --8<---------------cut here---------------end--------------->8--- >From execve(2): POSIX.1 specifies that the dispositions of any signals that are ignored or set to the default are left unchanged. POSIX.1 specifies one exception: if SIGCHLD is being ignored, then an implementation may leave the disposition unchanged or reset it to the default; Linux does the former. Therefore, setting `SIG_IGN' for `SIGINT' before the fork/execve results in ignoring the signals in the child, which is unexpected as a user of `system(3)'. The solution would be to restore `SIG_DFL' before `execve(2)' if before the call to `system*' the action was not `SIG_IGN'. In the mean time, I have a solution that works for single-threaded application: --8<---------------cut here---------------start------------->8--- (define (system* . args) (let ((handler+flags (sigaction SIGINT))) (dynamic-wind (lambda () (sigaction SIGINT SIG_IGN)) (lambda () (let ((cpid (primitive-fork))) (if (zero? cpid) (catch #t (lambda () (sigaction SIGINT SIG_DFL) (apply execlp (car args) args)) (lambda _ (primitive-exit EXIT_FAILURE))) (waitpid cpid)))) (lambda () (sigaction SIGINT (car handler+flags) (cdr handler+flags)))))) --8<---------------cut here---------------end--------------->8--- Thanks, Olivier -- Olivier Dion oldiob.ca From unknown Sat Aug 09 13:18:38 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Olivier Dion Subject: bug#73589: closed (Re: bug#73589: system* does not honor SIGINT restoration in child) Message-ID: References: <875xpmmwjd.fsf@gnu.org> <87jzer7djc.fsf@laura> X-Gnu-PR-Message: they-closed 73589 X-Gnu-PR-Package: guile Reply-To: 73589@debbugs.gnu.org Date: Sun, 20 Oct 2024 18:59:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1729450742-28747-1" This is a multi-part message in MIME format... ------------=_1729450742-28747-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #73589: system* does not honor SIGINT restoration in child which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 73589@debbugs.gnu.org. --=20 73589: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D73589 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1729450742-28747-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 73589-done) by debbugs.gnu.org; 20 Oct 2024 18:59:00 +0000 Received: from localhost ([127.0.0.1]:48481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2b8m-0007TQ-D4 for submit@debbugs.gnu.org; Sun, 20 Oct 2024 14:59:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2b8k-0007T9-4B for 73589-done@debbugs.gnu.org; Sun, 20 Oct 2024 14:58:59 -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 1t2b8E-00062G-3F; Sun, 20 Oct 2024 14:58:26 -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=BwVoxiPfD2Zh9BlGB7GIa06QPLtlmdQnxpmUCTeJ/9s=; b=EvzxSP8jEM7pzKvQ8ZYr 02vblnItgPrPkrcRx2g2Pz79DTlrVTSlyQ0tBd9JJVLyw7C0pRkKypJ9TjtzSJoCbVcZZiL0DGmD+ KrCtnMI+y7cbBsDL4fiAnzk4jxwqfL6Oin7XRR+VZ7mJq0hdP8l5q/lP7dHGd4I3V+BA6zZWe7k9a PZHF1OIMqAYKM1BbS1/Ed3paDROir6WunrnH4Xt0Fe8tUJUP1UeVrxVmiGQ1OW93jN7/al2L807Wr NPu3DjnRAiwtefG9Jpt5xOTIRyHd4TrKlRTOfakiqNSGU7MFvQ/4SaehKs+W9AgTLHKYGfWxwpfM0 w7RMvZE6aIMBNg==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Olivier Dion Subject: Re: bug#73589: system* does not honor SIGINT restoration in child In-Reply-To: <87jzer7djc.fsf@laura> (Olivier Dion's message of "Tue, 01 Oct 2024 16:51:03 -0400") References: <87jzer7djc.fsf@laura> Date: Sun, 20 Oct 2024 20:58:14 +0200 Message-ID: <875xpmmwjd.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) 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: 73589-done Cc: 73589-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, Olivier Dion skribis: > and its ouput from various executions: > > 1) $ ./a.out =3D> (nil) 0x1 (nil) > 2) $ guile -c '(system "./a.out")' =3D> (nil) 0x1 (nil) > 3) $ guile -c '(system* "./a.out")' =3D> 0x1 0x1 (nil) > > We can see that 3) does not honor restoration of `SIGINT' to `SIG_DFL' > like `system(3)' does. This seems to be because of the following > sigaction before the creation of the process: > > 1697 scm_dynwind_sigaction (SIGINT, > 1698 scm_from_uintptr_t ((uintptr_t) SIG_IGN), > 1699 SCM_UNDEFINED); > 1700 #ifdef SIGQUIT > 1701 scm_dynwind_sigaction (SIGQUIT, > 1702 scm_from_uintptr_t ((uintptr_t) SIG_IGN), > 1703 SCM_UNDEFINED); > 1704 #endif > 1705 > 1706 err =3D piped_process (&pid, prog, args, > 1707 SCM_UNDEFINED, SCM_UNDEFINED); This was fixed in commit 4ae33f76d6b33ea0bedfa36050d44c88d08c2823, which is included in 3.0.10: --8<---------------cut here---------------start------------->8--- $ cat t.c #include #include int main(void) { struct sigaction act; sigaction(SIGINT, NULL, &act); printf("%p %p %p\n", act.sa_handler, SIG_IGN, SIG_DFL); } $ gcc -Wall t.c $ ./a.out=20 (nil) 0x1 (nil) $ ./meta/guile -c '(system "./a.out")' (nil) 0x1 (nil) $ ./meta/guile -c '(system* "./a.out")' (nil) 0x1 (nil) --8<---------------cut here---------------end--------------->8--- Ludo=E2=80=99. ------------=_1729450742-28747-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 1 Oct 2024 20:51:18 +0000 Received: from localhost ([127.0.0.1]:53621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svjq2-0002C9-Ae for submit@debbugs.gnu.org; Tue, 01 Oct 2024 16:51:18 -0400 Received: from lists.gnu.org ([209.51.188.17]:38838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svjpz-0002C0-LW for submit@debbugs.gnu.org; Tue, 01 Oct 2024 16:51:16 -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 1svjpy-0008JB-9D for bug-guile@gnu.org; Tue, 01 Oct 2024 16:51:14 -0400 Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svjpv-0001TF-TA for bug-guile@gnu.org; Tue, 01 Oct 2024 16:51:14 -0400 Received: from localhost (157-208-8-209.mc.derytele.com [157.208.8.209]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 491Kp3rl122280 for ; Tue, 1 Oct 2024 16:51:07 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 491Kp3rl122280 From: Olivier Dion To: bug-guile@gnu.org Subject: system* does not honor SIGINT restoration in child Date: Tue, 01 Oct 2024 16:51:03 -0400 Message-ID: <87jzer7djc.fsf@laura> MIME-Version: 1.0 Content-Type: text/plain X-Poly-FromMTA: (157-208-8-209.mc.derytele.com [157.208.8.209]) at Tue, 1 Oct 2024 20:51:03 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit 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: -2.3 (--) Hi, Given the following C program: --8<---------------cut here---------------start------------->8--- #include #include int main(void) { struct sigaction act; sigaction(SIGINT, NULL, &act); printf("%p %p %p\n", act.sa_handler, SIG_IGN, SIG_DFL); } --8<---------------cut here---------------end--------------->8--- and its ouput from various executions: 1) $ ./a.out => (nil) 0x1 (nil) 2) $ guile -c '(system "./a.out")' => (nil) 0x1 (nil) 3) $ guile -c '(system* "./a.out")' => 0x1 0x1 (nil) We can see that 3) does not honor restoration of `SIGINT' to `SIG_DFL' like `system(3)' does. This seems to be because of the following sigaction before the creation of the process: --8<---------------cut here---------------start------------->8--- 1697 scm_dynwind_sigaction (SIGINT, 1698 scm_from_uintptr_t ((uintptr_t) SIG_IGN), 1699 SCM_UNDEFINED); 1700 #ifdef SIGQUIT 1701 scm_dynwind_sigaction (SIGQUIT, 1702 scm_from_uintptr_t ((uintptr_t) SIG_IGN), 1703 SCM_UNDEFINED); 1704 #endif 1705 1706 err = piped_process (&pid, prog, args, 1707 SCM_UNDEFINED, SCM_UNDEFINED); --8<---------------cut here---------------end--------------->8--- >From execve(2): POSIX.1 specifies that the dispositions of any signals that are ignored or set to the default are left unchanged. POSIX.1 specifies one exception: if SIGCHLD is being ignored, then an implementation may leave the disposition unchanged or reset it to the default; Linux does the former. Therefore, setting `SIG_IGN' for `SIGINT' before the fork/execve results in ignoring the signals in the child, which is unexpected as a user of `system(3)'. The solution would be to restore `SIG_DFL' before `execve(2)' if before the call to `system*' the action was not `SIG_IGN'. In the mean time, I have a solution that works for single-threaded application: --8<---------------cut here---------------start------------->8--- (define (system* . args) (let ((handler+flags (sigaction SIGINT))) (dynamic-wind (lambda () (sigaction SIGINT SIG_IGN)) (lambda () (let ((cpid (primitive-fork))) (if (zero? cpid) (catch #t (lambda () (sigaction SIGINT SIG_DFL) (apply execlp (car args) args)) (lambda _ (primitive-exit EXIT_FAILURE))) (waitpid cpid)))) (lambda () (sigaction SIGINT (car handler+flags) (cdr handler+flags)))))) --8<---------------cut here---------------end--------------->8--- Thanks, Olivier -- Olivier Dion oldiob.ca ------------=_1729450742-28747-1--