From 9c6dc69f3e3d338148e0bf6e19b9d0107856ac26 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 13 Nov 2024 17:41:14 +0100 Subject: [PATCH] logind-session: be more specific about session_kill() errors When kill_whom == _ALL, there can be two cases that lead to ESRCH: the session expects no scope at all or the scope is not active. Let's distinguish the two cases. --- src/login/logind-session-dbus.c | 2 +- src/login/logind-session.c | 10 +++++++--- src/login/logind-session.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index cc2d581bc5b..5300284e5ac 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -360,7 +360,7 @@ int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_erro if (r == 0) return 1; /* Will call us back */ - r = session_kill(s, whom, signo); + r = session_kill(s, whom, signo, error); if (r < 0) return r; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 26ed2d3e491..351b64b60bb 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -1387,16 +1387,20 @@ SessionState session_get_state(Session *s) { return SESSION_ONLINE; } -int session_kill(Session *s, KillWhom whom, int signo) { +int session_kill(Session *s, KillWhom whom, int signo, sd_bus_error *error) { assert(s); switch (whom) { case KILL_ALL: + if (!SESSION_CLASS_WANTS_SCOPE(s->class)) + return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, + "Session '%s' has no associated scope", s->id); + if (!s->scope) - return -ESRCH; + return sd_bus_error_set_errnof(error, ESRCH, "Scope for session '%s' not active", s->id); - return manager_kill_unit(s->manager, s->scope, KILL_ALL, signo, NULL); + return manager_kill_unit(s->manager, s->scope, KILL_ALL, signo, error); case KILL_LEADER: return pidref_kill(&s->leader, signo); diff --git a/src/login/logind-session.h b/src/login/logind-session.h index 86ffc64bdaa..2d2cb189fca 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -191,7 +191,7 @@ int session_finalize(Session *s); int session_release(Session *s); int session_save(Session *s); int session_load(Session *s); -int session_kill(Session *s, KillWhom whom, int signo); +int session_kill(Session *s, KillWhom whom, int signo, sd_bus_error *error); SessionState session_get_state(Session *u); -- 2.47.3