summaryrefslogtreecommitdiff
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-08-16 16:41:34 +0200
committerLennart Poettering <lennart@poettering.net>2021-08-17 13:17:44 +0200
commit7a6abbe93762fe23d415144ae7a040df3266bb5f (patch)
tree3c241ce87c245becbe36b6e3f1b366b32f2f6461 /src/basic/env-util.c
parent8b474a437ce980bd0909db59141b40d56f6d5688 (diff)
downloadsystemd-7a6abbe93762fe23d415144ae7a040df3266bb5f.tar.gz
env-util: add unsetenv_erase() helper
Let's unify how we remove secrets from the env block.
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index cb49125644..b42ca50b25 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -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;
+}