id128-util: use common implementation of helper to get/validate product ID

This commit is contained in:
Lennart Poettering
2021-04-29 16:39:09 +02:00
parent f813b62316
commit b4be4ff8ae
4 changed files with 35 additions and 21 deletions
+22
View File
@@ -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;
}
+2
View File
@@ -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);