84b277
From c4e4ad079d6c3c18b6f08722ce30796e8c53346b Mon Sep 17 00:00:00 2001
84b277
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
84b277
Date: Sat, 8 Feb 2014 20:29:56 -0500
84b277
Subject: [PATCH] logind: always kill session when termination is requested
84b277
84b277
KillUserProcesses=yes/no should be ignored when termination is
84b277
explicitly requested.
84b277
84b277
Conflicts:
84b277
	src/login/logind-dbus.c
84b277
	src/login/logind-seat-dbus.c
84b277
	src/login/logind-session-dbus.c
84b277
	src/login/logind-session.c
84b277
	src/login/logind-user-dbus.c
84b277
	src/login/logind.c
84b277
84b277
(cherry-picked (or better say rewritten) from 9bb69af4f2823fdd30902f5ffd959e9b041feb53)
84b277
84b277
Resolves: #1155502
84b277
---
84b277
 src/login/logind-dbus.c         |  6 +++---
84b277
 src/login/logind-seat-dbus.c    |  2 +-
84b277
 src/login/logind-seat.c         |  8 ++++----
84b277
 src/login/logind-seat.h         |  4 ++--
84b277
 src/login/logind-session-dbus.c |  2 +-
84b277
 src/login/logind-session.c      |  8 ++++----
84b277
 src/login/logind-session.h      |  2 +-
84b277
 src/login/logind-user-dbus.c    |  2 +-
84b277
 src/login/logind-user.c         |  4 ++--
84b277
 src/login/logind-user.h         |  2 +-
84b277
 src/login/logind.c              | 10 +++++-----
84b277
 11 files changed, 25 insertions(+), 25 deletions(-)
84b277
84b277
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
84b277
index 4137522..8a463f9 100644
84b277
--- a/src/login/logind-dbus.c
84b277
+++ b/src/login/logind-dbus.c
84b277
@@ -1927,7 +1927,7 @@ static DBusHandlerResult manager_message_handler(
84b277
                 if (!session)
84b277
                         return bus_send_error_reply(connection, message, &error, -ENOENT);
84b277
 
84b277
-                r = session_stop(session);
84b277
+                r = session_stop(session, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
@@ -1950,7 +1950,7 @@ static DBusHandlerResult manager_message_handler(
84b277
                 if (!user)
84b277
                         return bus_send_error_reply(connection, message, &error, -ENOENT);
84b277
 
84b277
-                r = user_stop(user);
84b277
+                r = user_stop(user, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
@@ -1973,7 +1973,7 @@ static DBusHandlerResult manager_message_handler(
84b277
                 if (!seat)
84b277
                         return bus_send_error_reply(connection, message, &error, -ENOENT);
84b277
 
84b277
-                r = seat_stop_sessions(seat);
84b277
+                r = seat_stop_sessions(seat, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
84b277
index 230f7f0..c87c1de 100644
84b277
--- a/src/login/logind-seat-dbus.c
84b277
+++ b/src/login/logind-seat-dbus.c
84b277
@@ -261,7 +261,7 @@ static DBusHandlerResult seat_message_dispatch(
84b277
 
84b277
         if (dbus_message_is_method_call(message, "org.freedesktop.login1.Seat", "Terminate")) {
84b277
 
84b277
-                r = seat_stop_sessions(s);
84b277
+                r = seat_stop_sessions(s, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
84b277
index feebcf4..d3b999d 100644
84b277
--- a/src/login/logind-seat.c
84b277
+++ b/src/login/logind-seat.c
84b277
@@ -369,7 +369,7 @@ int seat_start(Seat *s) {
84b277
         return 0;
84b277
 }
84b277
 
84b277
-int seat_stop(Seat *s) {
84b277
+int seat_stop(Seat *s, bool force) {
84b277
         int r = 0;
84b277
 
84b277
         assert(s);
84b277
@@ -381,7 +381,7 @@ int seat_stop(Seat *s) {
84b277
                            "MESSAGE=Removed seat %s.", s->id,
84b277
                            NULL);
84b277
 
84b277
-        seat_stop_sessions(s);
84b277
+        seat_stop_sessions(s, force);
84b277
 
84b277
         unlink(s->state_file);
84b277
         seat_add_to_gc_queue(s);
84b277
@@ -394,14 +394,14 @@ int seat_stop(Seat *s) {
84b277
         return r;
84b277
 }
84b277
 
84b277
-int seat_stop_sessions(Seat *s) {
84b277
+int seat_stop_sessions(Seat *s, bool force) {
84b277
         Session *session;
84b277
         int r = 0, k;
84b277
 
84b277
         assert(s);
84b277
 
84b277
         LIST_FOREACH(sessions_by_seat, session, s->sessions) {
84b277
-                k = session_stop(session);
84b277
+                k = session_stop(session, force);
84b277
                 if (k < 0)
84b277
                         r = k;
84b277
         }
84b277
diff --git a/src/login/logind-seat.h b/src/login/logind-seat.h
84b277
index be6db6e..bf496b3 100644
84b277
--- a/src/login/logind-seat.h
84b277
+++ b/src/login/logind-seat.h
84b277
@@ -72,8 +72,8 @@ bool seat_can_graphical(Seat *s);
84b277
 int seat_get_idle_hint(Seat *s, dual_timestamp *t);
84b277
 
84b277
 int seat_start(Seat *s);
84b277
-int seat_stop(Seat *s);
84b277
-int seat_stop_sessions(Seat *s);
84b277
+int seat_stop(Seat *s, bool force);
84b277
+int seat_stop_sessions(Seat *s, bool force);
84b277
 
84b277
 int seat_check_gc(Seat *s, bool drop_not_started);
84b277
 void seat_add_to_gc_queue(Seat *s);
84b277
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
84b277
index 86b0746..76e16e7 100644
84b277
--- a/src/login/logind-session-dbus.c
84b277
+++ b/src/login/logind-session-dbus.c
84b277
@@ -311,7 +311,7 @@ static DBusHandlerResult session_message_dispatch(
84b277
 
84b277
         if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Terminate")) {
84b277
 
84b277
-                r = session_stop(s);
84b277
+                r = session_stop(s, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
84b277
index 0fa290b..669a027 100644
84b277
--- a/src/login/logind-session.c
84b277
+++ b/src/login/logind-session.c
84b277
@@ -609,7 +609,7 @@ int session_start(Session *s) {
84b277
         return 0;
84b277
 }
84b277
 
84b277
-static int session_stop_scope(Session *s) {
84b277
+static int session_stop_scope(Session *s, bool force) {
84b277
         DBusError error;
84b277
         char *job;
84b277
         int r;
84b277
@@ -621,7 +621,7 @@ static int session_stop_scope(Session *s) {
84b277
         if (!s->scope)
84b277
                 return 0;
84b277
 
84b277
-        if (manager_shall_kill(s->manager, s->user->name)) {
84b277
+        if (force || manager_shall_kill(s->manager, s->user->name)) {
84b277
                 r = manager_stop_unit(s->manager, s->scope, &error, &job;;
84b277
                 if (r < 0) {
84b277
                         log_error("Failed to stop session scope: %s", bus_error(&error, r));
84b277
@@ -676,7 +676,7 @@ static void session_close_timer_fd(Session *s) {
84b277
         s->timer_fd = -1;
84b277
 }
84b277
 
84b277
-int session_stop(Session *s) {
84b277
+int session_stop(Session *s, bool force) {
84b277
         int r;
84b277
 
84b277
         assert(s);
84b277
@@ -690,7 +690,7 @@ int session_stop(Session *s) {
84b277
         session_remove_fifo(s);
84b277
 
84b277
         /* Kill cgroup */
84b277
-        r = session_stop_scope(s);
84b277
+        r = session_stop_scope(s, force);
84b277
 
84b277
         s->stopping = true;
84b277
 
84b277
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
84b277
index 9b76582..3659872 100644
84b277
--- a/src/login/logind-session.h
84b277
+++ b/src/login/logind-session.h
84b277
@@ -131,7 +131,7 @@ void session_set_idle_hint(Session *s, bool b);
84b277
 int session_create_fifo(Session *s);
84b277
 void session_remove_fifo(Session *s);
84b277
 int session_start(Session *s);
84b277
-int session_stop(Session *s);
84b277
+int session_stop(Session *s, bool force);
84b277
 int session_finalize(Session *s);
84b277
 void session_release(Session *s);
84b277
 int session_save(Session *s);
84b277
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
84b277
index fa2ecba..72dd5d0 100644
84b277
--- a/src/login/logind-user-dbus.c
84b277
+++ b/src/login/logind-user-dbus.c
84b277
@@ -242,7 +242,7 @@ static DBusHandlerResult user_message_dispatch(
84b277
 
84b277
         if (dbus_message_is_method_call(message, "org.freedesktop.login1.User", "Terminate")) {
84b277
 
84b277
-                r = user_stop(u);
84b277
+                r = user_stop(u, true);
84b277
                 if (r < 0)
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
 
84b277
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
84b277
index 653574e..6ddda54 100644
84b277
--- a/src/login/logind-user.c
84b277
+++ b/src/login/logind-user.c
84b277
@@ -466,13 +466,13 @@ static int user_remove_runtime_path(User *u) {
84b277
         return r;
84b277
 }
84b277
 
84b277
-int user_stop(User *u) {
84b277
+int user_stop(User *u, bool force) {
84b277
         Session *s;
84b277
         int r = 0, k;
84b277
         assert(u);
84b277
 
84b277
         LIST_FOREACH(sessions_by_user, s, u->sessions) {
84b277
-                k = session_stop(s);
84b277
+                k = session_stop(s, force);
84b277
                 if (k < 0)
84b277
                         r = k;
84b277
         }
84b277
diff --git a/src/login/logind-user.h b/src/login/logind-user.h
84b277
index a12532e..13513fa 100644
84b277
--- a/src/login/logind-user.h
84b277
+++ b/src/login/logind-user.h
84b277
@@ -72,7 +72,7 @@ void user_free(User *u);
84b277
 int user_check_gc(User *u, bool drop_not_started);
84b277
 void user_add_to_gc_queue(User *u);
84b277
 int user_start(User *u);
84b277
-int user_stop(User *u);
84b277
+int user_stop(User *u, bool force);
84b277
 int user_finalize(User *u);
84b277
 UserState user_get_state(User *u);
84b277
 int user_get_idle_hint(User *u, dual_timestamp *t);
84b277
diff --git a/src/login/logind.c b/src/login/logind.c
84b277
index 5180be7..da3c099 100644
84b277
--- a/src/login/logind.c
84b277
+++ b/src/login/logind.c
84b277
@@ -618,14 +618,14 @@ static void manager_dispatch_other(Manager *m, int fd) {
84b277
         if (s) {
84b277
                 assert(s->fifo_fd == fd);
84b277
                 session_remove_fifo(s);
84b277
-                session_stop(s);
84b277
+                session_stop(s, false);
84b277
                 return;
84b277
         }
84b277
 
84b277
         s = hashmap_get(m->timer_fds, INT_TO_PTR(fd + 1));
84b277
         if (s) {
84b277
                 assert(s->timer_fd == fd);
84b277
-                session_stop(s);
84b277
+                session_stop(s, false);
84b277
                 return;
84b277
         }
84b277
 
84b277
@@ -942,7 +942,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
84b277
                 seat->in_gc_queue = false;
84b277
 
84b277
                 if (seat_check_gc(seat, drop_not_started) == 0) {
84b277
-                        seat_stop(seat);
84b277
+                        seat_stop(seat, false);
84b277
                         seat_free(seat);
84b277
                 }
84b277
         }
84b277
@@ -954,7 +954,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
84b277
                 /* First, if we are not closing yet, initiate stopping */
84b277
                 if (!session_check_gc(session, drop_not_started) &&
84b277
                     session_get_state(session) != SESSION_CLOSING)
84b277
-                        session_stop(session);
84b277
+                        session_stop(session, false);
84b277
 
84b277
                 if (!session_check_gc(session, drop_not_started)) {
84b277
                         session_finalize(session);
84b277
@@ -968,7 +968,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
84b277
 
84b277
                 if (!user_check_gc(user, drop_not_started) &&
84b277
                     user_get_state(user) != USER_CLOSING)
84b277
-                        user_stop(user);
84b277
+                        user_stop(user, false);
84b277
 
84b277
                 if (!user_check_gc(user, drop_not_started)) {
84b277
                         user_finalize(user);