summaryrefslogtreecommitdiff
path: root/src/core/machine-id-setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/machine-id-setup.c')
-rw-r--r--src/core/machine-id-setup.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 2d5ae3b3b9..8f682c6d10 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -108,7 +108,7 @@ static int generate_machine_id(char id[34], const char *root) {
unsigned char *p;
sd_id128_t buf;
char *q;
- const char *vm_id, *dbus_machine_id;
+ const char *dbus_machine_id;
assert(id);
@@ -133,8 +133,8 @@ static int generate_machine_id(char id[34], const char *root) {
/* If that didn't work, see if we are running in a container,
* and a machine ID was passed in via $container_uuid the way
* libvirt/LXC does it */
- r = detect_container(NULL);
- if (r > 0) {
+
+ if (detect_container() > 0) {
_cleanup_free_ char *e = NULL;
r = getenv_for_pid(1, "container_uuid", &e);
@@ -146,26 +146,24 @@ static int generate_machine_id(char id[34], const char *root) {
}
}
- } else {
+ } else if (detect_vm() == VIRTUALIZATION_KVM) {
+
/* If we are not running in a container, see if we are
* running in qemu/kvm and a machine ID was passed in
* via -uuid on the qemu/kvm command line */
- r = detect_vm(&vm_id);
- if (r > 0 && streq(vm_id, "kvm")) {
- char uuid[36];
+ char uuid[36];
- fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
- if (fd >= 0) {
- r = loop_read_exact(fd, uuid, 36, false);
- safe_close(fd);
+ fd = open("/sys/class/dmi/id/product_uuid", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+ if (fd >= 0) {
+ r = loop_read_exact(fd, uuid, 36, false);
+ safe_close(fd);
+ if (r >= 0) {
+ r = shorten_uuid(id, uuid);
if (r >= 0) {
- r = shorten_uuid(id, uuid);
- if (r >= 0) {
- log_info("Initializing machine ID from KVM UUID.");
- return 0;
- }
+ log_info("Initializing machine ID from KVM UUID.");
+ return 0;
}
}
}