From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion Newsgroups: gmane.lisp.guile.bugs Subject: bug#73589: 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 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17053"; mail-complaints-to="usenet@ciao.gmane.io" To: 73589@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Tue Oct 01 22:52:25 2024 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 1svjr5-0004Cb-6h for guile-bugs@m.gmane-mx.org; Tue, 01 Oct 2024 22:52:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svjqm-00009q-Cw; Tue, 01 Oct 2024 16:52:04 -0400 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 1svjql-00009e-1d for bug-guile@gnu.org; Tue, 01 Oct 2024 16:52:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svjqk-0001jx-Hl for bug-guile@gnu.org; Tue, 01 Oct 2024 16:52:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=qCFhgJd/+pjkGA3Yt/FheGwp6mKcBQ0jNhpbydPK5xc=; b=SeZrDcZixwPahyFExOS4VF3TXSF/gigppKeXjg56Ko6ZFJjeS31tZ/nl+JT4IdhFaOcJi4byhkZJ7VYvzKE5/61rFhoQgTtYCeZ7WC2bdvh3eO7+jXbugIzv4PwdXfKTSmKNd9nWsKhw225FZbOkzwv7AAL34HPvDvJCE1RMOMX/wWXI21mQ855Dd8LrKsMhxc/dAGZHvVkplqaOegsKQeTxsRUeOOE4FwW9Rbqeo0T70SQ7folPB4FtPdQMQT5sZUfIKpA8NCAnOqn9V30rCmpSbabneTnHeOZqzSWAiXjFfC5bg+RSlF6mhQYHe3jj8SrlcvLU+ro3F8qgX5HV4w==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svjqj-0002D8-U7 for bug-guile@gnu.org; Tue, 01 Oct 2024 16:52:01 -0400 X-Loop: help-debbugs@gnu.org 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-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17278158788446 (code B ref -1); Tue, 01 Oct 2024 20:52:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Oct 2024 20:51:18 +0000 Original-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 Original-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 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 1svjpy-0008JB-9D for bug-guile@gnu.org; Tue, 01 Oct 2024 16:51:14 -0400 Original-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 Original-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 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-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:11001 Archived-At: 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