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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2377 invoked from network); 10 Apr 2022 20:50:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Apr 2022 20:50:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649623809; b=VasxHvFekYvD6+v7W6hfqqWet/IoJEXQh7qmNc9SeASOMZoB1Qr+EdqH3RuNfWBnHhN9Bedbr7 c4q17MRg+4lrqQlc/tfvKPcvsem6DE/Q8c1lRrAP9lPgBTuS4BbLDjxg7fdsdbCbp20v5V+V05 zYk5eYMutMEcwnQjhxrfaVehvx1MN7NCbNwRV63Zcho3SvnTCMUQ5QnAkr5r/eujqAKrDVLe4X rHe2eaTfcsXO6U++ypLipD4HxFlq9qLealpzpTz3xCv0eN3jN8I4bx5yR6qD0CxMmRuVAdWAVm fesDgZQyKgzXZX6pNkyI1iybAoEGd2yXNAkJ1YypzXABdg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1649623809; bh=GnUVCIlMREeiLLDUtaAFgo3PnvdCbYT+2NRipIx9P7s=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=TiioJY/3Q2sLyWeqACQMDKifycUfvjUiGQtHbAjzipIEk/yGw9+kzyetMa19sEyItQ8L+4Ohxa BKcXsYpRdzLRl/rWS4JZVEshdmeyoDw+rBpwe9vOGVXerTC5/3dAITFR+6+gGO7XDSE3HuGjXc IGf4ZE8LkXmNcs7jgf6zwEf/uONHLxElynlrjmZ4wOh/opgLRvM6zWsiqJmqXh77pkpmlm9dMi jd2s4CVYoc8Dt5SIcCfVN3yd1dr+S5YEwrjvpt6jAncI8DFGLTJHrRV4ZLqYe6iDhbzvusmaIn gdmFbjktjesKGe/qTwJfKj3t5kmBg0cEcDg+2HmXhK5xjg==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=jJhgDcsUztVyzEoK3l5y11id24qo0/7MauZ+SX5jIXc=; b=e3ywbm36PbZsXyb3foYkmroRqc 1TZS7NZPYdpwDzLVCEc7W0wLIAo2KSZHr83g9kmR+1hII6lr/vlB/WPHXLbxdOteM0KyH4he8VlC1 sngmnXFUL8Spq/W2+ERMgcaK/snIG2UZ2KTD4ErkE9rfqvEQURy5+JN+yhjWZ2JRmTS4BDcoBRz4b D+HdDb38XNWfcB40AG0VSS6xp3X3WH1A2nde8xB6xN3Er709NS5rjsNt43OrbowOLRnIVwXEQKT92 TpkVUBrhk62OdeHk7j9R+S3V3tplg1ds0/m+uErrZ4K34xvqNZ35k9h/NDdiw53N1uAcN5Oz+9O9T aZ/ZrpCg==; Received: from authenticated user by zero.zsh.org with local id 1ndeVb-0000Zs-KD; Sun, 10 Apr 2022 20:50:07 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f53.google.com ([209.85.218.53]:46849) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ndeUz-0000GP-9J; Sun, 10 Apr 2022 20:49:30 +0000 Received: by mail-ej1-f53.google.com with SMTP id t11so149726eju.13 for ; Sun, 10 Apr 2022 13:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jJhgDcsUztVyzEoK3l5y11id24qo0/7MauZ+SX5jIXc=; b=nqNjNBVDm2gfYVQEpItUiZx2aRmG4ZuC1dIYMGVw3qteZsFD9MVvZT6P0MnZXFl+Sd B0ujBOPmwICNG/y5VfpfakPJFLps9hamAqGQhcxwJPQHeEsaptYTE6TLohIoTSYUuSXO WrtVxR8EuRw0JWIBxo0CRx/t7hYXWbGrBSoVsxPyh17xJytdknb/9DgiY6dz+wj4yv8s 7M7OO4k8TMAD/tc4qEjZee2iXgxR/iTRbRWaNHE3FFAYrKZN+CLX8RuK1XaancwNfSJX 88gxjIhUDlvuhTOAeHiq0MvOISIfChAzaQ/WH3EnkyK7Ju42aG6kwNO3HVeYsgyH1z1B E0Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jJhgDcsUztVyzEoK3l5y11id24qo0/7MauZ+SX5jIXc=; b=bVNYc33U6zXOFoYsW+zF0b3sO1lsfj2DIDeHmRAdfxcHFFCxClh1l5DjWC8Z7wYnj6 SUIFBe3S2p2RT/pooyi/pg6KHGensAsH+s776zOIM82lLqKbLDqLGDiqfz7yBe4LRp1A 7oOjLGBl5f3SgENqU00uBY+AStNxLXp/LATBXX6UFpepNnr4Z/J/m2bId3JfxfuzJFLf j/hXy3l10aKMeQ1XjluCMlVSAwGdn9gYLeQgyrgfVf1pcLVuYxpYNbIc/bb9IaYyNIfv DecCdHf47VHM98WLGSjZkz4jbRgPxelphYMTuXmgYSmRaiBJZGiwoKL6q6U57okulDc1 XVAw== X-Gm-Message-State: AOAM5333oDMYzIiJqmUeWYnsQ7VVuYEtjyOZ2Y3RT8E5M7chvTCOcPAl E1CyasxL5Bgg6USlDfYKQn4T4wYh9QzAQZHE6xlTatKlpOWgfeXT X-Google-Smtp-Source: ABdhPJxu4YWIDjhXQjJ3TDVmm7dEFztNRcfHJCinyyLTiGnj/qKPI4lXGyEOZjo682Q4rAfhGXYG2Tdl2HOw2GCZ9BM= X-Received: by 2002:a17:907:62a1:b0:6da:7952:d4d2 with SMTP id nd33-20020a17090762a100b006da7952d4d2mr26879402ejc.260.1649623768768; Sun, 10 Apr 2022 13:49:28 -0700 (PDT) MIME-Version: 1.0 References: <25170.64465.301441.247673@lwm.klanderman.net> <87fsmk2a03.fsf@lwm.klanderman.net> <87czho2967.fsf@lwm.klanderman.net> In-Reply-To: <87czho2967.fsf@lwm.klanderman.net> From: Bart Schaefer Date: Sun, 10 Apr 2022 13:49:17 -0700 Message-ID: Subject: Re: using trap function to cleanup and exit? To: Greg Klanderman Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 50029 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: On Sun, Apr 10, 2022 at 9:30 AM Greg Klanderman wrote: > > I've tried both exit and return in a list trap, and am not seeing the > script exit. The rules for traps and child processes are a bit hard to follow. If a signal trap is set to something other than the default in the parent, then that signal is supposed to be blocked in the child, which means the signal won't be propagated from the parent to the child. The following options also control signaling behavior: MONITOR - off by default in scripts, and when off, causes background jobs to be left running when the shell exits. POSIX_JOBS - off by default in native mode, when on forces MONITOR off in subshells HUP - on by default, and if MONITOR is also set, causes child processes to be sent a SIGHUP when the parent exits TRAPS_ASYNC - off by default, when on the parent handles signals immediately, otherwise foreground children must exit first POSIX_TRAPS - off in native mode, modifies the behavior of the EXIT trap (on in sh/bash/ksh emulations) LOCAL_TRAPS - off in native mode, saves trap state on function entry and restores on function return > Also, is exit intentionally disabled from within a trap function? No; there was a bugfix for a related thing in 5.6.1 and a couple of other exit-from-a-trap tweaks involving loop structures that are pending the next release, but exit from a trap should work (and does in some simple tests I did). Do you have a simple example, and are you sure you're not seeing the effects of some of the above options? > I didn't expect that, even with the special return handling. So, > there is no way to exit 0 from a trap, since that is interpreted as > the signal having been handled, and wanting to continue executing? Again I'm not seeing this. If I exit zero from an INT trap, the exit status of the interrupted script is zero. However, if I exit from an exit trap, the status of the exit trap is ignored and I get the status from before it was called, e.g., killing a script with SIGINT always returns 130 even when TRAPEXIT calls exit with a different value. I'm not sure that's clearly documented anywhere. > With no traps of either type, should the child sleep remain after the > script is killed by a signal? See above RE signal options. Probably yes.