]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-id128: id128_write overwrites target file
authorEvgeny Vereshchagin <evvers@ya.ru>
Tue, 13 Dec 2016 11:45:01 +0000 (11:45 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Tue, 13 Dec 2016 13:03:14 +0000 (13:03 +0000)
src/libsystemd/sd-id128/id128-util.c
test/TEST-14-MACHINE-ID/test.sh

index 337eae24b45132adfd5c8f1ba6f7dfe7e094ca36..e6d45c18e33a0ac635169003e4016e291470b8a0 100644 (file)
@@ -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;
 
index 201d5281da6a11d4ce9c90b120ea8bd67cc51779..f7a39dd696c998800cca59b7421a6f3d5b57bf1f 100755 (executable)
@@ -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")