ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
9fc0f6
From a777218d241e52279039da5a2ba9b5a69576583c Mon Sep 17 00:00:00 2001
9fc0f6
From: Lennart Poettering <lennart@poettering.net>
9fc0f6
Date: Mon, 28 Apr 2014 18:11:40 +0200
9fc0f6
Subject: [PATCH] machine-id: only look into KVM uuid when we are not running
9fc0f6
 in a container
9fc0f6
9fc0f6
Resolves: #1123452
9fc0f6
9fc0f6
(cherry picked from commit 0b36bbc42d3a408531517a02acaf56105b863d55)
9fc0f6
9fc0f6
Conflicts:
9fc0f6
	src/core/machine-id-setup.c
9fc0f6
---
9fc0f6
 src/core/machine-id-setup.c | 53 +++++++++++++++++++++++----------------------
9fc0f6
 1 file changed, 27 insertions(+), 26 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
9fc0f6
index 291930e..8cfcf51 100644
9fc0f6
--- a/src/core/machine-id-setup.c
9fc0f6
+++ b/src/core/machine-id-setup.c
9fc0f6
@@ -92,32 +92,9 @@ static int generate(char id[34], const char *root) {
9fc0f6
                 }
9fc0f6
         }
9fc0f6
 
9fc0f6
-        /* If that didn't work, see if we are running in qemu/kvm and a
9fc0f6
-         * machine ID was passed in via -uuid on the qemu/kvm command
9fc0f6
-         * line */
9fc0f6
-
9fc0f6
-        r = detect_vm(&vm_id);
9fc0f6
-        if (r > 0 && streq(vm_id, "kvm")) {
9fc0f6
-                char uuid[37];
9fc0f6
-
9fc0f6
-                fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
9fc0f6
-                if (fd >= 0) {
9fc0f6
-                        k = loop_read(fd, uuid, 36, false);
9fc0f6
-                        close_nointr_nofail(fd);
9fc0f6
-
9fc0f6
-                        if (k >= 36) {
9fc0f6
-                                r = shorten_uuid(id, uuid);
9fc0f6
-                                if (r >= 0) {
9fc0f6
-                                        log_info("Initializing machine ID from KVM UUID.");
9fc0f6
-                                        return 0;
9fc0f6
-                                }
9fc0f6
-                        }
9fc0f6
-                }
9fc0f6
-        }
9fc0f6
-
9fc0f6
-        /* If that didn't work either, see if we are running in a
9fc0f6
-         * container, and a machine ID was passed in via
9fc0f6
-         * $container_uuid the way libvirt/LXC does it */
9fc0f6
+        /* If that didn't work, see if we are running in a container,
9fc0f6
+         * and a machine ID was passed in via $container_uuid the way
9fc0f6
+         * libvirt/LXC does it */
9fc0f6
         r = detect_container(NULL);
9fc0f6
         if (r > 0) {
9fc0f6
                 _cleanup_free_ char *e = NULL;
9fc0f6
@@ -132,6 +109,30 @@ static int generate(char id[34], const char *root) {
9fc0f6
                                 }
9fc0f6
                         }
9fc0f6
                 }
9fc0f6
+
9fc0f6
+        } else {
9fc0f6
+                /* If we are not running in a container, see if we are
9fc0f6
+                 * running in qemu/kvm and a machine ID was passed in
9fc0f6
+                 * via -uuid on the qemu/kvm command line */
9fc0f6
+
9fc0f6
+                r = detect_vm(&vm_id);
9fc0f6
+                if (r > 0 && streq(vm_id, "kvm")) {
9fc0f6
+                        char uuid[37];
9fc0f6
+
9fc0f6
+                        fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
9fc0f6
+                        if (fd >= 0) {
9fc0f6
+                                k = loop_read(fd, uuid, 36, false);
9fc0f6
+                                close_nointr_nofail(fd);
9fc0f6
+
9fc0f6
+                                if (k >= 36) {
9fc0f6
+                                        r = shorten_uuid(id, uuid);
9fc0f6
+                                        if (r >= 0) {
9fc0f6
+                                                log_info("Initializing machine ID from KVM UUID.");
9fc0f6
+                                                return 0;
9fc0f6
+                                        }
9fc0f6
+                                }
9fc0f6
+                        }
9fc0f6
+                }
9fc0f6
         }
9fc0f6
 
9fc0f6
         /* If that didn't work, generate a random machine id */