diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-04-28 14:15:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-04-29 16:39:09 +0200 |
commit | b4be4ff8ae0c7ab54a60f77b95f967131e1fcc6b (patch) | |
tree | cfa394d481c209162b5fb64a78c0a107600856f5 /src/libsystemd/sd-id128 | |
parent | f813b62316395205f4c744cde43885081b5f88ae (diff) | |
download | systemd-b4be4ff8ae0c7ab54a60f77b95f967131e1fcc6b.tar.gz |
id128-util: use common implementation of helper to get/validate product ID
Diffstat (limited to 'src/libsystemd/sd-id128')
-rw-r--r-- | src/libsystemd/sd-id128/id128-util.c | 22 | ||||
-rw-r--r-- | src/libsystemd/sd-id128/id128-util.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libsystemd/sd-id128/id128-util.c b/src/libsystemd/sd-id128/id128-util.c index a3f6da6381..2074771a41 100644 --- a/src/libsystemd/sd-id128/id128-util.c +++ b/src/libsystemd/sd-id128/id128-util.c @@ -210,3 +210,25 @@ sd_id128_t id128_make_v4_uuid(sd_id128_t id) { } DEFINE_HASH_OPS(id128_hash_ops, sd_id128_t, id128_hash_func, id128_compare_func); + +int id128_get_product(sd_id128_t *ret) { + sd_id128_t uuid; + int r; + + assert(ret); + + /* Reads the systems product UUID from DMI or devicetree (where it is located on POWER). This is + * particularly relevant in VM environments, where VM managers typically place a VM uuid there. */ + + r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &uuid); + if (r == -ENOENT) + r = id128_read("/sys/firmware/devicetree/base/vm,uuid", ID128_UUID, &uuid); + if (r < 0) + return r; + + if (sd_id128_is_null(uuid) || sd_id128_is_allf(uuid)) + return -EADDRNOTAVAIL; /* Recognizable error */ + + *ret = uuid; + return 0; +} diff --git a/src/libsystemd/sd-id128/id128-util.h b/src/libsystemd/sd-id128/id128-util.h index 6b09bcd96a..053ef0a6a8 100644 --- a/src/libsystemd/sd-id128/id128-util.h +++ b/src/libsystemd/sd-id128/id128-util.h @@ -36,3 +36,5 @@ int id128_compare_func(const sd_id128_t *a, const sd_id128_t *b) _pure_; extern const struct hash_ops id128_hash_ops; sd_id128_t id128_make_v4_uuid(sd_id128_t id); + +int id128_get_product(sd_id128_t *ret); |