chiark / gitweb /
logind: Add a two new variables to the user session tracking file.
authorColin Guthrie <colin@mageia.org>
Mon, 3 Sep 2012 22:57:58 +0000 (23:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Sep 2012 06:19:54 +0000 (08:19 +0200)
This counts 'online sessions' in addition to 'active sessions' and 'sessions'.

In this context, an 'online session' covers all session in the 'active' state
in addition to the explicit 'online' state.

This provides an easy machanism to determin all relevant sessions easily
(i.e. those that are not 'closing') and adds new semantics to the sd-login.c
APIs sd_uid_get_sessions() and sd_uid_get_seats() where the require_active
argument can be supplied as a value 2 which only lists sessions which are
'online'.

This functionality should allow client applications to avoid deadlocks where
they only exit when all sessions are complete, such as a the problem where
PulseAudio will not exit until all sessions are gone, but in itself prevents
the session from exiting.

src/login/logind-user.c
src/login/sd-login.c

index a6672ce670acd7180bec825de3c3766cc9c1d8a3..9dfead9d5d706213d690b4f66e3dda34fdfbe016 100644 (file)
@@ -180,6 +180,20 @@ int user_save(User *u) {
                         fputs(i->id, f);
                 }
 
+                fputs("\nONLINE_SESSIONS=", f);
+                first = true;
+                LIST_FOREACH(sessions_by_user, i, u->sessions) {
+                        if (session_get_state(i) == SESSION_CLOSING)
+                                continue;
+
+                        if (first)
+                                first = false;
+                        else
+                                fputc(' ', f);
+
+                        fputs(i->id, f);
+                }
+
                 fputs("\nACTIVE_SEATS=", f);
                 first = true;
                 LIST_FOREACH(sessions_by_user, i, u->sessions) {
@@ -193,6 +207,20 @@ int user_save(User *u) {
 
                         fputs(i->seat->id, f);
                 }
+
+                fputs("\nONLINE_SEATS=", f);
+                first = true;
+                LIST_FOREACH(sessions_by_user, i, u->sessions) {
+                        if (session_get_state(i) == SESSION_CLOSING || !i->seat)
+                                continue;
+
+                        if (first)
+                                first = false;
+                        else
+                                fputc(' ', f);
+
+                        fputs(i->seat->id, f);
+                }
                 fputc('\n', f);
         }
 
index 1978a05dc02809e887c7330d425bb06b1c5b4f6e..88dd510870015952a0a46b9112afbbcb25737c74 100644 (file)
@@ -259,11 +259,11 @@ 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 == 2 ? "ONLINE_SESSIONS" : (require_active ? "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 == 2 ? "ONLINE_SEATS" : (require_active ? "ACTIVE_SEATS" : "SEATS"), seats);
 }
 
 static int file_of_session(const char *session, char **_p) {