From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 01/10] globalvar: add scopes to snapshot and restore globalvars
Date: Thu, 12 Nov 2026 09:41:14 +0100 [thread overview]
Message-ID: <02acb118-bc0d-4e7f-b053-2a43fd423d49@pengutronix.de> (raw)
In-Reply-To: <20261030-boot-globalvar-stack-v1-1-a03803e1100c@pengutronix.de>
On 10/30/26 11:53, Sascha Hauer wrote:
> Code that runs foreign code, like boot scripts, often wants to revert
> whatever that code changed in the global namespace afterwards. So far
> this is done by hand for each use case: either by saving and restoring a
> fixed list of variables, or by putting variables into a dedicated
> namespace which is cleared afterwards.
>
> Add globalvar_scope_push() and globalvar_scope_pop() to do this
> generically. A scope records the current values of all globalvars whose
> name begins with one of the given prefixes. Popping it restores changed
> values, removes variables created in the meantime and creates removed
> variables again. Variables are only removed or recreated if they were
> created with globalvar_add_simple(), which is what the shell's global
> command and most dynamically created variables use. For all other
> globalvars, which are backed by a C variable, only the value is
> restored, through the regular setter so the C variable follows.
>
> Scopes can be nested as long as they are popped in reverse order.
As mentioned before, I have misgivings about _global_ variables being scoped,
but we have effectively that already for some variables...
Some bike shedding: I think I like the term of "banked" global variables
more, but that's just a suggestion.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> +static bool globalvar_scope_match(const struct globalvar_scope *scope,
> + const char *name)
> +{
> + const char * const *prefix;
> +
> + for (prefix = scope->prefixes; *prefix; prefix++)
> + if (str_has_prefix(name, *prefix))
> + return true;
I see that the prefixes have a trailing . to avoid partial matches, but
I think that's a bit of a surprising API compared to do boundary matching
(or matching to the end of string _or_ dot). Just a nit.
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-11-12 10:13 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 10:53 [PATCH 00/10] boot: revert boot related globalvars after booting Sascha Hauer
2026-10-30 10:53 ` [PATCH 01/10] globalvar: add scopes to snapshot and restore globalvars Sascha Hauer
2026-11-12 8:41 ` Ahmad Fatoum [this message]
2026-11-12 13:25 ` Sascha Hauer
2026-11-12 13:27 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 02/10] bootm: revert globalvar changes in bootm_boot_cleanup() Sascha Hauer
2026-11-12 7:48 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 03/10] boot: revert globalvar changes after each boot entry Sascha Hauer
2026-11-12 7:48 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 04/10] bootchooser: use a globalvar scope for its bootargs Sascha Hauer
2026-11-12 7:49 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 05/10] test: py: add test for reverting globalvars after boot Sascha Hauer
2026-11-12 7:51 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 06/10] bootargs: remove unused linux_bootargs_overwrite() Sascha Hauer
2026-11-12 7:52 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 07/10] of: add watchdog bootarg directly instead of via a globalvar Sascha Hauer
2026-11-12 7:59 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 08/10] boot: drop the dyn infix from the bootentries bootargs variable Sascha Hauer
2026-11-12 8:02 ` Ahmad Fatoum
2026-11-12 13:07 ` Sascha Hauer
2026-10-30 10:54 ` [PATCH 09/10] defaultenv: don't use global.linux.bootargs.dyn.* in boot entries Sascha Hauer
2026-11-12 8:19 ` Ahmad Fatoum
2026-10-30 10:54 ` [PATCH 10/10] Documentation: migration-guides: describe reverting boot globalvars Sascha Hauer
2026-11-12 8:21 ` Ahmad Fatoum
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=02acb118-bc0d-4e7f-b053-2a43fd423d49@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox