[systemd-devel] [PATCH] logind: always kill session when termination is requested

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Feb 8 17:48:13 PST 2014


KillUserProcesses=yes/no should be ignored when termination is
explicitly requested.
---
This goes on top of
* logind: use session_get_state() to get sessions state of the user                                
* logind: just call user_stop() if user_check_gc() returns false                                   

With this patch loginctl terminate-user/session work for me.

Zbyszek

 src/login/logind-dbus.c         |  6 +++---
 src/login/logind-seat-dbus.c    |  2 +-
 src/login/logind-seat.c         |  8 ++++----
 src/login/logind-seat.h         |  4 ++--
 src/login/logind-session-dbus.c |  2 +-
 src/login/logind-session.c      | 12 ++++++------
 src/login/logind-session.h      |  2 +-
 src/login/logind-user-dbus.c    |  2 +-
 src/login/logind-user.c         |  4 ++--
 src/login/logind-user.h         |  2 +-
 src/login/logind.c              |  6 +++---
 11 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index d671346..bd0de33 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -939,7 +939,7 @@ static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *
         if (!session)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
 
-        r = session_stop(session);
+        r = session_stop(session, true);
         if (r < 0)
                 return r;
 
@@ -964,7 +964,7 @@ static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *use
         if (!user)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
 
-        r = user_stop(user);
+        r = user_stop(user, true);
         if (r < 0)
                 return r;
 
@@ -989,7 +989,7 @@ static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *use
         if (!seat)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
 
-        r = seat_stop_sessions(seat);
+        r = seat_stop_sessions(seat, true);
         if (r < 0)
                 return r;
 
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 909007c..26cddfe 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -201,7 +201,7 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
         assert(message);
         assert(s);
 
-        r = seat_stop_sessions(s);
+        r = seat_stop_sessions(s, true);
         if (r < 0)
                 return r;
 
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index c7f112a..631be5f 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -418,7 +418,7 @@ int seat_start(Seat *s) {
         return 0;
 }
 
-int seat_stop(Seat *s) {
+int seat_stop(Seat *s, bool force) {
         int r = 0;
 
         assert(s);
@@ -430,7 +430,7 @@ int seat_stop(Seat *s) {
                            "MESSAGE=Removed seat %s.", s->id,
                            NULL);
 
-        seat_stop_sessions(s);
+        seat_stop_sessions(s, force);
 
         unlink(s->state_file);
         seat_add_to_gc_queue(s);
@@ -443,14 +443,14 @@ int seat_stop(Seat *s) {
         return r;
 }
 
-int seat_stop_sessions(Seat *s) {
+int seat_stop_sessions(Seat *s, bool force) {
         Session *session;
         int r = 0, k;
 
         assert(s);
 
         LIST_FOREACH(sessions_by_seat, session, s->sessions) {
-                k = session_stop(session);
+                k = session_stop(session, force);
                 if (k < 0)
                         r = k;
         }
diff --git a/src/login/logind-seat.h b/src/login/logind-seat.h
index 9e21e3a..9e469d4 100644
--- a/src/login/logind-seat.h
+++ b/src/login/logind-seat.h
@@ -80,8 +80,8 @@ bool seat_can_graphical(Seat *s);
 int seat_get_idle_hint(Seat *s, dual_timestamp *t);
 
 int seat_start(Seat *s);
-int seat_stop(Seat *s);
-int seat_stop_sessions(Seat *s);
+int seat_stop(Seat *s, bool force);
+int seat_stop_sessions(Seat *s, bool force);
 
 bool seat_check_gc(Seat *s, bool drop_not_started);
 void seat_add_to_gc_queue(Seat *s);
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index 7ee4956..f9305dd 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -188,7 +188,7 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
         assert(message);
         assert(s);
 
-        r = session_stop(s);
+        r = session_stop(s, true);
         if (r < 0)
                 return r;
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index f661cc8..d4742e1 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -565,7 +565,7 @@ int session_start(Session *s) {
         return 0;
 }
 
-static int session_stop_scope(Session *s) {
+static int session_stop_scope(Session *s, bool force) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         char *job;
         int r;
@@ -575,7 +575,7 @@ static int session_stop_scope(Session *s) {
         if (!s->scope)
                 return 0;
 
-        if (manager_shall_kill(s->manager, s->user->name)) {
+        if (force || manager_shall_kill(s->manager, s->user->name)) {
                 r = manager_stop_unit(s->manager, s->scope, &error, &job);
                 if (r < 0) {
                         log_error("Failed to stop session scope: %s", bus_error_message(&error, r));
@@ -595,7 +595,7 @@ static int session_stop_scope(Session *s) {
         return 0;
 }
 
-int session_stop(Session *s) {
+int session_stop(Session *s, bool force) {
         int r;
 
         assert(s);
@@ -609,7 +609,7 @@ int session_stop(Session *s) {
         session_remove_fifo(s);
 
         /* Kill cgroup */
-        r = session_stop_scope(s);
+        r = session_stop_scope(s, force);
 
         s->stopping = true;
 
@@ -672,7 +672,7 @@ static int release_timeout_callback(sd_event_source *es, uint64_t usec, void *us
         assert(es);
         assert(s);
 
-        session_stop(s);
+        session_stop(s, false);
         return 0;
 }
 
@@ -812,7 +812,7 @@ static int session_dispatch_fifo(sd_event_source *es, int fd, uint32_t revents,
         /* EOF on the FIFO means the session died abnormally. */
 
         session_remove_fifo(s);
-        session_stop(s);
+        session_stop(s, false);
 
         return 1;
 }
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index 42552bc..c9af5eb 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -136,7 +136,7 @@ int session_get_idle_hint(Session *s, dual_timestamp *t);
 void session_set_idle_hint(Session *s, bool b);
 int session_create_fifo(Session *s);
 int session_start(Session *s);
-int session_stop(Session *s);
+int session_stop(Session *s, bool force);
 int session_finalize(Session *s);
 void session_release(Session *s);
 int session_save(Session *s);
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 2d49b8b..18eea89 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -180,7 +180,7 @@ static int method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata
         assert(message);
         assert(u);
 
-        r = user_stop(u);
+        r = user_stop(u, true);
         if (r < 0)
                 return r;
 
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 2a11bab..a1e35b2 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -494,13 +494,13 @@ static int user_remove_runtime_path(User *u) {
         return r;
 }
 
-int user_stop(User *u) {
+int user_stop(User *u, bool force) {
         Session *s;
         int r = 0, k;
         assert(u);
 
         LIST_FOREACH(sessions_by_user, s, u->sessions) {
-                k = session_stop(s);
+                k = session_stop(s, force);
                 if (k < 0)
                         r = k;
         }
diff --git a/src/login/logind-user.h b/src/login/logind-user.h
index b0fefe9..f237d2a 100644
--- a/src/login/logind-user.h
+++ b/src/login/logind-user.h
@@ -72,7 +72,7 @@ void user_free(User *u);
 bool user_check_gc(User *u, bool drop_not_started);
 void user_add_to_gc_queue(User *u);
 int user_start(User *u);
-int user_stop(User *u);
+int user_stop(User *u, bool force);
 int user_finalize(User *u);
 UserState user_get_state(User *u);
 int user_get_idle_hint(User *u, dual_timestamp *t);
diff --git a/src/login/logind.c b/src/login/logind.c
index 84c5b7d..d68eda6 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -862,7 +862,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
                 seat->in_gc_queue = false;
 
                 if (!seat_check_gc(seat, drop_not_started)) {
-                        seat_stop(seat);
+                        seat_stop(seat, false);
                         seat_free(seat);
                 }
         }
@@ -874,7 +874,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
                 /* First, if we are not closing yet, initiate stopping */
                 if (!session_check_gc(session, drop_not_started) &&
                     session_get_state(session) != SESSION_CLOSING)
-                        session_stop(session);
+                        session_stop(session, false);
 
                 /* Normally, this should make the session busy again,
                  * if it doesn't then let's get rid of it
@@ -890,7 +890,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
                 user->in_gc_queue = false;
 
                 if (!user_check_gc(user, drop_not_started)) {
-                        user_stop(user);
+                        user_stop(user, false);
                         user_finalize(user);
                         user_free(user);
                 }
-- 
1.8.5.3



More information about the systemd-devel mailing list