From: Karel Zak Date: Wed, 28 Aug 2024 08:24:41 +0000 (+0200) Subject: env: cleanup env_list API X-Git-Tag: v2.42-start~214^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8616dff420c817f6dbd3cd4d01e1186662c16a8f;p=thirdparty%2Futil-linux.git env: cleanup env_list API * rename env_from_fd() to env_list_from_fd() * rename remove_entry() to ul_remove_entry() Signed-off-by: Karel Zak --- diff --git a/include/env.h b/include/env.h index d4dde7f22..ba0f670d3 100644 --- a/include/env.h +++ b/include/env.h @@ -15,11 +15,9 @@ extern void __sanitize_env(struct ul_env_list **org); 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, int overwrite); extern void env_list_free(struct ul_env_list *ls); -extern struct ul_env_list *env_from_fd(int pid); +extern struct ul_env_list *env_list_from_fd(int pid); extern char *safe_getenv(const char *arg); @@ -34,7 +32,7 @@ static inline void xsetenv(char const *name, char const *val, int overwrite) err(XSETENV_EXIT_CODE, _("failed to set the %s environment variable"), name); } -static inline int remove_entry(char **argv, int remove, int last) +static inline int ul_remove_entry(char **argv, int remove, int last) { memmove(argv + remove, argv + remove + 1, sizeof(char *) * (last - remove)); return last - 1; diff --git a/lib/env.c b/lib/env.c index cfc5e3c04..02c115867 100644 --- a/lib/env.c +++ b/lib/env.c @@ -121,11 +121,11 @@ struct ul_env_list *env_list_add_variable( } /* - * Use env_from_fd() to read environment from @fd. + * Use env_list_from_fd() to read environment from @fd. * * @fd must be /proc//environ file. */ -struct ul_env_list *env_from_fd(int fd) +struct ul_env_list *env_list_from_fd(int fd) { char *buf = NULL, *p; ssize_t rc = 0; @@ -189,7 +189,7 @@ void __sanitize_env(struct ul_env_list **org) if (strncmp(*cur, *bad, strlen(*bad)) == 0) { if (org) *org = env_list_add_from_string(*org, *cur); - last = remove_entry(envp, cur - envp, last); + last = ul_remove_entry(envp, cur - envp, last); cur--; break; } @@ -204,7 +204,7 @@ void __sanitize_env(struct ul_env_list **org) continue; /* OK */ if (org) *org = env_list_add_from_string(*org, *cur); - last = remove_entry(envp, cur - envp, last); + last = ul_remove_entry(envp, cur - envp, last); cur--; break; } diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index d6a50fd95..0f5babaad 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -644,7 +644,7 @@ int main(int argc, char *argv[]) /* Pass environment variables of the target process to the spawned process */ if (env_fd >= 0) { - if ((envls = env_from_fd(env_fd)) == NULL) + if ((envls = env_list_from_fd(env_fd)) == NULL) err(EXIT_FAILURE, _("failed to get environment variables")); clearenv(); if (env_list_setenv(envls, 0) < 0) diff --git a/text-utils/more.c b/text-utils/more.c index 953e94db1..a8d2ef176 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -299,7 +299,7 @@ static void argscan(struct more_control *ctl, int as_argc, char **as_argv) } } if (move) { - as_argc = remove_entry(as_argv, opt, as_argc); + as_argc = ul_remove_entry(as_argv, opt, as_argc); opt--; } }