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.
This commit is contained in:
Mike Yuan
2024-11-13 17:49:07 +01:00
parent 2f2058da0b
commit 9c6dc69f3e
3 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -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;
+8 -4
View File
@@ -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 (!s->scope)
return -ESRCH;
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);
return manager_kill_unit(s->manager, s->scope, KILL_ALL, signo, NULL);
if (!s->scope)
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, error);
case KILL_LEADER:
return pidref_kill(&s->leader, signo);
+1 -1
View File
@@ -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);