All of lore.kernel.org
 help / color / mirror / Atom feed
From: Giacomo Mazzola <gmazz@amazon.de>
To: <kvm@vger.kernel.org>
Cc: Giacomo Mazzola <gmazz@amazon.de>, Andrew Jones <andrew.jones@linux.dev>
Subject: [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line into environ
Date: Tue, 20 Oct 2026 15:25:25 +0000	[thread overview]
Message-ID: <20261020152525.57694-9-gmazz@amazon.de> (raw)
In-Reply-To: <20261020152525.57694-1-gmazz@amazon.de>

Add support for passing environment variables via the command line.
If any argv element starts with 'KUT_ENV=', the value after the '='
is parsed as a comma-separated list of KEY=VAL pairs and fed to
setup_env().  The KUT_ENV= argument is then removed from argv so
tests do not see it as a spurious positional argument.

Example: KUT_ENV=PARAM_1=VALUE_1,PARAM_2=VALUE_2

Signed-off-by: Giacomo Mazzola <gmazz@amazon.de>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
---
 lib/argv.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/lib/argv.c b/lib/argv.c
index fa5ff9ae..6a2b791c 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -27,6 +27,36 @@ static const char *skip_blanks(const char *p)
 	return p;
 }
 
+static void setup_args_env(void)
+{
+	static const char prefix[] = "KUT_ENV=";
+	char *env, *p;
+	int i, j;
+
+	for (i = 0; i < __argc; i++) {
+		if (strncmp(__argv[i], prefix, sizeof(prefix) - 1) == 0)
+			break;
+	}
+
+	if (i == __argc)
+		return;
+
+	env = __argv[i] + sizeof(prefix) - 1;
+
+	/* Shift remaining args down to preserve order. */
+	for (j = i; j < __argc - 1; j++)
+		__argv[j] = __argv[j + 1];
+	__argv[--__argc] = NULL;
+
+	/* Convert comma separators to newlines for setup_env(). */
+	for (p = env; *p; p++) {
+		if (*p == ',')
+			*p = '\n';
+	}
+
+	setup_env(env, p - env);
+}
+
 void __setup_args(void)
 {
 	const char *args = __args;
@@ -39,6 +69,8 @@ void __setup_args(void)
 		*copy_ptr++ = '\0';
 	}
 	__argc = argv - __argv;
+
+	setup_args_env();
 }
 
 void setup_args(const char *args)
@@ -130,6 +162,9 @@ void setup_env(char *env, int size)
 	bool newline = false;
 	int i = 0;
 
+	while (__environ[i])
+		i++;
+
 	while (*p)
 		++p;
 	if (p == eof)
-- 
2.47.3


  parent reply	other threads:[~2026-10-20 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 15:25 [kvm-unit-tests PATCH v2 0/8] x86: fixes for running KUT as EFI on non-QEMU KVM hosts Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 1/8] x86: efi: use PER_CPU_SIZE for per-CPU stack allocation Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 2/8] x86: fix EFI memory allocator to clamp regions to 4 GiB Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 3/8] x86: skip PMU init when no PMU is advertised Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 4/8] x86: fix ISR thunk to use absolute indirect jump Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 5/8] x86: replace per-AP bringup prints with a single summary line Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 6/8] x86: add timeout-based SMP bringup when fw_cfg is unavailable Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 7/8] efi: fix load_options_size conversion to character count Giacomo Mazzola
2026-10-20 15:25 ` Giacomo Mazzola [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-06-09 14:09 [kvm-unit-tests PATCH 8/8] efi: parse KUT_ENV= from load options into environ Giacomo Mazzola
2026-06-25 14:04 ` [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line " Giacomo Mazzola
2026-09-29 13:08   ` Andrew Jones

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=20261020152525.57694-9-gmazz@amazon.de \
    --to=gmazz@amazon.de \
    --cc=andrew.jones@linux.dev \
    --cc=kvm@vger.kernel.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.