Blame SOURCES/0196-sd-login-let-s-also-make-sd-login-understand-.host.patch

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