env-util: add helper to replace env block

This commit is contained in:
Luca Boccassi
2023-09-20 00:06:21 +01:00
parent ef7af0acf2
commit 58cb36e56b
2 changed files with 21 additions and 0 deletions

View File

@@ -1074,3 +1074,22 @@ int getenv_steal_erase(const char *name, char **ret) {
return 1;
}
int set_full_environment(char **env) {
int r;
clearenv();
STRV_FOREACH(e, env) {
_cleanup_free_ char *k = NULL, *v = NULL;
r = split_pair(*e, "=", &k, &v);
if (r < 0)
return r;
if (setenv(k, v, /* overwrite= */ true) < 0)
return -errno;
}
return 0;
}

View File

@@ -77,3 +77,5 @@ int setenv_systemd_exec_pid(bool update_only);
int getenv_path_list(const char *name, char ***ret_paths);
int getenv_steal_erase(const char *name, char **ret);
int set_full_environment(char **env);