From: Karel Zak Date: Wed, 4 Sep 2024 10:19:41 +0000 (+0200) Subject: env: add "overwrite" argument to env_list_setenv() X-Git-Tag: v2.42-start~214^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0d87646bc53115636d7bb2bdf46a90df88aa6e46;p=thirdparty%2Futil-linux.git env: add "overwrite" argument to env_list_setenv() Signed-off-by: Karel Zak --- diff --git a/include/env.h b/include/env.h index 5e9198c88..d4dde7f22 100644 --- a/include/env.h +++ b/include/env.h @@ -17,7 +17,7 @@ extern struct ul_env_list *env_list_add_variable(struct ul_env_list *ls, const char *name, const char *value); -extern int env_list_setenv(struct ul_env_list *ls); +extern int env_list_setenv(struct ul_env_list *ls, int overwrite); extern void env_list_free(struct ul_env_list *ls); extern struct ul_env_list *env_from_fd(int pid); diff --git a/lib/env.c b/lib/env.c index bab8822b0..cfc5e3c04 100644 --- a/lib/env.c +++ b/lib/env.c @@ -149,13 +149,13 @@ struct ul_env_list *env_from_fd(int fd) /* * Use setenv() for all stuff in @ls. */ -int env_list_setenv(struct ul_env_list *ls) +int env_list_setenv(struct ul_env_list *ls, int overwrite) { int rc = 0; while (ls && rc == 0) { if (ls->name && ls->value) - rc = setenv(ls->name, ls->value, 0); + rc = setenv(ls->name, ls->value, overwrite); ls = ls->next; } return rc; @@ -273,7 +273,7 @@ int main(void) } /* restore removed */ - env_list_setenv(removed); + env_list_setenv(removed, 0); /* check restore */ for (bad = forbid; *bad; bad++) { diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 50e66de58..4ec9b50d1 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -58,7 +58,7 @@ static void suid_drop(struct libmnt_context *cxt) /* restore "bad" environment variables */ if (envs_removed) { - env_list_setenv(envs_removed); + env_list_setenv(envs_removed, 0); env_list_free(envs_removed); envs_removed = NULL; } diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index 8f7bac922..d6a50fd95 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -647,7 +647,7 @@ int main(int argc, char *argv[]) if ((envls = env_from_fd(env_fd)) == NULL) err(EXIT_FAILURE, _("failed to get environment variables")); clearenv(); - if (env_list_setenv(envls) < 0) + if (env_list_setenv(envls, 0) < 0) err(EXIT_FAILURE, _("failed to set environment variables")); env_list_free(envls); close(env_fd); diff --git a/sys-utils/umount.c b/sys-utils/umount.c index 17e668c8b..d8ab3f7ca 100644 --- a/sys-utils/umount.c +++ b/sys-utils/umount.c @@ -129,7 +129,7 @@ static void suid_drop(struct libmnt_context *cxt) /* restore "bad" environment variables */ if (envs_removed) { - env_list_setenv(envs_removed); + env_list_setenv(envs_removed, 0); env_list_free(envs_removed); envs_removed = NULL; }