richardphibel / rpms / systemd

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