From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 7034B21726 for ; Mon, 22 Apr 2024 02:00:02 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713744002; b=Pvs3bCa5dOxpwWTGmQp8RvGISW2VvamR21Hga0socjAkSkYtjmvPLLZec4icKhP6+f8zBCJFkk PPLC5HiiDeKnAfj1cCU+If4yqiZ5jLK/gdn3IhAD6Ke84VYlRMtMfkz7gag7cAmGGlAOI40Zqq ahRfkJ58cfmCE9skkp0beXqiF7Y4zGKAnrwV68zYEFqcFlnl47bgxWIhRtaWmISvhmP8XmTol8 DIk5eX0dmqaTFErtd9WGvbnIah5+YmztXJ8j8cT9xhJ3qcODfyDOD8vogSg6qL4o7tb0sIk/CM pMe7Ni6jDD4e5Gp7/GL8s5IbJffUa2dgLOLF3srrS+vTmw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713744002; bh=JsJfwpGsbOx6/Cyh92OfR4/Pu4Ri9d+WJQYbA4ZQAh0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=X5ncwkCkhKcZ3/WRV69/9Kcm6PQ2bDdS3XnLsnIuQTAGkxAUSYhhdX4CiXRpNbgRfPdTlHkQUa rEPUsWlcca63pZN7y0InjniVUkFeWsVVYe8YbHuPM3ZhOp2mrvYnOhJZBGrKgu2zBu5a+UUngw /XU8V04BMxkdZVI+bt5nvdbBL5HgYeOTuxTa+CpaF8ONNz5qYQJbgTRHka8GhNhIo1JYmTSf4v lgN5X6jyXqPQslmOFcUjDx3B7RYUrPKmEEMrW8mjq8eRPRwtI0yMhxLhRNoowU+Oibivc6xD9i A378EcqR0FJ0rNzPAyOraCVw6+aT7OIE7y2BMzf3lOG/UA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lfJANl2DKc8ao7mWzqDizHv44m6FsBcwrpQ2v9lLVhQ=; b=CojaYH7cofXQGlfKNG+YGaB6pQ OZprPB2aZM+m1oaJ15VVg9oWzRvzd2A9ThN3g20jDyXmOY7Garo3vtxMcJl/iOb06e8VuALLOhePE XRVpeCXCyzarzTh7uDOTzDe8/hR74ipmre/8xhjiqmHMvJKuR34qbsSIhJ/YKf6PWL22C2qV3xr9l i0/5y370h+lpIHBeqN8zcdK5i9qAGIknStt0vSEiL9ycQ2lnMvq+8KSIyX7IWeOG73X1Z8C3zKQnn p/aOioMwYHXERLg3vLh4i2ASl6s3PXcf6sXMNJtVBUl/KN8OW6VQLIBfGn3PxLSQpWhoZ0WujJDDW 3mMfXmNg==; Received: by zero.zsh.org with local id 1ryh6I-000DTr-DI; Mon, 22 Apr 2024 00:00:02 +0000 Authentication-Results: zsh.org; iprev=pass (joooj.vinc17.net) smtp.remote-ip=155.133.131.76; dmarc=none header.from=vinc17.net; arc=none Received: from joooj.vinc17.net ([155.133.131.76]:42050) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ryh5S-000CkA-B9; Sun, 21 Apr 2024 23:59:11 +0000 Received: from smtp-qaa.vinc17.net (2a02-8428-1b1d-4d01-96a9-491d-7b48-ba31.rev.sfr.net [IPv6:2a02:8428:1b1d:4d01:96a9:491d:7b48:ba31]) by joooj.vinc17.net (Postfix) with ESMTPSA id C73BA43B; Mon, 22 Apr 2024 01:59:09 +0200 (CEST) Received: by qaa.vinc17.org (Postfix, from userid 1000) id 77F61CA011A; Mon, 22 Apr 2024 01:59:09 +0200 (CEST) Date: Mon, 22 Apr 2024 01:59:09 +0200 From: Vincent Lefevre To: zsh-users@zsh.org Subject: Re: How to propagate SIGTERM to the foreground job, if any? Message-ID: <20240421235909.GD146837@qaa.vinc17.org> Mail-Followup-To: zsh-users@zsh.org References: <20240419171752.GA48158@cventin.lip.ens-lyon.fr> <20240419190027.GA109916@joooj.vinc17.net> <20240419213225.GA146837@qaa.vinc17.org> <20240421172909.GB146837@qaa.vinc17.org> <20240421174358.GC146837@qaa.vinc17.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.12+69 (354c5b11) vl-149028 (2023-12-10) X-Seq: 29857 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On 2024-04-21 14:25:31 -0700, Bart Schaefer wrote: > On Sun, Apr 21, 2024 at 10:44 AM Vincent Lefevre wrote: > > > > > xterm was just a very simple example. In practice, several commands > > > are involved, and among them, there are zsh functions that may need > > > to affect the environment. > > This seems to work: > > trap 'kill -TERM -$$ ; exit' TERM No, this was basically one of the first things I had tried. But this assumes that the shell script is the process group leader, and in my case, it isn't (see below). > > Moreover, a Ctrl-C in the terminal doesn't seem to be handled > > correctly > > Which terminal? The terminal where the script is running. One of the use cases (which is causing the problem) is that I have a GNU Screen session running Mutt, and from Mutt I execute a script, which executes unison, which needs to execute ssh. But instead of ssh, it executes a zsh script, which does various things before executing the real ssh; in particular, it may execute ssh-add (via a zsh function). The process group leader is the mutt process. I use the same mechanism with Subversion and Git (which may need ssh), and when I type Ctrl-C, this kills what needs to be killed, as expected. But here, the issue is that unison blocks SIGINT for its child (ssh, which, in my case, is the wrapper script) so that it can do some cleanup on the remote side before ssh is terminated. After the cleanup, unison sends a SIGTERM to its child. But this means that only the script is killed. If a ssh-add was running, asking for a passphrase, then keys typed in the terminal are sent to either Mutt or ssh-add, more or less randomly, while I would expect ssh-add to be terminated. I also found a few days ago that a similar issue occurred due to a possible timeout in unison, e.g. if I wait too long before typing the passphrase (so, even if SIGINT were not blocked, there would still be an issue with the possible timeout). You can see additional details in the bug I had reported several months ago: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1052451 but after some reflection and finding the issue with the timeout, I think that the real bug is in my script, which should kill the current job and itself when receiving SIGTERM. > > (here, ssh-add with several files in argument is executed > > via zsh functions, but it refuses to quit on Ctrl-C). > > Does this mean you can't interrupt it while it's prompting for a > passphrase? I don't know what happens exactly. Normally (e.g. when run from the command line), both SIGINT and SIGTERM terminates it. > Can you reproduce this with something other than ssh-add ? Your script with xterm is fine. But if I replace "xterm &" by ssh-add file1 file2 file3 & I get ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory errors. It seems that ssh-add doesn't like to be backgrounded. ssh-add in foreground doesn't have any issue, but of course, this script no longer works as wanted. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)