]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
id128-util: use FOREACH_STRING where appropriate
authorMike Yuan <me@yhndnzj.com>
Wed, 24 Jan 2024 09:02:28 +0000 (17:02 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 24 Jan 2024 09:09:45 +0000 (17:09 +0800)
src/libsystemd/sd-id128/id128-util.c

index a73bc1fa540f63b863544585681fa04c57d66e76..7e5cb95d30f0ed00ae1636e4327e65b82dc9db05 100644 (file)
@@ -12,6 +12,7 @@
 #include "sha256.h"
 #include "stdio-util.h"
 #include "string-util.h"
+#include "strv.h"
 #include "sync-util.h"
 #include "virt.h"
 
@@ -231,11 +232,15 @@ int id128_get_product(sd_id128_t *ret) {
                     * of the host */
                 return -ENOENT;
 
-        r = id128_read("/sys/class/dmi/id/product_uuid", ID128_FORMAT_UUID, &uuid);
-        if (r == -ENOENT)
-                r = id128_read("/proc/device-tree/vm,uuid", ID128_FORMAT_UUID, &uuid);
-        if (r == -ENOENT)
-                r = id128_read("/sys/hypervisor/uuid", ID128_FORMAT_UUID, &uuid);
+        FOREACH_STRING(i,
+                       "/sys/class/dmi/id/product_uuid", /* KVM */
+                       "/proc/device-tree/vm,uuid",      /* Device tree */
+                       "/sys/hypervisor/uuid") {         /* Xen */
+
+                r = id128_read(i, ID128_FORMAT_UUID, &uuid);
+                if (r != -ENOENT)
+                        break;
+        }
         if (r < 0)
                 return r;