From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,XM_LIGHT_HEAVY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25801 invoked from network); 10 Apr 2022 15:46:44 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Apr 2022 15:46:44 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649605604; b=A4Gaq0YJEkAuoreETsb16Uw9LfkVmQkwSLPL6RTapjBSbUNWd0lMCOi9aSVUJlkWEtFWw3QKga uCpKFeDhud+qEHv5bRpQhqAITRxaRD48m3d0/4VYbmIZR0KBzDlffeBRn+1cJ4Mv0Ly5N2IZkW XFt7uKKz1kxVwrbbY9r1uZLHzjV/sioIASDvrV4QqBqPxX0+6FZD0rjyju9SPmMB63qLWoVwW0 Dyv1pVVDwOSAgZb4Q1S5LZaO1MWSYi0WD2Vr4cPfXaFgnBUH0HaONa8YzlBwkadtiocn4Xz3Sp t2242/poRB4fiDWK58MlEJBRv7yQGJ6cpZHirqWoMgxwAQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (so254-31.mailgun.net) smtp.remote-ip=198.61.254.31; dkim=pass header.d=klanderman.net header.s=mg header.a=rsa-sha256; dmarc=none header.from=klanderman.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1649605604; bh=iGtcnMUGk+gfxWL6kT1PUX5l3/cfAjmlxitBlyH4XnM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Reply-To:Subject:To:From:Date:Message-ID: Content-Transfer-Encoding:Content-Type:MIME-Version:DKIM-Signature: DKIM-Signature; b=grU5+4hrPCxsPIf/ejfivT7Xtw7Fi3HIauMjZxmeT9z5WBSGT7Wa6xvf9BuqR5KZAcGcLBQnBu lFZug9PiVHXrTNSOkRBxzGR0dOcb0pp5FpwxJT9pcgDSSsJTtFUkFN9qy4EL0ubru/e7IgfKYB 3YD1o4pp/tilzFMLw4PI9daVI1E2QRgJdJQdxj0IOh/qOyQ36yOsQ7G44AlPqv1hr005EIMInT S2+TE1zvdXGt7fk1Ytg+h/m08Ms5DF7jWiPFLyCdcTelN72t/DfIyoyPdUu4gVFJU46vhGHKPE kNwvCzjkP08XtfWOIM+2NHSuTnpn3RNLpSirJUkZNjStoA==; 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:Reply-To:Subject:To:From:Date: Message-ID:Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=QrY8+VyocUzoEe7fQNGMD8ZMQuTLPbWsL5AeWDrzM4w=; b=Cu+CZYSv35YW7Qdt6DFM3phuVX sEZ8EHDrgEHN81nyE3p1LcHpUayipvYy89zXKtYW54NB59ZbrjSIrb0h1dSRDrp/fcKN+Wyrx/NG1 4+//Gy8O0SoVSgct1CRXggYufXbTIkSkM8Xe6nauTtyeIVWScE5fzl+Nhu3zZ5U3t6XxMF9X6YrV+ fmk3W+bms3Mlob/rbEMYJeMmpRxGbXBPRGvlhVsMmraKJ6sKDbge83enHKG9eHdveQh4NoONTBfHS Zs4sGBEkJeOZ95ZA4uZJiIkS+D6NYxoe07CZuZDVRqNCrmdpVSlwC+iWDVD0dv3AGOkZdi5359PC6 dsYXDz+A==; Received: from authenticated user by zero.zsh.org with local id 1ndZlz-000B6x-95; Sun, 10 Apr 2022 15:46:43 +0000 Authentication-Results: zsh.org; iprev=pass (so254-31.mailgun.net) smtp.remote-ip=198.61.254.31; dkim=pass header.d=klanderman.net header.s=mg header.a=rsa-sha256; dmarc=none header.from=klanderman.net; arc=none Received: from so254-31.mailgun.net ([198.61.254.31]:51930) by zero.zsh.org with utf8esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ndZlj-000Amm-I9; Sun, 10 Apr 2022 15:46:28 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=klanderman.net; q=dns/txt; s=mg; t=1649605587; h=Reply-To: Subject: Subject: To: To: From: From: Date: Message-ID: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender: Sender; bh=QrY8+VyocUzoEe7fQNGMD8ZMQuTLPbWsL5AeWDrzM4w=; b=WetN6GjKSpgKn73a5AhwbEGlzQI6z8MZ6qkC4PyYHJuYb9tpijbbPUjCru3FH6ooO3LLB3DK HoWzKUgsH+Rbr1TIt0NxLFWOQAwflGU9IQPObOuwZnIK1s0VnJgkfUATs897D4L4OM/zjucx GtXtiMaZlJd4bG/UazUghYWryNk= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyIwZjNkNyIsICJ6c2gtd29ya2Vyc0B6c2gub3JnIiwgIjk3ZGJkOCJd Received: from smtp2.klanderman.net (smtp2.klanderman.net [142.93.10.110]) by smtp-out-n04.prod.us-east-1.postgun.com with SMTP id 6252fbd138a4f8e57d0faa96 (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Sun, 10 Apr 2022 15:46:25 GMT Received: from lwm.klanderman.net (pool-72-93-77-73.bstnma.fios.verizon.net [72.93.77.73]) by smtp2.klanderman.net (Postfix) with ESMTPSA id 8C75A40E08; Sun, 10 Apr 2022 11:46:25 -0400 (EDT) Received: by lwm.klanderman.net (Postfix, from userid 1000) id 597B429E0094; Sun, 10 Apr 2022 11:46:25 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <25170.64465.301441.247673@lwm.klanderman.net> Date: Sun, 10 Apr 2022 11:46:25 -0400 From: Greg Klanderman To: Zsh list Subject: using trap function to cleanup and exit? Reply-To: Greg Klanderman X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid (x86_64-unknown-linux) X-Seq: 50022 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Hi, I've been trying to ensure some cleanup is done when a script I'm writing exits, whether normally, with an error, or when killed (other than with -9, of course). I had thought a try/always block would handle signals as well, but it appears not. So I've been trying to use either trap functions or the trap builtin (list traps) with no success. [zsh below is debian/5.8.1-1 (Debian testing)] Here's a simple test script (the sleep has been substituted for an external command that waits on a condition and outputs something; my actual use case also has that within a loop): When run, it immediately prints: | in foo | in do_something then when hit with SIGTERM: | in TRAPTERM | cleanup however, the process and its child (sleep) remain running. I expected both to exit. Additionally, when I hit it with some other signal (SIGINT), the script does get killed, however, the child sleep process remains. Is that expected? I tried TRAPEXIT as well, both at top level and within the function foo, but that seems not to handle signals. How can I ensure that a script and non-disowned children are killed when a signal is received, after doing some cleanup? Is there a way to do that for all appropriate signals, or do I have to explicitly list the desired signals? thank you, Greg