From unknown Tue Jun 17 20:29:23 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#73589 <73589@debbugs.gnu.org> To: bug#73589 <73589@debbugs.gnu.org> Subject: Status: system* does not honor SIGINT restoration in child Reply-To: bug#73589 <73589@debbugs.gnu.org> Date: Wed, 18 Jun 2025 03:29:23 +0000 retitle 73589 system* does not honor SIGINT restoration in child reassign 73589 guile submitter 73589 Olivier Dion severity 73589 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 01 16:51:18 2024 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 From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 20 14:59:00 2024 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. From unknown Tue Jun 17 20:29:23 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 18 Nov 2024 12:24:15 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator