From 25e8304fd7e392a73fce31e54a94b301d1786e9b Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Mon, 20 Aug 2018 09:25:00 +0200 Subject: [PATCH] Prep v239: Fix logind-session.c, it got screwed by migration. --- src/login/logind-session.c | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/login/logind-session.c b/src/login/logind-session.c index d860c310d..e0daa4440 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -722,6 +722,17 @@ static int session_stop_cgroup(Session *s, bool force) { assert(s); + // elogind must not kill lingering user processes alive + if ( (force || manager_shall_kill(s->manager, s->user->name) ) + && (user_check_linger_file(s->user) < 1) ) { + r = session_kill(s, KILL_ALL, SIGTERM); + if (r < 0) + return r; + } + + return 0; +} +#endif // 0 int session_stop(Session *s, bool force) { int r; @@ -740,7 +751,11 @@ int session_stop(Session *s, bool force) { session_remove_fifo(s); /* Kill cgroup */ +#if 0 /// elogind does not start scopes, but sessions r = session_stop_scope(s, force); +#else + r = session_stop_cgroup(s, force); +#endif // 0 s->stopping = true; @@ -749,6 +764,9 @@ int session_stop(Session *s, bool force) { session_save(s); user_save(s->user); +#if 1 /// elogind must queue this session again + session_add_to_gc_queue(s); +#endif // 1 return r; } @@ -766,8 +784,6 @@ int session_finalize(Session *s) { "SESSION_ID=%s", s->id, "USER_ID=%s", s->user->name, "LEADER="PID_FMT, s->leader, - LOG_MESSAGE("Removed session %s.", s->id), - NULL); LOG_MESSAGE("Removed session %s.", s->id)); s->timer_event_source = sd_event_source_unref(s->timer_event_source); @@ -982,8 +998,6 @@ int session_create_fifo(Session *s) { /* Create FIFO */ if (!s->fifo_path) { - r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0, false); - r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0, 0); r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0, MKDIR_WARN_MODE); if (r < 0) return r; @@ -1049,10 +1063,12 @@ bool session_may_gc(Session *s, bool drop_not_started) { return false; } +#if 0 /// elogind supports neither scopes nor jobs if (s->scope_job && manager_job_is_active(s->manager, s->scope_job)) return false; if (s->scope && manager_unit_is_active(s->manager, s->scope)) +#endif // 0 return false; return true; @@ -1075,7 +1091,11 @@ SessionState session_get_state(Session *s) { if (s->stopping || s->timer_event_source) return SESSION_CLOSING; +#if 0 /// elogind does not support systemd scope_jobs if (s->scope_job || s->fifo_fd < 0) +#else + if (s->fifo_fd < 0) +#endif // 0 return SESSION_OPENING; if (session_is_active(s)) @@ -1087,10 +1107,27 @@ SessionState session_get_state(Session *s) { int session_kill(Session *s, KillWho who, int signo) { assert(s); +#if 0 /// Without direct cgroup support, elogind can not kill sessions if (!s->scope) return -ESRCH; return manager_kill_unit(s->manager, s->scope, who, signo, NULL); +#else + if (who == KILL_LEADER) { + if (s->leader <= 0) + return -ESRCH; + + /* FIXME: verify that leader is in cgroup? */ + + if (kill(s->leader, signo) < 0) { + return log_error_errno(errno, "Failed to kill process leader %d for session %s: %m", s->leader, s->id); + } + return 0; + } else + return cg_kill_recursive (SYSTEMD_CGROUP_CONTROLLER, s->id, signo, + CGROUP_IGNORE_SELF | CGROUP_REMOVE, + NULL, NULL, NULL); +#endif // 0 } static int session_open_vt(Session *s) { @@ -1180,8 +1217,6 @@ void session_restore_vt(Session *s) { * little dance to avoid having the terminal be available * for reuse before we've cleaned it up. */ - old_fd = s->vtfd; - s->vtfd = -1; old_fd = TAKE_FD(s->vtfd); vt = session_open_vt(s); @@ -1307,8 +1342,6 @@ int session_set_controller(Session *s, const char *sender, bool force, bool prep } session_release_controller(s, true); - s->controller = name; - name = NULL; s->controller = TAKE_PTR(name); session_save(s); -- 2.30.2