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