chiark / gitweb /
logind: Do not fail display count if a device has no parent
[elogind.git] / src / login / sd-login.c
index 2930b8751f06f35c49f177643d42583f035fd989..ef67040ebc065f0570a6d30ffdb1bd416cb8b8b7 100644 (file)
@@ -254,6 +254,26 @@ _public_ int sd_session_is_active(const char *session) {
         return r;
 }
 
+_public_ int sd_session_is_remote(const char *session) {
+        int r;
+        _cleanup_free_ char *p = NULL, *s = NULL;
+
+        r = file_of_session(session, &p);
+        if (r < 0)
+                return r;
+
+        r = parse_env_file(p, NEWLINE, "REMOTE", &s, NULL);
+        if (r < 0)
+                return r;
+
+        if (!s)
+                return -EIO;
+
+        r = parse_boolean(s);
+
+        return r;
+}
+
 _public_ int sd_session_get_state(const char *session, char **state) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
@@ -364,6 +384,14 @@ _public_ int sd_session_get_display(const char *session, char **display) {
         return session_get_string(session, "DISPLAY", display);
 }
 
+_public_ int sd_session_get_remote_user(const char *session, char **remote_user) {
+        return session_get_string(session, "REMOTE_USER", remote_user);
+}
+
+_public_ int sd_session_get_remote_host(const char *session, char **remote_host) {
+        return session_get_string(session, "REMOTE_HOST", remote_host);
+}
+
 static int file_of_seat(const char *seat, char **_p) {
         char *p;
         int r;
@@ -602,7 +630,32 @@ _public_ int sd_get_uids(uid_t **users) {
 }
 
 _public_ int sd_get_machine_names(char ***machines) {
-        return get_files_in_directory("/run/systemd/machines/", machines);
+        char **l = NULL, **a, **b;
+        int r;
+
+        r = get_files_in_directory("/run/systemd/machines/", &l);
+        if (r < 0)
+                return r;
+
+        if (l) {
+                r = 0;
+
+                /* Filter out the unit: symlinks */
+                for (a = l, b = l; *a; a++) {
+                        if (startswith(*a, "unit:"))
+                                free(*a);
+                        else {
+                                *b = *a;
+                                b++;
+                                r++;
+                        }
+                }
+
+                *b = NULL;
+        }
+
+        *machines = l;
+        return r;
 }
 
 static inline int MONITOR_TO_FD(sd_login_monitor *m) {