From: Zbigniew Jędrzejewski-Szmek Date: Sun, 9 Feb 2014 01:29:56 +0000 (-0500) Subject: logind: always kill session when termination is requested X-Git-Tag: v209~179 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=9bb69af4f2823fdd30902f5ffd959e9b041feb53;hp=4daf54a851e4fb7ed1a13c3117bba12528fd2c7f logind: always kill session when termination is requested KillUserProcesses=yes/no should be ignored when termination is explicitly requested. --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 7e96a04ca..08e53c369 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 909007c30..26cddfea7 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 c7f112afb..631be5f74 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 9e21e3a8a..9e469d41c 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 7ee49562c..f9305ddbe 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 f661cc8b8..d4742e113 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 42552bc2b..c9af5ebe0 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 2d49b8b96..18eea8970 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 06fdbb36f..ac4a651f3 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 b0fefe9b9..f237d2a6b 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 a6f84e853..554409926 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 @@ -891,7 +891,7 @@ void manager_gc(Manager *m, bool drop_not_started) { if (!user_check_gc(user, drop_not_started) && user_get_state(user) != USER_CLOSING) - user_stop(user); + user_stop(user, false); if (!user_check_gc(user, drop_not_started)) { user_finalize(user);