env-util: add unsetenv_erase() helper

Let's unify how we remove secrets from the env block.
This commit is contained in:
Lennart Poettering
2021-08-17 13:17:44 +02:00
parent 8b474a437c
commit 7a6abbe937
8 changed files with 77 additions and 18 deletions
+17
View File
@@ -870,3 +870,20 @@ int getenv_path_list(const char *name, char ***ret_paths) {
*ret_paths = TAKE_PTR(l);
return 1;
}
int unsetenv_erase(const char *name) {
char *p;
assert(name);
p = getenv(name);
if (!p)
return 0;
string_erase(p);
if (unsetenv(name) < 0)
return -errno;
return 1;
}
+2
View File
@@ -68,3 +68,5 @@ int setenv_systemd_exec_pid(bool update_only);
/* Parses and does sanity checks on an environment variable containing
* PATH-like colon-separated absolute paths */
int getenv_path_list(const char *name, char ***ret_paths);
int unsetenv_erase(const char *name);