From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28539 invoked by alias); 30 Jun 2017 11:50:07 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41378 Received: (qmail 1955 invoked from network); 30 Jun 2017 11:50:07 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f45.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.45):SA:0(-0.0/5.0):. Processed in 0.819999 secs); 30 Jun 2017 11:50:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: layus.on@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 74.125.82.45 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=ybfE/a7rfrvTrxnfCOE2YoTDXhGE+5CZyya+B1hXd0c=; b=t45/mgs6UcqsRbU77kTNnr1c9Jczmkd8Cq1D9Fb5R7e0suP4N5LgvLQ4huooRUW0ol hNbK8mmCKmJNaVx2IuXl+b0UXfkSLL0EKSLWGMdypiWW90ps9mkaQ87JgYYUe4EzpNoo saXqOCISgoa4e8fRPoXHFOpeaJvdATdlVOY93rx5VfVAxsdu7ta3lAo58lfv0MiJsHbg gwMQDyh+WdsmLW4F5DHDUdpSsuZjTAHt9pmRs/LyerVfvFnQRZe0Uusz6to5P+pxYCqs d19txsqMVAl8dIzKCZ8SrFkoaNl0c+10G8WkyUh8Z7fm7AjObiytEj9qJo4XCOHS40D/ MT2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ybfE/a7rfrvTrxnfCOE2YoTDXhGE+5CZyya+B1hXd0c=; b=dp0KD1hmyD589hxlB/+iHNqTzTt7toh4WwFt5BE/ElTj753sbhvPkQ5LKq2Wkd5kZa 1sdCecB/hw/X00q1HmkoRNzAHz3fK16hbjWi4mTkvScM+cFF6GLuksDMUSgVkq5XmODa kHR/Mfpn/AXlheTQcTDSts6oDzkqT2CFtrAfGUU8B1x8uD6mWNy/8X3yKm6t2HsYXAYU xJQOAAuWWxH7B+LUNTY220Cg1DOgvf0AdTs12d3FLRrcprmh88vCPmtc2B2dlsngbw/e UGYstm7pbp2wEtxhVe5iAKggqx4i3czkC2T/TSiY02lw0+UamJkM8laOVYMJSthC1dry iHyA== X-Gm-Message-State: AKS2vOz2BRTJdVauWIaNHSYTiGLyzWpq/vGdUORocfFPKQzLZk1L/8Z6 j40jucG3DL3avIw/ X-Received: by 10.28.134.79 with SMTP id i76mr5325250wmd.108.1498823398307; Fri, 30 Jun 2017 04:49:58 -0700 (PDT) Subject: Re: Race condition when setting TERM{,INFO{,_DIRS}} To: Bart Schaefer , zsh-workers@zsh.org References: <2ad57c3b-f0c4-afd9-4789-ae50571c63e1@gmail.com> <170627143044.ZM8536@torch.brasslantern.com> From: "Guillaume Maudoux (Layus)" Message-ID: <45762363-3882-27b8-8433-63ccfdc0b8be@gmail.com> Date: Fri, 30 Jun 2017 13:49:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <170627143044.ZM8536@torch.brasslantern.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US 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?