summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-07-21 19:12:50 +0200
committerLennart Poettering <lennart@poettering.net>2016-07-22 12:59:36 +0200
commit15b1248a6b63448c2081fb2ed433f83b32febe47 (patch)
tree35325e0e970d2a021ba6b7bd172820577fc2adca /src/libsystemd
parent317feb4d9f84cf177aa71496b214bcbbf9682750 (diff)
machine-id-setup: port machine_id_commit() to new id128-util.c APIs
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-id128/id128-util.c19
-rw-r--r--src/libsystemd/sd-id128/id128-util.h4
2 files changed, 17 insertions, 6 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);
}
diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h
index 73e4c710c4..3ba59acbca 100644
--- a/src/libsystemd/sd-id128/id128-util.h
+++ b/src/libsystemd/sd-id128/id128-util.h
@@ -41,5 +41,5 @@ typedef enum Id128Format {
int id128_read_fd(int fd, Id128Format f, sd_id128_t *ret);
int id128_read(const char *p, Id128Format f, sd_id128_t *ret);
-int id128_write_fd(int fd, Id128Format f, sd_id128_t id);
-int id128_write(const char *p, Id128Format f, sd_id128_t id);
+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);