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.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_PCNT
	autolearn=no autolearn_force=no version=3.4.0
Date: Fri, 22 Jan 2016 02:42:29 +0100
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: prompt update and TRAPCHLD
Message-ID: <20160122014229.GB26912@zira.vinc17.org>
Mail-Followup-To: zsh-workers@zsh.org
References: <20160114171631.GC12351@cventin.lip.ens-lyon.fr>
 <160114185941.ZM18307@torch.brasslantern.com>
 <20160121135120.GC21104@cventin.lip.ens-lyon.fr>
 <160121111355.ZM25640@torch.brasslantern.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <160121111355.ZM25640@torch.brasslantern.com>
X-Mailer-Info: https://www.vinc17.net/mutt/
User-Agent: Mutt/1.5.24-6551-vl-r83103 (2016-01-05)
X-Seq: zsh-workers 37728

On 2016-01-21 11:13:55 -0800, Bart Schaefer wrote:
> The rule actually is that traps are executed as early as it is "safe" to
> do so (memory management, etc.), and one of those times is immediately
> before another command is going to be run; so the trap could execute for
> example at any time during your precmd function, or during zle-line-init,
> etc.
> 
> So in that sense yes, there is a race condition.

The following code solves it:

updprompt()
{
  unset _trapchld_called
  [...]
  [[ -n $_trapchld_called ]] && updprompt
}

TRAPCHLD()
{
  if [[ -o interactive && -n $TTY ]] then
    {
      updprompt
      typeset -g _trapchld_called=1
    }
  fi
}

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

