logind-session: be more specific about session_kill() errors, plus minor fixes for sd_bus_error handling (#35150)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_SUCH_UNIT, ENOENT),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_SUCH_PROCESS, ESRCH),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_UNIT_FOR_PID, ESRCH),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID, ENOENT),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_UNIT_EXISTS, EEXIST),
|
||||
@@ -65,8 +66,6 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED, EALREADY),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_NTP_SUPPORT, EOPNOTSUPP),
|
||||
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_SUCH_PROCESS, ESRCH),
|
||||
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_NAME_SERVERS, ESRCH),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_INVALID_REPLY, EINVAL),
|
||||
SD_BUS_ERROR_MAP(BUS_ERROR_NO_SUCH_RR, ENOENT),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "bus-error.h"
|
||||
|
||||
#define BUS_ERROR_NO_SUCH_UNIT "org.freedesktop.systemd1.NoSuchUnit"
|
||||
#define BUS_ERROR_NO_SUCH_PROCESS "org.freedesktop.systemd1.NoSuchProcess"
|
||||
#define BUS_ERROR_NO_UNIT_FOR_PID "org.freedesktop.systemd1.NoUnitForPID"
|
||||
#define BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID "org.freedesktop.systemd1.NoUnitForInvocationID"
|
||||
#define BUS_ERROR_UNIT_EXISTS "org.freedesktop.systemd1.UnitExists"
|
||||
@@ -66,8 +67,6 @@
|
||||
#define BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED "org.freedesktop.timedate1.AutomaticTimeSyncEnabled"
|
||||
#define BUS_ERROR_NO_NTP_SUPPORT "org.freedesktop.timedate1.NoNTPSupport"
|
||||
|
||||
#define BUS_ERROR_NO_SUCH_PROCESS "org.freedesktop.systemd1.NoSuchProcess"
|
||||
|
||||
#define BUS_ERROR_NO_NAME_SERVERS "org.freedesktop.resolve1.NoNameServers"
|
||||
#define BUS_ERROR_INVALID_REPLY "org.freedesktop.resolve1.InvalidReply"
|
||||
#define BUS_ERROR_NO_SUCH_RR "org.freedesktop.resolve1.NoSuchRR"
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -671,7 +671,7 @@ static int extract_image_and_extensions(
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (isempty(id))
|
||||
return sd_bus_error_set_errnof(error, SYNTHETIC_ERRNO(ESTALE), "Image %s os-release metadata lacks the ID field", name_or_path);
|
||||
return sd_bus_error_set_errnof(error, ESTALE, "Image %s os-release metadata lacks the ID field", name_or_path);
|
||||
|
||||
if (prefixes) {
|
||||
valid_prefixes = strv_split(prefixes, WHITESPACE);
|
||||
@@ -715,7 +715,7 @@ static int extract_image_and_extensions(
|
||||
r = extension_release_validate(ext->path, id, version_id, confext_level, "portable", extension_release, IMAGE_CONFEXT);
|
||||
|
||||
if (r == 0)
|
||||
return sd_bus_error_set_errnof(error, SYNTHETIC_ERRNO(ESTALE), "Image %s extension-release metadata does not match the root's", ext->path);
|
||||
return sd_bus_error_set_errnof(error, ESTALE, "Image %s extension-release metadata does not match the root's", ext->path);
|
||||
if (r < 0)
|
||||
return sd_bus_error_set_errnof(error, r, "Failed to compare image %s extension-release metadata with the root's os-release: %m", ext->path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user