]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind-session: be more specific about session_kill() errors 35150/head
authorMike Yuan <me@yhndnzj.com>
Wed, 13 Nov 2024 16:41:14 +0000 (17:41 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 13 Nov 2024 16:49:07 +0000 (17:49 +0100)
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
src/login/logind-session.c
src/login/logind-session.h

index cc2d581bc5bd7a6f0603fa2a53cb0f4ac9edd88c..5300284e5ac6b0315ee1519acaa53fe61a97de4d 100644 (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;
 
index 26ed2d3e491c3900689ccc97bc21e838eae8965c..351b64b60bba83e984355270c4677ae52cc72426 100644 (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 (!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);
index 86ffc64bdaad7b5046519abb7d3cd2e71b8e4737..2d2cb189fca6bd28ae6aae325f8cba939eb9e45e 100644 (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);