From da2d1421143038a648473402f1e6fd17be05fd0c Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Tue, 13 Dec 2016 11:45:01 +0000 Subject: [PATCH] sd-id128: id128_write overwrites target file --- src/libsystemd/sd-id128/id128-util.c | 2 +- test/TEST-14-MACHINE-ID/test.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index 337eae24b45..e6d45c18e33 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -186,7 +186,7 @@ int id128_write_fd(int fd, Id128Format f, sd_id128_t id, bool do_sync) { int id128_write(const char *p, Id128Format f, sd_id128_t id, bool do_sync) { _cleanup_close_ int fd = -1; - fd = open(p, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444); + fd = open(p, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_TRUNC, 0444); if (fd < 0) return -errno; diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index 201d5281da6..f7a39dd696c 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -83,7 +83,8 @@ check expected "$r/etc/machine-id" r="$(pwd)/transient-machine-id" setup_root "$r" -touch "$r/etc/machine-id" +systemd-machine-id-setup --print --root "$r" +echo abc >>"$r/etc/machine-id" mount -o remount,ro "$r" mount -t tmpfs tmpfs "$r/run" transient_id=$(systemd-machine-id-setup --print --root "$r")