Subject: bug#74252: 31.0.50; multi-tty;: init_tty using getenv for COLORTERM

From: Gerd Möllmann <[email-masked]>
Date: Fri, 08 Nov 2024 11:22:18 +0100

Gerd Möllmann <[email-masked]> writes:

The following patch works perfectly for me (including daemon mode).

>From 1d729a0bdeef0534c05b5f8358b19c04a814a308 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <[email-masked]>
Date: Fri, 8 Nov 2024 11:05:58 +0100
Subject: [PATCH] multi-tty: fix wrong COLORTERM (bug#74252)

* src/term.c (init_tty): Use egetenv, not getenv, to pick up
emacsclient's environment.
---
 src/term.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/term.c b/src/term.c
index 66395ac6077..80a14fa1277 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4358,7 +4358,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
 
       tty->TN_max_colors = tgetnum ("Co");
 
-#ifdef TERMINFO
+#  ifdef TERMINFO
       {
 	const char *fg = tigetstr ("setf24");
 	const char *bg = tigetstr ("setb24");
@@ -4383,7 +4383,9 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
 	   (de-facto standard introduced by tmux) or if	requested by
 	   the COLORTERM environment variable.  */
 	else if ((tigetflag ("Tc") > 0)
-		 || ((bg = getenv ("COLORTERM")) != NULL
+		 /* Use egetenv, not getenv, here so that we pick up
+		    environment variables sent to us by emacsclient.  */
+		 || ((bg = egetenv ("COLORTERM")) != NULL
 		     && strcasecmp (bg, "truecolor") == 0))
 	  {
 	    tty->TS_set_foreground = "\033[%?%p1%{8}%<%t3%p1%d%e38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%d%;m";
-- 
2.47.0