[systemd-commits] 9 commits - TODO man/sd_uid_get_state.xml src/login src/shared src/test

Lennart Poettering lennart at kemper.freedesktop.org
Tue Sep 11 23:31:16 PDT 2012


 TODO                       |   12 ++++++++++++
 man/sd_uid_get_state.xml   |   17 +++++++++--------
 src/login/logind-seat.c    |    3 ++-
 src/login/logind-session.c |    5 +++++
 src/login/logind-user.c    |   41 ++++++++++++++++++++++++++++++++++++++---
 src/login/pam-module.c     |    4 ++--
 src/login/sd-login.c       |   14 ++++++++++++--
 src/shared/unit-name.c     |   35 ++++++++++++++---------------------
 src/test/test-unit-name.c  |   44 ++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 138 insertions(+), 37 deletions(-)

New commits:
commit 1b2ac6b3116877068570f1d8da5e0a83a0acf7ad
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Sep 12 08:31:08 2012 +0200

    test: extend unit-name test a bit

diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index cf43455..50187e1 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -53,6 +53,26 @@ int main(int argc, char* argv[]) {
         puts(t);
         free(t);
 
+        t = unit_name_replace_instance(".service", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("foo at bar", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("foo@", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("@", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("@bar", "waldo");
+        puts(t);
+        free(t);
+
         t = unit_name_from_path("/waldo", ".mount");
         puts(t);
         k = unit_name_to_path(t);

commit d18dff430bf60291a41b2c7dbe0ae5a5c4edf36c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Sep 12 08:30:35 2012 +0200

    login: reshuffle meaning of require_active parameter

diff --git a/man/sd_uid_get_state.xml b/man/sd_uid_get_state.xml
index b9b713c..183e8a6 100644
--- a/man/sd_uid_get_state.xml
+++ b/man/sd_uid_get_state.xml
@@ -111,7 +111,7 @@
                 or active on a specific seat. Accepts a Unix user
                 identifier and a seat identifier string as
                 parameters. The <parameter>require_active</parameter>
-                parameter is a boolean. If non-zero (true) this
+                parameter is a boolean value. If non-zero (true) this
                 function will test if the user is active (i.e. has a
                 session that is in the foreground and accepting user
                 input) on the specified seat, otherwise (false) only
@@ -122,13 +122,14 @@
                 be used to determine the current sessions of the
                 specified user. Acceptes a Unix user identifier as
                 parameter. The <parameter>require_active</parameter>
-                boolean parameter controls whether the returned list
-                shall consist of only those sessions where the user is
-                currently active (true) or where the user is currently
-                logged in at all, possibly inactive (false). The call
-                returns a NULL terminated string array of session
-                identifiers in <parameter>sessions</parameter> which
-                needs to be freed by the caller with the libc
+                parameter controls whether the returned list shall
+                consist of only those sessions where the user is
+                currently active (> 0), where the user is currently
+                online but possibly inactive (= 0), or
+                logged in at all but possibly closing the session (< 0). The call returns a
+                NULL terminated string array of session identifiers in
+                <parameter>sessions</parameter> which needs to be
+                freed by the caller with the libc
                 <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 call after use, including all the strings
                 referenced. If the string array parameter is passed as
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 88dd510..82fe2ce 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -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 == 2 ? "ONLINE_SESSIONS" : (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 == 2 ? "ONLINE_SEATS" : (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) {

commit 78ab361c8f5f5d7614b5bf98b92f3aec4183bfb7
Author: Colin Guthrie <colin at mageia.org>
Date:   Tue Sep 4 01:37:28 2012 +0100

    logind: Avoid unnecesary rewrite of user file when switching sessions of the same user.

diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index 937315e..c2cf6e5 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -263,7 +263,8 @@ int seat_set_active(Seat *s, Session *session) {
 
         if (old_active) {
                 session_save(old_active);
-                user_save(old_active->user);
+                if (!session || session->user != old_active->user)
+                        user_save(old_active->user);
         }
 
         return 0;

commit 23bd3b6263e4fd9c15cfb6c05e65fa425791374c
Author: Colin Guthrie <colin at mageia.org>
Date:   Tue Sep 4 01:37:27 2012 +0100

    logind: Ensure the user, seat and session files are updated when the session is closing.

diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 77462a8..9740e23 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -714,9 +714,11 @@ int session_stop(Session *s) {
                         seat_set_active(s->seat, NULL);
 
                 seat_send_changed(s->seat, "Sessions\0");
+                seat_save(s->seat);
         }
 
         user_send_changed(s->user, "Sessions\0");
+        user_save(s->user);
 
         s->started = false;
 
@@ -870,6 +872,9 @@ void session_remove_fifo(Session *s) {
                 assert_se(epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_DEL, s->fifo_fd, NULL) == 0);
                 close_nointr_nofail(s->fifo_fd);
                 s->fifo_fd = -1;
+
+                session_save(s);
+                user_save(s->user);
         }
 
         if (s->fifo_path) {

commit 2dc8f41a2bdcc25e6ec69a99cb6f34615cce59a5
Author: Colin Guthrie <colin at mageia.org>
Date:   Mon Sep 3 23:57:58 2012 +0100

    logind: Add a two new variables to the user session tracking file.
    
    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.

diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index a6672ce..9dfead9 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -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);
         }
 
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 1978a05..88dd510 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -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) {

commit 47acb2f15f2319ec0fc341a4271d45067da2ed24
Author: Colin Guthrie <colin at mageia.org>
Date:   Mon Sep 3 23:47:02 2012 +0100

    logind: Properly list the ACTIVE_SEATS in the user session tracking file.
    
    Prevsiouly the first active seat for a user would never be listed and
    any subsequent seats would be concatenated on without any spaces.

diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index a33978c..a6672ce 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -189,7 +189,9 @@ int user_save(User *u) {
                         if (first)
                                 first = false;
                         else
-                                fputs(i->seat->id, f);
+                                fputc(' ', f);
+
+                        fputs(i->seat->id, f);
                 }
                 fputc('\n', f);
         }

commit c9caad802128a5dc599342c1400a61f31e8b17b5
Author: Colin Guthrie <colin at mageia.org>
Date:   Mon Sep 3 23:47:01 2012 +0100

    logind: If all user sessions are in closing state, set the overall status to closing.
    
    PulseAudio for example will keep a client connection open provided
    at least one session exists. However, if all sessions are currently
    in the process of closing, we should flag that as the overall state
    appropriately to better reflect what is happening.
    
    Although this does better reflect the status for any given user, it does
    not actually solve the overall problem of PulseAudio still finding some
    sessions active and thus not exiting and therefore actually preventing
    the session from closing. Future commits will extend sd-login to cope
    with this situation.

diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index aa9c3f1..a33978c 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -568,15 +568,20 @@ void user_add_to_gc_queue(User *u) {
 
 UserState user_get_state(User *u) {
         Session *i;
+        bool all_closing = true;
 
         assert(u);
 
-        LIST_FOREACH(sessions_by_user, i, u->sessions)
+
+        LIST_FOREACH(sessions_by_user, i, u->sessions) {
                 if (session_is_active(i))
                         return USER_ACTIVE;
+                if (session_get_state(i) != SESSION_CLOSING)
+                        all_closing = false;
+        }
 
         if (u->sessions)
-                return USER_ONLINE;
+                return all_closing ? USER_CLOSING : USER_ONLINE;
 
         if (user_check_linger_file(u) > 0)
                 return USER_LINGERING;

commit f904bdf2e9f6f858802489ab07ff070d4677bccb
Author: Colin Guthrie <colin at mageia.org>
Date:   Mon Sep 3 23:47:00 2012 +0100

    pam: Add session class to the debug log.

diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 0727164..d7f4128 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -517,8 +517,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
         if (debug)
                 pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: "
-                           "uid=%u pid=%u service=%s type=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s",
-                           uid, pid, service, type, seat, vtnr, tty, display, yes_no(remote), remote_user, remote_host);
+                           "uid=%u pid=%u service=%s type=%s class=%s seat=%s vtnr=%u tty=%s display=%s remote=%s remote_user=%s remote_host=%s",
+                           uid, pid, service, type, class, seat, vtnr, tty, display, yes_no(remote), remote_user, remote_host);
 
         reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
         if (!reply) {

commit 8556879e0d14925ce897875c6c264368e2d048c2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Sep 12 04:46:38 2012 +0200

    unit-name: rework unit_name_replace_instance function()
    
    https://bugzilla.redhat.com/show_bug.cgi?id=855863

diff --git a/TODO b/TODO
index 4371c73..2917068 100644
--- a/TODO
+++ b/TODO
@@ -49,6 +49,18 @@ Bugfixes:
 
 Features:
 
+* perfomance messages for selinux are gone from debug log?
+
+* http://lists.freedesktop.org/archives/systemd-devel/2012-September/006502.html
+
+* don't use writev() in tmpfiles for sake of compat with sysfs?
+
+* come up with a nice way to write queue/read_ahead_kb for a block device without interfering with readahead
+
+* journald: add kernel cmdline option to disable ratelimiting for debug purposes
+
+* Add a way to reference the machine/boot ID from ExecStart= and similar command lines
+
 * move PID 1 segfaults to /var/lib/systemd/coredump?
 
 * Document word splitting syntax for ExecStart= and friends
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 7193718..d639122 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -357,36 +357,29 @@ bool unit_name_is_instance(const char *n) {
 char *unit_name_replace_instance(const char *f, const char *i) {
         const char *p, *e;
         char *r, *k;
-        size_t a;
+        size_t a, b;
 
         assert(f);
 
         p = strchr(f, '@');
-        assert_se(e = strrchr(f, '.'));
-
-        a = p - f;
-
-        if (p) {
-                size_t b;
-
-                b = strlen(i);
-
-                r = new(char, a + 1 + b + strlen(e) + 1);
-                if (!r)
-                        return NULL;
+        if (!p)
+                return strdup(f);
 
-                k = mempcpy(r, f, a + 1);
-                k = mempcpy(k, i, b);
-        } else {
+        e = strrchr(f, '.');
+        if (!e)
+                assert_se(e = strchr(f, 0));
 
-                r = new(char, a + strlen(e) + 1);
-                if (!r)
-                        return NULL;
+        a = p - f;
+        b = strlen(i);
 
-                k = mempcpy(r, f, a);
-        }
+        r = new(char, a + 1 + b + strlen(e) + 1);
+        if (!r)
+                return NULL;
 
+        k = mempcpy(r, f, a + 1);
+        k = mempcpy(k, i, b);
         strcpy(k, e);
+
         return r;
 }
 
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 392e358..cf43455 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -29,6 +29,30 @@
 int main(int argc, char* argv[]) {
         char *t, *k;
 
+        t = unit_name_replace_instance("foo at .service", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("foo at xyz.service", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("xyz", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("", "waldo");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("", "");
+        puts(t);
+        free(t);
+
+        t = unit_name_replace_instance("foo.service", "waldo");
+        puts(t);
+        free(t);
+
         t = unit_name_from_path("/waldo", ".mount");
         puts(t);
         k = unit_name_to_path(t);



More information about the systemd-commits mailing list