summaryrefslogtreecommitdiffstats
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-17 17:54:09 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-19 11:41:42 +0200
commitcc915eefafa89fe49da3afaf0f3fdaef24679b62 (patch)
tree08dac990efaaea4a8a2b894e7f6241ef74402ea7 /src/basic/env-util.c
parentvmspawn: make "-n" just work (diff)
downloadsystemd-cc915eefafa89fe49da3afaf0f3fdaef24679b62.tar.xz
systemd-cc915eefafa89fe49da3afaf0f3fdaef24679b62.zip
env-util: suppress unnecessary setenv() in setenvf()
Diffstat (limited to '')
-rw-r--r--src/basic/env-util.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 3e385e5ee4..cf2c47d214 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -1146,5 +1146,10 @@ int setenvf(const char *name, bool overwrite, const char *valuef, ...) {
if (r < 0)
return -ENOMEM;
+ /* Try to suppress writes if the value is already set correctly (simply because memory management of
+ * environment variables sucks a bit. */
+ if (streq_ptr(getenv(name), value))
+ return 0;
+
return RET_NERRNO(setenv(name, value, overwrite));
}