diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-07-21 19:12:50 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-07-22 12:59:36 +0200 |
commit | 15b1248a6b63448c2081fb2ed433f83b32febe47 (patch) | |
tree | 35325e0e970d2a021ba6b7bd172820577fc2adca /src/libsystemd/sd-id128/id128-util.c | |
parent | 317feb4d9f84cf177aa71496b214bcbbf9682750 (diff) |
machine-id-setup: port machine_id_commit() to new id128-util.c APIs
Diffstat (limited to 'src/libsystemd/sd-id128/id128-util.c')
-rw-r--r-- | src/libsystemd/sd-id128/id128-util.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index c1742cab0e..aaac838b59 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -18,6 +18,7 @@ ***/ #include <fcntl.h> +#include <unistd.h> #include "fd-util.h" #include "hexdecoct.h" @@ -140,9 +141,10 @@ int id128_read(const char *p, Id128Format f, sd_id128_t *ret) { return id128_read_fd(fd, f, ret); } -int id128_write_fd(int fd, Id128Format f, sd_id128_t id) { +int id128_write_fd(int fd, Id128Format f, sd_id128_t id, bool do_sync) { char buffer[36 + 2]; size_t sz; + int r; assert(fd >= 0); assert(f < _ID128_FORMAT_MAX); @@ -157,15 +159,24 @@ int id128_write_fd(int fd, Id128Format f, sd_id128_t id) { sz = 37; } - return loop_write(fd, buffer, sz, false); + r = loop_write(fd, buffer, sz, false); + if (r < 0) + return r; + + if (do_sync) { + if (fsync(fd) < 0) + return -errno; + } + + return r; } -int id128_write(const char *p, Id128Format f, sd_id128_t id) { +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); if (fd < 0) return -errno; - return id128_write_fd(fd, f, id); + return id128_write_fd(fd, f, id, do_sync); } |