+static int get_valid_machine_id(int fd, char id[34]) {
+ char id_to_validate[34];
+
+ assert(fd >= 0);
+ assert(id);
+
+ if (loop_read(fd, id_to_validate, 33, false) == 33 && id_to_validate[32] == '\n') {
+ id_to_validate[32] = 0;
+
+ if (id128_is_valid(id_to_validate)) {
+ memcpy(id, id_to_validate, 32);
+ id[32] = '\n';
+ id[33] = 0;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+static int write_machine_id(int fd, char id[34]) {
+ assert(fd >= 0);
+ assert(id);
+ lseek(fd, 0, SEEK_SET);
+
+ if (loop_write(fd, id, 33, false) == 33)
+ return 0;
+
+ return -errno;
+}
+
+int machine_id_setup(const char *root) {
+ const char *etc_machine_id, *run_machine_id;