Date: Sun, 12 Apr 2026 13:44:10 +0000 From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 14c8e003318b - stable/14 - stand: split fg/bg handling up a little further Message-ID: <69dba1aa.439d7.4ff8b5db@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=14c8e003318b3c29f1b9a7a61092c9e3df5f2bc1 commit 14c8e003318b3c29f1b9a7a61092c9e3df5f2bc1 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2025-08-22 03:48:14 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2026-04-12 13:43:38 +0000 stand: split fg/bg handling up a little further These can be setup independently, so we should also check them and initialize each independently. This fixes a pre-existing bug where-in we may not pickup a bg color specified in the environment if a fg color wasn't set. The new version also ensures that we're hooking the color vars properly if we're using a value that was already there, as the console may need to adjust if something wants to switch them up again. Otherwise, a teken.fg_color set in loader could conceivably occur that only changes the color when you get to the kernel, which could be surprising. Reviewed by: imp (cherry picked from commit 95e6fd1fd85a448d2c68473b85a61fba24c9bc4f) --- stand/common/gfx_fb.c | 59 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/stand/common/gfx_fb.c b/stand/common/gfx_fb.c index 9aa0431a04d6..687c081a1d5d 100644 --- a/stand/common/gfx_fb.c +++ b/stand/common/gfx_fb.c @@ -223,35 +223,60 @@ gfx_parse_mode_str(char *str, int *x, int *y, int *depth) return (true); } +/* + * Returns true if we set the color from pre-existing environment, false if + * just used existing defaults. + */ +static bool +gfx_fb_evalcolor(const char *envname, teken_color_t *cattr, + ev_sethook_t sethook, ev_unsethook_t unsethook) +{ + const char *ptr; + char env[10]; + bool from_env = false; + + ptr = getenv(envname); + if (ptr != NULL) { + *cattr = strtol(ptr, NULL, 10); + + /* + * If we can't unset the value, then it's probably hooked + * properly and we can just carry on. Otherwise, we want to + * reinitialize it so that we can hook it for the console that + * we're resetting defaults for. + */ + if (unsetenv(envname) != 0) + return (true); + from_env = true; + } + + snprintf(env, sizeof(env), "%d", *cattr); + env_setenv(envname, EV_VOLATILE, env, sethook, unsethook); + + return (from_env); +} + void gfx_fb_setcolors(teken_attr_t *attr, ev_sethook_t sethook, ev_unsethook_t unsethook) { const char *ptr; - char env[10]; + bool need_setattr = false; /* * On first run, we setup an environment hook to process any color * changes. If the env is already set, we pick up fg and bg color * values from the environment. */ - ptr = getenv("teken.fg_color"); - if (ptr != NULL) { - attr->ta_fgcolor = strtol(ptr, NULL, 10); - ptr = getenv("teken.bg_color"); - attr->ta_bgcolor = strtol(ptr, NULL, 10); - + if (gfx_fb_evalcolor("teken.fg_color", &attr->ta_fgcolor, + sethook, unsethook)) + need_setattr = true; + if (gfx_fb_evalcolor("teken.bg_color", &attr->ta_bgcolor, + sethook, unsethook)) + need_setattr = true; + + if (need_setattr) teken_set_defattr(&gfx_state.tg_teken, attr); - } else { - snprintf(env, sizeof(env), "%d", - attr->ta_fgcolor); - env_setenv("teken.fg_color", EV_VOLATILE, env, - sethook, unsethook); - snprintf(env, sizeof(env), "%d", - attr->ta_bgcolor); - env_setenv("teken.bg_color", EV_VOLATILE, env, - sethook, unsethook); - } } static uint32_thome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69dba1aa.439d7.4ff8b5db>
