Compare commits

...

4 Commits

Author SHA1 Message Date
Lennart Poettering 0306d1598d
Merge pull request #17028 from poettering/logind-replace-job
logind: make TerminateSession() count
2020-09-11 22:17:41 +02:00
Lennart Poettering 1a42ce0920 logind: make sure when we are explicitly asked to terminate session/user/seat to use "replace" job mode
Otherwise our request will possibly fail if something else is already
enqeued, but given this is an explicit user request, let's not allow
things to fail.

Fixes: #16702
2020-09-11 18:09:34 +02:00
Lennart Poettering bda625730d logind: clarify what the second argument of session_stop() means when calling it 2020-09-11 18:09:30 +02:00
Lennart Poettering 40771cf524 logind: minor simplification 2020-09-11 18:09:11 +02:00
8 changed files with 20 additions and 21 deletions

View File

@ -4072,13 +4072,13 @@ int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error,
return strdup_job(reply, job);
}
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) {
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **ret_job) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
assert(manager);
assert(unit);
assert(job);
assert(ret_job);
r = bus_call_method(
manager->bus,
@ -4086,12 +4086,12 @@ int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, c
"StopUnit",
error,
&reply,
"ss", unit, "fail");
"ss", unit, job_mode ?: "fail");
if (r < 0) {
if (sd_bus_error_has_names(error, BUS_ERROR_NO_SUCH_UNIT,
BUS_ERROR_LOAD_FAILED)) {
*job = NULL;
*ret_job = NULL;
sd_bus_error_free(error);
return 0;
}
@ -4099,7 +4099,7 @@ int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, c
return r;
}
return strdup_job(reply, job);
return strdup_job(reply, ret_job);
}
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *ret_error) {

View File

@ -25,7 +25,7 @@ int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_
int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, char **wants, char **after, const char *requires_mounts_for, sd_bus_message *more_properties, sd_bus_error *error, char **job);
int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
int manager_stop_unit(Manager *manager, const char *unit, const char *job_mode, sd_bus_error *error, char **job);
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *error);

View File

@ -152,7 +152,7 @@ int bus_seat_method_terminate(sd_bus_message *message, void *userdata, sd_bus_er
if (r == 0)
return 1; /* Will call us back */
r = seat_stop_sessions(s, true);
r = seat_stop_sessions(s, /* force = */ true);
if (r < 0)
return r;

View File

@ -178,7 +178,7 @@ int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus
if (r == 0)
return 1; /* Will call us back */
r = session_stop(s, true);
r = session_stop(s, /* force = */ true);
if (r < 0)
return r;

View File

@ -735,10 +735,9 @@ int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error) {
/* Send signals */
session_send_signal(s, true);
user_send_changed(s->user, "Display", NULL);
if (s->seat) {
if (s->seat->active == s)
seat_send_changed(s->seat, "ActiveSession", NULL);
}
if (s->seat && s->seat->active == s)
seat_send_changed(s->seat, "ActiveSession", NULL);
return 0;
}
@ -769,7 +768,7 @@ static int session_stop_scope(Session *s, bool force) {
(s->user->user_record->kill_processes > 0 ||
manager_shall_kill(s->manager, s->user->user_record->user_name)))) {
r = manager_stop_unit(s->manager, s->scope, &error, &s->scope_job);
r = manager_stop_unit(s->manager, s->scope, force ? "replace" : "fail", &error, &s->scope_job);
if (r < 0) {
if (force)
return log_error_errno(r, "Failed to stop session scope: %s", bus_error_message(&error, r));
@ -882,7 +881,7 @@ static int release_timeout_callback(sd_event_source *es, uint64_t usec, void *us
assert(es);
assert(s);
session_stop(s, false);
session_stop(s, /* force = */ false);
return 0;
}
@ -1054,7 +1053,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, false);
session_stop(s, /* force = */ false);
return 1;
}

View File

@ -216,7 +216,7 @@ int bus_user_method_terminate(sd_bus_message *message, void *userdata, sd_bus_er
if (r == 0)
return 1; /* Will call us back */
r = user_stop(u, true);
r = user_stop(u, /* force */ true);
if (r < 0)
return r;

View File

@ -475,7 +475,7 @@ int user_start(User *u) {
return 0;
}
static void user_stop_service(User *u) {
static void user_stop_service(User *u, bool force) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
@ -487,7 +487,7 @@ static void user_stop_service(User *u) {
u->service_job = mfree(u->service_job);
r = manager_stop_unit(u->manager, u->service, &error, &u->service_job);
r = manager_stop_unit(u->manager, u->service, force ? "replace" : "fail", &error, &u->service_job);
if (r < 0)
log_warning_errno(r, "Failed to stop user service '%s', ignoring: %s", u->service, bus_error_message(&error, r));
}
@ -518,7 +518,7 @@ int user_stop(User *u, bool force) {
r = k;
}
user_stop_service(u);
user_stop_service(u, force);
u->stopping = true;

View File

@ -912,7 +912,7 @@ static void manager_gc(Manager *m, bool drop_not_started) {
seat->in_gc_queue = false;
if (seat_may_gc(seat, drop_not_started)) {
seat_stop(seat, false);
seat_stop(seat, /* force = */ false);
seat_free(seat);
}
}
@ -924,7 +924,7 @@ static void manager_gc(Manager *m, bool drop_not_started) {
/* First, if we are not closing yet, initiate stopping */
if (session_may_gc(session, drop_not_started) &&
session_get_state(session) != SESSION_CLOSING)
(void) session_stop(session, false);
(void) session_stop(session, /* force = */ false);
/* Normally, this should make the session referenced
* again, if it doesn't then let's get rid of it