summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-id128/id128-util.c
diff options
context:
space:
mode:
authorHarald Seiler <hws@denx.de>2020-09-06 21:23:36 +0200
committerHarald Seiler <hws@denx.de>2020-10-19 16:28:21 +0200
commit8085114828c3b07406298f0fa89d368413978e20 (patch)
tree2913094d48dff8ca27c0440377a2c5b67ba011b2 /src/libsystemd/sd-id128/id128-util.c
parent583cef3b7347c4e6ca269d38efef6d2e4314aba6 (diff)
downloadsystemd-8085114828c3b07406298f0fa89d368413978e20.tar.gz
id128: add format which treats "uninitialized" like an empty id
Add a new ID128_PLAIN_OR_UNINIT format which treats the string "uninitialized" like the file was empty and return -ENOMEDIUM. This format should be used when reading an /etc/machine-id file from an image that is not currently running.
Diffstat (limited to 'src/libsystemd/sd-id128/id128-util.c')
-rw-r--r--src/libsystemd/sd-id128/id128-util.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c
index 335f22b920..ebbfb2d32e 100644
--- a/src/libsystemd/sd-id128/id128-util.c
+++ b/src/libsystemd/sd-id128/id128-util.c
@@ -10,6 +10,7 @@
#include "id128-util.h"
#include "io-util.h"
#include "stdio-util.h"
+#include "string-util.h"
char *id128_to_uuid_string(sd_id128_t id, char s[static ID128_UUID_STRING_MAX]) {
unsigned n, k = 0;
@@ -97,6 +98,11 @@ int id128_read_fd(int fd, Id128Format f, sd_id128_t *ret) {
switch (l) {
+ case 13:
+ case 14:
+ /* Treat an "uninitialized" id file like an empty one */
+ return f == ID128_PLAIN_OR_UNINIT && strneq(buffer, "uninitialized\n", l) ? -ENOMEDIUM : -EINVAL;
+
case 33: /* plain UUID with trailing newline */
if (buffer[32] != '\n')
return -EINVAL;
@@ -115,7 +121,7 @@ int id128_read_fd(int fd, Id128Format f, sd_id128_t *ret) {
_fallthrough_;
case 36: /* RFC UUID without trailing newline */
- if (f == ID128_PLAIN)
+ if (IN_SET(f, ID128_PLAIN, ID128_PLAIN_OR_UNINIT))
return -EINVAL;
buffer[36] = 0;