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 322E223D25 for ; Tue, 23 Apr 2024 19:34:13 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713893653; b=fIyJnalEb43h29ejr4hjGpur3Sep44HNb1bM5Pq3DYpL0t37Yrdu4juTaKyOrJqLwYvAwIdtcI xKEWR03hHq3J51HVEnt/cFr9nUQPk09v8CLVeKsz3jT3ygu5IFNi05WqpSqnpRkilPHMOZiFTn Z5mmi1Gx4hSsnExjEbnZg4Utz0mP0hzsHG2Bis4V6sd8aRdyBeRlR+Y3GT4A+6Jwb0upZJ4eMY OyXtq31oRxMWZtxoyUFsjemBE55dQbsQ8S5fSKVo+qBLhv4txRXFUvwVUiMF5NLKFUBgv/jhDh njPuriOAo4A8RL7hX59Cyf8wp3LkpaxLxsT95fG9cXkX3g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713893653; bh=NA253iHKRirX0tTsQzpC4qE0V0nmTY/eNExZuggEApY=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ALpqVKtzFhaL9SXuBZmkzDdBuBut4ImrhzcjFeayuCx3Dcy2sAElXTdnXxYdO2Qbe32+CvgRx0 lnalBqFBZIOwRrDd0TZYN0NvI7RpbCSl1JtDRulZYgpV4JLOFvHv7AHmGHa5VDnKE0jUOIU4mZ WHfRIVV3KgYfuFsiH2cCbwM7INmHXV8V0+kcqekEYpPcs+QgPR0jUsA6n2gaptnHG8WmHD8CRH e44dgTPjsLgb2zHyMLr+Wx+PBEnL5q3fQU7iU+9HBAFpT4pQHrU19LkSsTRCYEl6oPH9S5Hqzs TeDixM34fVKqGLPmDiKoPqL2fFqTzOsQWXm3Sh9dXLDQlA==; 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:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=vjr10MENu06BW0j3F/N43XZwuvmIoOaJldUwiJyB6Sg=; b=mXgLPRz8jzsbzdIRBT87j7gTPP ekq7nede1jcQ99ex3wih66NYySKqL+U0qHuO6a4K3j/2heGLr/2PpeyNTpA540BLhOjfjxxxE26Lr x0GCfYzhtg1p01DpTq2ecj9PlJ3GRQ57ra5En6LgWXrRcyQdekoePhppSha9UIZzRh1DHJHjgz4NN 6hT0eZngf1vBrHZveX+SE51uJSO7P3KcrGc8966H2EeLQTe2hmBxnlS4fspOfzsJ9mjzCQjcPdaLD bkHsDiCdwbDvEQdnlbmREpMQPAP67vj2MugNgJiNchBsW20wAHtq5pDZMOMPMmgjg1b7S2Eqk/x1Z Di5Q47YQ==; Received: by zero.zsh.org with local id 1rzK21-0001sB-AH; Tue, 23 Apr 2024 17:34:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f49.google.com ([209.85.208.49]:43042) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rzK09-0000vd-Kx; Tue, 23 Apr 2024 17:32:21 +0000 Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-56e78970853so155093a12.0 for ; Tue, 23 Apr 2024 10:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1713893537; x=1714498337; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vjr10MENu06BW0j3F/N43XZwuvmIoOaJldUwiJyB6Sg=; b=Pr5NKMNDF7tmap1iUB46AnSyQnB1leu/jy7E70s4v/PQd4YUTllKJycxFcMCNZuUd8 dhrAEn01AZz/JYMnmMOB32iJhcd16WLRT61snqS2ejkMerTM84qF86Jsfah+lsEKtVxD /b3ybODsF2cEme++7DevqMpLh5kjtbKYRQvWfRwRBnYwm8lES4XB64480G5QsgWmjoFW fe9g3V/pQzXwasmSXq+86u5T7JtVx0clgphmvTkYJuepZDQYBy5uDqq0ZyHZ5QNjL7ir 5xCZg7c4hd/dftECF1PjQ2wceMzEXv6PnN+/u6yl/6ueQPSSWy9d5kksPe9/uyT+gX9v bZ/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713893537; x=1714498337; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vjr10MENu06BW0j3F/N43XZwuvmIoOaJldUwiJyB6Sg=; b=w2eysGvH4r6jl77pUudo+tnZrcT00AiXxKNcTiVysnJi2yRUvGNpfSF/4MfiR5Gyn+ 3XAX3juPBqPadI6bJYNiyqzxjs1Uq0zoJBB5C9zIbOvV5mLMnEQwhvvxnPb4IwrDMx6Z QPvUmfdwMJoVFVeMUO4hvsfAIXXyMrjMsRT1YDlPzrQo2btHLOnzGBzhF50w7fZGY6M/ wvowijNXggVvVaznDzynJ2YkYDSJ83ul/a6CoTRMPa78mQcwYx7UQOmp3Rw/+QH3MhBS GYtyvZO/TEPMoBYGueieS+iZ7gvrTMU3D35v+28eDNqgcJZdFBLn6+uSDZEybIBQ7NNw Yavg== X-Gm-Message-State: AOJu0YxczMc+o1cOdpt4ZJu6Un/pR9cfCM4kIu7p1ezhtG8ywyAPDhf8 0zqlrA3nMCKZxw41/yT7ZNM9eAke+CHUhFUDTIbFi+DE+QFxHXohEoNNkquh43LzFdC/YFL/Cb+ DntFblaYsMnesv7I297nLTdIevB8pOMA35uaJCXXtG3aHXhp4yA== X-Google-Smtp-Source: AGHT+IFJZkK/4Wlx8C6Esaaa7jeKo79w4VkfbNmGA3S4cGK8FdJKGV+81vow1MoTBtiA0gwu5cry6SoNTMfm/dBjnNA= X-Received: by 2002:a17:907:9450:b0:a55:77fa:80d7 with SMTP id dl16-20020a170907945000b00a5577fa80d7mr4520245ejc.8.1713893536372; Tue, 23 Apr 2024 10:32:16 -0700 (PDT) MIME-Version: 1.0 References: <20240419190027.GA109916@joooj.vinc17.net> <20240419213225.GA146837@qaa.vinc17.org> <20240421172909.GB146837@qaa.vinc17.org> <20240421174358.GC146837@qaa.vinc17.org> <20240421235909.GD146837@qaa.vinc17.org> <20240423151717.GA82287@qaa.vinc17.org> In-Reply-To: <20240423151717.GA82287@qaa.vinc17.org> From: Bart Schaefer Date: Tue, 23 Apr 2024 10:32:05 -0700 Message-ID: Subject: Re: How to propagate SIGTERM to the foreground job, if any? To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29860 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 Tue, Apr 23, 2024 at 8:17=E2=80=AFAM Vincent Lefevre wrote: > > I think that I should start to test with something simpler, with > a command like > > unison -sshcmd ~/scripts/ssh ~/testdir ssh://remote_host/testdir I would wish for a test with something simpler than unison as the driver, but ... > For ~/scripts/ssh, the following works with I type Ctrl-C > when ssh-add asks for the passphrase: If you mean running scripts/ssh from an interactive shell, I'd expect ^C to work even without the trap, because the terminal driver will deliver the INT to ssh-add before (or effectively simultaneously with) zsh. > But %1 might not be the right job in more complex cases. > BTW, I'm wondering why %1 works, but not %%. As I said before, %% is the same as %+ which is the most recent background job. There's no shortcut to the foreground job because zsh assumes that a foreground process will get job control signals directly from the terminal driver -- invoking job control from a signal trap that bypasses the foreground process was never considered in the design. > Moreover "term" is output twice. Why? I believe what's happening is this: When you "kill %1" the job exits with status 143, which indicates it received a TERM signal. When zsh gets the SIGCHLD and sees the exit status, it interprets this as meaning it should also handle the TERM signal. > But these solutions do not work when ssh-add is in a zsh function I think that's because using a function wrapper causes the function itself to be come a subshell that has its own copy of the trap. Within the subshell, there is no $e (copied from $! only in the parent) so the trap doesn't work. What happens if you "exec ssh-add" in the function instead of just calling it? > On 2024-04-21 17:41:38 -0700, Bart Schaefer wrote: > > Try this: > > trap 'setopt MONITOR HUP NOCHECKJOBS; exit' TERM > > This doesn't work at all with the above test. Hm, unison may be blocking the HUP signal as well. Try adding trap - HUP to the script to restore default behavior in the children.