ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ff6046
From 1fd670e06332423a3e0b19ca717145c14e8418a1 Mon Sep 17 00:00:00 2001
ff6046
From: Lennart Poettering <lennart@poettering.net>
ff6046
Date: Tue, 17 Jul 2018 12:24:50 +0200
ff6046
Subject: [PATCH] sd-login: let's also make sd-login understand ".host"
ff6046
ff6046
if sd-bus and machined grok it, then sd-login should grok it too.
ff6046
ff6046
(cherry picked from commit a8c9b7a0fc0aa02666042543ff9a652aae3c9499)
ff6046
ff6046
Resolves: #1683334
ff6046
---
ff6046
 src/libsystemd/sd-login/sd-login.c | 27 +++++++++++++++++----------
ff6046
 1 file changed, 17 insertions(+), 10 deletions(-)
ff6046
ff6046
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
ff6046
index c2f7133e42..aeae6d78a9 100644
ff6046
--- a/src/libsystemd/sd-login/sd-login.c
ff6046
+++ b/src/libsystemd/sd-login/sd-login.c
ff6046
@@ -892,20 +892,27 @@ _public_ int sd_machine_get_class(const char *machine, char **class) {
ff6046
         const char *p;
ff6046
         int r;
ff6046
 
ff6046
-        assert_return(machine_name_is_valid(machine), -EINVAL);
ff6046
         assert_return(class, -EINVAL);
ff6046
 
ff6046
-        p = strjoina("/run/systemd/machines/", machine);
ff6046
-        r = parse_env_file(NULL, p, NEWLINE, "CLASS", &c, NULL);
ff6046
-        if (r == -ENOENT)
ff6046
-                return -ENXIO;
ff6046
-        if (r < 0)
ff6046
-                return r;
ff6046
-        if (!c)
ff6046
-                return -EIO;
ff6046
+        if (streq(machine, ".host")) {
ff6046
+                c = strdup("host");
ff6046
+                if (!c)
ff6046
+                        return -ENOMEM;
ff6046
+        } else {
ff6046
+                if (!machine_name_is_valid(machine))
ff6046
+                        return -EINVAL;
ff6046
 
ff6046
-        *class = TAKE_PTR(c);
ff6046
+                p = strjoina("/run/systemd/machines/", machine);
ff6046
+                r = parse_env_file(NULL, p, NEWLINE, "CLASS", &c, NULL);
ff6046
+                if (r == -ENOENT)
ff6046
+                        return -ENXIO;
ff6046
+                if (r < 0)
ff6046
+                        return r;
ff6046
+                if (!c)
ff6046
+                        return -EIO;
ff6046
+        }
ff6046
 
ff6046
+        *class = TAKE_PTR(c);
ff6046
         return 0;
ff6046
 }
ff6046