[openwrt/openwrt] ucode: fix reusing the current environment in uloop.process()
LEDE Commits
lede-commits at lists.infradead.org
Wed Oct 8 10:50:48 PDT 2025
nbd pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/7418c2d89b1c2bda3b14679abbcc45c716e469eb
commit 7418c2d89b1c2bda3b14679abbcc45c716e469eb
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Wed Oct 8 19:50:20 2025 +0200
ucode: fix reusing the current environment in uloop.process()
Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
...op-allow-reusing-the-existing-environment.patch | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/package/utils/ucode/patches/110-uloop-allow-reusing-the-existing-environment.patch b/package/utils/ucode/patches/110-uloop-allow-reusing-the-existing-environment.patch
new file mode 100644
index 0000000000..867b434789
--- /dev/null
+++ b/package/utils/ucode/patches/110-uloop-allow-reusing-the-existing-environment.patch
@@ -0,0 +1,57 @@
+From: Felix Fietkau <nbd at nbd.name>
+Date: Wed, 8 Oct 2025 19:11:46 +0200
+Subject: [PATCH] uloop: allow reusing the existing environment
+
+When passing null as environment argument, reuse existing environ.
+This makes it possible to avoid having to duplicate and convert it
+by passing the output of getenv().
+
+Signed-off-by: Felix Fietkau <nbd at nbd.name>
+---
+
+--- a/lib/uloop.c
++++ b/lib/uloop.c
+@@ -1016,7 +1016,22 @@ uc_uloop_process(uc_vm_t *vm, size_t nar
+
+ if (pid == 0) {
+ argp = calloc(ucv_array_length(arguments) + 2, sizeof(char *));
+- envp = calloc(ucv_object_length(env_arg) + 1, sizeof(char *));
++ envp = environ;
++
++ if (env_arg) {
++ envp = calloc(ucv_object_length(env_arg) + 1, sizeof(char *));
++ i = 0;
++ ucv_object_foreach(env_arg, envk, envv) {
++ buf = xprintbuf_new();
++
++ ucv_stringbuf_printf(buf, "%s=", envk);
++ ucv_to_stringbuf(vm, buf, envv, false);
++
++ envp[i++] = buf->buf;
++
++ free(buf);
++ }
++ }
+
+ if (!argp || !envp)
+ _exit(-1);
+@@ -1026,19 +1041,6 @@ uc_uloop_process(uc_vm_t *vm, size_t nar
+ for (i = 0; i < ucv_array_length(arguments); i++)
+ argp[i+1] = ucv_to_string(vm, ucv_array_get(arguments, i));
+
+- i = 0;
+-
+- ucv_object_foreach(env_arg, envk, envv) {
+- buf = xprintbuf_new();
+-
+- ucv_stringbuf_printf(buf, "%s=", envk);
+- ucv_to_stringbuf(vm, buf, envv, false);
+-
+- envp[i++] = buf->buf;
+-
+- free(buf);
+- }
+-
+ execvpe((const char *)ucv_string_get(executable),
+ (char * const *)argp, (char * const *)envp);
+
More information about the lede-commits
mailing list