chiark / gitweb /
sd-bus: when credentials of the "org.freedesktop.DBus" service are queried return...
[elogind.git] / src / libelogind / sd-login / sd-login.c
index 161eccd08134b4881306cfd36814e330cda77e9f..5f90ba70c4121ab13fdec1077ee974b9caffab4f 100644 (file)
@@ -862,11 +862,27 @@ _public_ int sd_seat_can_graphical(const char *seat) {
 }
 
 _public_ int sd_get_seats(char ***seats) {
-        return get_files_in_directory("/run/systemd/seats/", seats);
+        int r;
+
+        r = get_files_in_directory("/run/systemd/seats/", seats);
+        if (r == -ENOENT) {
+                if (seats)
+                        *seats = NULL;
+                return 0;
+        }
+        return r;
 }
 
 _public_ int sd_get_sessions(char ***sessions) {
-        return get_files_in_directory("/run/systemd/sessions/", sessions);
+        int r;
+
+        r = get_files_in_directory("/run/systemd/sessions/", sessions);
+        if (r == -ENOENT) {
+                if (sessions)
+                        *sessions = NULL;
+                return 0;
+        }
+        return r;
 }
 
 _public_ int sd_get_uids(uid_t **users) {
@@ -877,8 +893,14 @@ _public_ int sd_get_uids(uid_t **users) {
         _cleanup_free_ uid_t *l = NULL;
 
         d = opendir("/run/systemd/users/");
-        if (!d)
+        if (!d) {
+                if (errno == ENOENT) {
+                        if (users)
+                                *users = NULL;
+                        return 0;
+                }
                 return -errno;
+        }
 
         FOREACH_DIRENT_ALL(de, d, return -errno) {
                 int k;
@@ -920,14 +942,13 @@ _public_ int sd_get_uids(uid_t **users) {
 }
 
 _public_ int sd_get_machine_names(char ***machines) {
-        char **l = NULL, **a, **b;
+        char **l, **a, **b;
         int r;
 
-        assert_return(machines, -EINVAL);
-
         r = get_files_in_directory("/run/systemd/machines/", &l);
         if (r == -ENOENT) {
-                *machines = NULL;
+                if (machines)
+                        *machines = NULL;
                 return 0;
         }
         if (r < 0)
@@ -937,7 +958,7 @@ _public_ int sd_get_machine_names(char ***machines) {
                 r = 0;
 
                 /* Filter out the unit: symlinks */
-                for (a = l, b = l; *a; a++) {
+                for (a = b = l; *a; a++) {
                         if (startswith(*a, "unit:") || !machine_name_is_valid(*a))
                                 free(*a);
                         else {
@@ -950,7 +971,8 @@ _public_ int sd_get_machine_names(char ***machines) {
                 *b = NULL;
         }
 
-        *machines = l;
+        if (machines)
+                *machines = l;
         return r;
 }