Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
Date: Sat, 16 Apr 2016 12:13:21 -0700
From: frederik@ofb.net
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: exec redirect prevents trap
Message-ID: <20160416191321.GA13911@ofb.net>
Reply-To: frederik@ofb.net
References: <20160416075941.GA27994@ofb.net>
 <160416093433.ZM24261@torch.brasslantern.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <160416093433.ZM24261@torch.brasslantern.com>
User-Agent: Mutt/1.5.24 (2015-08-30)
Sender:  <frederik@ofb.net>
X-Seq: zsh-workers 38293

On Sat, Apr 16, 2016 at 09:34:33AM -0700, Bart Schaefer wrote:
> On Apr 16, 12:59am, frederik@ofb.net wrote:
> }
> }     #!/bin/zsh
> }     exec > >(tee -a /tmp/foo)
> }     trap "echo hi" INT TERM EXIT
> }     sleep 1d;
> } 
> } When I run it and hit ^C, it doesn't print anything. But when I remove
> } the "exec" line and do the same, it prints "hi".
> 
> I suspect what you have here is a race condition.  When zsh exits,
> it first sends a HUP signal to all its children, including the tee
> process.  If tee dies before the exit trap runs, the "hi" will go
> nowhere.
> 
> Try one of these:
> 
>     exec > >(trap '' HUP; tee -a /tmp/foo)
> 
>     exec > >(tee -a /tmp/foo &! )
> 

The second one works, thank you. Not sure why the first one doesn't
work for me...

In my script, I had something like:

    trap "echo hi; rm -f bar" INT TERM EXIT

and I noticed that 'bar' wasn't getting removed. But changing it to

    trap "rm -f bar; echo hi" INT TERM EXIT

works, so I guess that must also have been a problem with 'tee'
exiting.

My apologies, I guess this was more of a zsh-users question...

Thank you,

Frederick

