chiark / gitweb /
sd-login: treat missing /run/elogind/{seats,sessions,users} the same as empty
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 31 May 2017 14:48:47 +0000 (23:48 +0900)
committerSven Eden <yamakuzure@gmx.net>
Tue, 25 Jul 2017 07:46:52 +0000 (09:46 +0200)
C.f. 0543105b0fb13e4243b71a78f62f81fb9dde5d51.
This makes if /run/elogind/{seats,sessions,users} are missing, then
sd_get_seats(), sd_get_sessions() and sd_get_uids() return 0, that is,
an empty list, instead of -ENOENT.

src/libelogind/sd-login/sd-login.c

index 161eccd08134b4881306cfd36814e330cda77e9f..7630e6265334f3f7d60e4248bd0b728648650faa 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;