[systemd-commits] src/login

Lennart Poettering lennart at kemper.freedesktop.org
Fri Feb 7 07:34:47 PST 2014


 src/login/logind-dbus.c |   46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

New commits:
commit 99e7e3922e1d25d0092bd61444c86dcc9a1e030e
Author: Djalal Harouni <tixxdz at opendz.org>
Date:   Thu Feb 6 21:37:14 2014 +0100

    logind: add function session_jobs_reply() to unify the create reply
    
    The session_send_create_reply() function which notifies clients about
    session creation is used for both session and user units. Unify the
    shared code in a new function session_jobs_reply().
    
    The session_save() will be called unconditionally on sessions since it
    does not make sense to only call it if '!session->started', this will
    also allow to update the session state as soon as possible.

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 642ba07..28b5cd4 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -1911,6 +1911,27 @@ const sd_bus_vtable manager_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
+static int session_jobs_reply(Session *s, const char *unit, const char *result) {
+        int r = 0;
+
+        assert(s);
+        assert(unit);
+
+        if (!s->started)
+                return r;
+
+        if (streq(result, "done"))
+                r = session_send_create_reply(s, NULL);
+        else {
+                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
+
+                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
+                r = session_send_create_reply(s, &e);
+        }
+
+        return r;
+}
+
 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
         const char *path, *result, *unit;
         Manager *m = userdata;
@@ -1950,18 +1971,9 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_b
                         session->scope_job = NULL;
                 }
 
-                if (session->started) {
-                        if (streq(result, "done"))
-                                session_send_create_reply(session, NULL);
-                        else {
-                                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
-
-                                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
-                                session_send_create_reply(session, &e);
-                        }
-                } else
-                        session_save(session);
+                session_jobs_reply(session, unit, result);
 
+                session_save(session);
                 session_add_to_gc_queue(session);
         }
 
@@ -1979,17 +1991,7 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_b
                 }
 
                 LIST_FOREACH(sessions_by_user, session, user->sessions) {
-                        if (!session->started)
-                                continue;
-
-                        if (streq(result, "done"))
-                                session_send_create_reply(session, NULL);
-                        else {
-                                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
-
-                                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
-                                session_send_create_reply(session, &e);
-                        }
+                        session_jobs_reply(session, unit, result);
                 }
 
                 user_save(user);



More information about the systemd-commits mailing list