Skip to content

Commit

Permalink
logind: reset session leader if we know for a fact that it is gone
Browse files Browse the repository at this point in the history
rhel-only

Related: #2223602
  • Loading branch information
msekletar authored and jamacku committed Jul 20, 2023
1 parent 1ac7d4d commit 33c6637
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/login/logind-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,9 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
session->scope_job = mfree(session->scope_job);
(void) session_jobs_reply(session, unit, result);

/* Scope job is done so leader should be gone as well. */
session_invalidate_leader(session);

session_save(session);
user_save(session->user);
}
Expand Down
18 changes: 18 additions & 0 deletions src/login/logind-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ int session_set_leader(Session *s, pid_t pid) {
return 1;
}

int session_invalidate_leader(Session *s) {
assert(s);

if (s->leader <= 0)
return 0;

if (pid_is_alive(s->leader))
return 0;

(void) hashmap_remove_value(s->manager->sessions_by_leader, PID_TO_PTR(s->leader), s);
s->leader = 0;

(void) session_save(s);

return 1;
}

static void session_save_devices(Session *s, FILE *f) {
SessionDevice *sd;
Iterator i;
Expand Down Expand Up @@ -1096,6 +1113,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_invalidate_leader(s);
session_stop(s, false);

return 1;
Expand Down
1 change: 1 addition & 0 deletions src/login/logind-session.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Session *, session_free);

void session_set_user(Session *s, User *u);
int session_set_leader(Session *s, pid_t pid);
int session_invalidate_leader(Session *s);
bool session_may_gc(Session *s, bool drop_not_started);
void session_add_to_gc_queue(Session *s);
int session_activate(Session *s);
Expand Down

0 comments on commit 33c6637

Please sign in to comment.