zsh-workers
 help / color / mirror / code / Atom feed
From: "Guillaume Maudoux (Layus)" <layus.on@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: Race condition when setting TERM{,INFO{,_DIRS}}
Date: Fri, 30 Jun 2017 13:49:56 +0200	[thread overview]
Message-ID: <45762363-3882-27b8-8433-63ccfdc0b8be@gmail.com> (raw)
In-Reply-To: <170627143044.ZM8536@torch.brasslantern.com>

Thanks Bart,

I have found the origin of this issue.
There are no threads indeed, but there is caching in ncurses for 
environment variables.

Due to a bug in ncurses' code, it failed to detect that the environment 
var changed,
and so failed to find the terminfo database.

I will send a patch upstream, with this list in cc.

Zsh could avoid that by initializing the term as late as possible.
Calling init_term before parsing zshrc, while nothing required to write 
in the terminal is premature.
Fish for example delays initializing the terminal until the first write.
Well, this would have avoided my issue, but it is not sufficient in the 
general case anyway.

Thanks again for your answer!

Regards,

-- Layus.


On 27/06/17 23:30, Bart Schaefer wrote:
> On Jun 27,  3:52pm, Guillaume Maudoux (Layus) wrote:
> }
> } In my case, when TERMINFO_DIRS is set from /etc/zshenv, the new value is
> } ignored by ncurses.
> } The same applies to the subsequent TERM=$TERM in /etc/zshenv.
>
> What does "the same" mean here?
>
> } However, if I add a delay before TERM=$TERM, then the TERMINFO_DIRS
> } update is seen, and the terminal is properly detected.
> }
> } Could it be that there are threads involved in zsh ?
>
> There aren't threads, but there are signal handlers.  We've had issues
> before where certain terminal emulators will fire signals at the process
> they are controlling at, shall we say, inopportune times.
>
> However, the most common culprit would be the WINCH (window size change)
> signal, which we block before reading init scripts and don't unblock
> until ZLE is started up.  And I don't know why ncurses would be doing
> anything at all during /etc/zshenv, except via init_term() from those
> assignments if ncurses is what provides tgetent().
>
> Normally init_term() is called when setupvals() imports TERM from the
> environment, which happens before zshenv is read.  This would also be
> the case for import of TERMINFO_DIRS, although if that happens before
> TERM has been imported, init_term() will do nothing.
>
> One thing I have noticed is that if TERMINFO_DIRS is in the environment
> when the shell first starts up, tgetent() looks *only* there for $TERM.
> Conversely if the shell starts and then TERMINFO_DIRS is assigned later,
> the default definitions are also consulted.  I don't know if that means
> that TERMINFO_DIRS is ignored when a default has already been loaded.
> This might differ in various tgetent() implementations.
>
> Also, the "can't find terminal definition for ..." message is suppressed
> during import from the environment.
>
> If TERM is not in the environment
>
> Aside: Does it matter that terminfodirssetfn() does not check (x == 0)
> except before adding to the environment?


  reply	other threads:[~2017-06-30 11:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 13:52 Guillaume Maudoux (Layus)
2017-06-27 21:30 ` Bart Schaefer
2017-06-30 11:49   ` Guillaume Maudoux (Layus) [this message]
2017-06-30 12:05     ` getenv() caching bug Guillaume Maudoux (Layus)
2017-06-30 17:33       ` Thomas Dickey
2017-06-30 12:34     ` Race condition when setting TERM{,INFO{,_DIRS}} Mikael Magnusson
2017-06-30 13:36       ` Guillaume Maudoux (Layus)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45762363-3882-27b8-8433-63ccfdc0b8be@gmail.com \
    --to=layus.on@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).