chiark / gitweb /
logind: split up HandleSleepKey= into HandleSuspendKey= and HandleHibernateKey=
[elogind.git] / src / login / sd-login.c
index 912ced31790209c4d495db648e2ddd00fe11e294..45e3bb8dcd07c03451f106d235bfe8ee96f64b45 100644 (file)
@@ -259,11 +259,21 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) {
 }
 
 _public_ int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions) {
-        return uid_get_array(uid, require_active ? "ACTIVE_SESSIONS" : "SESSIONS", sessions);
+        return uid_get_array(
+                        uid,
+                        require_active == 0 ? "ONLINE_SESSIONS" :
+                        require_active > 0  ? "ACTIVE_SESSIONS" :
+                                              "SESSIONS",
+                        sessions);
 }
 
 _public_ int sd_uid_get_seats(uid_t uid, int require_active, char ***seats) {
-        return uid_get_array(uid, require_active ? "ACTIVE_SEATS" : "SEATS", seats);
+        return uid_get_array(
+                        uid,
+                        require_active == 0 ? "ONLINE_SEATS" :
+                        require_active > 0  ? "ACTIVE_SEATS" :
+                                              "SEATS",
+                        seats);
 }
 
 static int file_of_session(const char *session, char **_p) {
@@ -317,6 +327,30 @@ _public_ int sd_session_is_active(const char *session) {
         return r;
 }
 
+_public_ int sd_session_get_state(const char *session, char **state) {
+        char *p, *s = NULL;
+        int r;
+
+        if (!state)
+                return -EINVAL;
+
+        r = file_of_session(session, &p);
+        if (r < 0)
+                return r;
+
+        r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
+        free(p);
+
+        if (r < 0) {
+                free(s);
+                return r;
+        } else if (!s)
+                return -EIO;
+
+        *state = s;
+        return 0;
+}
+
 _public_ int sd_session_get_uid(const char *session, uid_t *uid) {
         int r;
         char *p, *s = NULL;
@@ -559,7 +593,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
         return r;
 }
 
-_public_ int sd_seat_can_multi_session(const char *seat) {
+static int seat_get_can(const char *seat, const char *variable) {
         char *p, *s = NULL;
         int r;
 
@@ -568,7 +602,7 @@ _public_ int sd_seat_can_multi_session(const char *seat) {
                 return r;
 
         r = parse_env_file(p, NEWLINE,
-                           "CAN_MULTI_SESSION", &s,
+                           variable, &s,
                            NULL);
         free(p);
 
@@ -586,6 +620,18 @@ _public_ int sd_seat_can_multi_session(const char *seat) {
         return r;
 }
 
+_public_ int sd_seat_can_multi_session(const char *seat) {
+        return seat_get_can(seat, "CAN_MULTI_SESSION");
+}
+
+_public_ int sd_seat_can_tty(const char *seat) {
+        return seat_get_can(seat, "CAN_TTY");
+}
+
+_public_ int sd_seat_can_graphical(const char *seat) {
+        return seat_get_can(seat, "CAN_GRAPHICAL");
+}
+
 _public_ int sd_get_seats(char ***seats) {
         return get_files_in_directory("/run/systemd/seats/", seats);
 }
@@ -605,11 +651,12 @@ _public_ int sd_get_uids(uid_t **users) {
                 return -errno;
 
         for (;;) {
-                struct dirent buffer, *de;
+                struct dirent *de;
+                union dirent_storage buf;
                 int k;
                 uid_t uid;
 
-                k = readdir_r(d, &buffer, &de);
+                k = readdir_r(d, &buf.de, &de);
                 if (k != 0) {
                         r = -k;
                         goto finish;