From 3a35bb2809b93b2426bdf194c16cdcc1d9a65447 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 3 May 2015 22:26:52 +0200 Subject: [PATCH] Rename systemd-logind to logind. --- man/logind.xml | 18 +++--- src/login/logind-session.c | 128 ++++++++++++++++++++++++++----------- src/login/logind.c | 4 +- 3 files changed, 101 insertions(+), 49 deletions(-) diff --git a/man/logind.xml b/man/logind.xml index da0bd7a0c..7afacbf34 100644 --- a/man/logind.xml +++ b/man/logind.xml @@ -21,10 +21,10 @@ along with systemd; If not, see . --> - + - systemd-logind.service + logind.service systemd @@ -38,25 +38,25 @@ - systemd-logind.service + logind.service 8 - systemd-logind.service - systemd-logind + logind.service + logind Login manager - systemd-logind.service - /usr/lib/systemd/systemd-logind + logind.service + /usr/lib/systemd/logind Description - systemd-logind is a system service that + logind is a system service that manages user logins. It is responsible for: @@ -100,7 +100,7 @@ See the logind D-Bus API Documentation for information about the - APIs systemd-logind provides. + APIs logind provides. For more information on the inhibition logic see the Inhibitor diff --git a/src/login/logind-session.c b/src/login/logind-session.c index c93a4827a..108139ce3 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -36,12 +36,12 @@ #include "audit.h" #include "bus-util.h" #include "bus-error.h" -#include "cgroup-util.h" -#include "def.h" #include "logind-session.h" #include "formats-util.h" #include "terminal-util.h" +#define RELEASE_USEC (20*USEC_PER_SEC) + static void session_remove_fifo(Session *s); Session* session_new(Manager *m, const char *id) { @@ -120,6 +120,13 @@ void session_free(Session *s) { LIST_REMOVE(sessions_by_seat, s->seat->sessions, s); } + if (s->scope) { + hashmap_remove(s->manager->session_units, s->scope); + free(s->scope); + } + + free(s->scope_job); + sd_bus_message_unref(s->create_message); free(s->tty); @@ -187,6 +194,11 @@ int session_save(Session *s) { if (s->class >= 0) fprintf(f, "CLASS=%s\n", session_class_to_string(s->class)); + if (s->scope) + fprintf(f, "SCOPE=%s\n", s->scope); + if (s->scope_job) + fprintf(f, "SCOPE_JOB=%s\n", s->scope_job); + if (s->fifo_path) fprintf(f, "FIFO=%s\n", s->fifo_path); @@ -305,6 +317,8 @@ int session_load(Session *s) { r = parse_env_file(s->state_file, NEWLINE, "REMOTE", &remote, + "SCOPE", &s->scope, + "SCOPE_JOB", &s->scope_job, "FIFO", &s->fifo_path, "SEAT", &seat, "TTY", &s->tty, @@ -479,21 +493,42 @@ int session_activate(Session *s) { return 0; } -static int session_start_cgroup(Session *s) { +static int session_start_scope(Session *s) { int r; assert(s); assert(s->user); - assert(s->leader > 0); + assert(s->user->slice); + + if (!s->scope) { + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_free_ char *description = NULL; + char *scope, *job = NULL; + + description = strjoin("Session ", s->id, " of user ", s->user->name, NULL); + if (!description) + return log_oom(); + + scope = strjoin("session-", s->id, ".scope", NULL); + if (!scope) + return log_oom(); + + r = manager_start_scope(s->manager, scope, s->leader, s->user->slice, description, "logind.service", "systemd-user-sessions.service", &error, &job); + if (r < 0) { + log_error("Failed to start session scope %s: %s %s", + scope, bus_error_message(&error, r), error.name); + free(scope); + return r; + } else { + s->scope = scope; - /* First, create our own group */ - r = cg_create(SYSTEMD_CGROUP_CONTROLLER, s->id); - if (r < 0) - return log_error_errno(r, "Failed to create cgroup %s: %m", s->id); + free(s->scope_job); + s->scope_job = job; + } + } - r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, s->id, s->leader); - if (r < 0) - log_warning_errno(r, "Failed to attach PID %d to cgroup %s: %m", s->leader, s->id); + if (s->scope) + hashmap_put(s->manager->session_units, s->scope, s); return 0; } @@ -513,7 +548,8 @@ int session_start(Session *s) { if (r < 0) return r; - r = session_start_cgroup(s); + /* Create cgroup */ + r = session_start_scope(s); if (r < 0) return r; @@ -554,16 +590,31 @@ int session_start(Session *s) { return 0; } -static int session_stop_cgroup(Session *s, bool force) { +static int session_stop_scope(Session *s, bool force) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + char *job = NULL; int r; assert(s); + if (!s->scope) + return 0; + if (force || manager_shall_kill(s->manager, s->user->name)) { - r = session_kill(s, KILL_ALL, SIGTERM); - if (r < 0) + r = manager_stop_unit(s->manager, s->scope, &error, &job); + if (r < 0) { + log_error("Failed to stop session scope: %s", bus_error_message(&error, r)); + return r; + } + + free(s->scope_job); + s->scope_job = job; + } else { + r = manager_abandon_scope(s->manager, s->scope, &error); + if (r < 0) { + log_error("Failed to abandon session scope: %s", bus_error_message(&error, r)); return r; + } } return 0; @@ -583,7 +634,7 @@ int session_stop(Session *s, bool force) { session_remove_fifo(s); /* Kill cgroup */ - r = session_stop_cgroup(s, force); + r = session_stop_scope(s, force); s->stopping = true; @@ -642,6 +693,16 @@ int session_finalize(Session *s) { return r; } +static int release_timeout_callback(sd_event_source *es, uint64_t usec, void *userdata) { + Session *s = userdata; + + assert(es); + assert(s); + + session_stop(s, false); + return 0; +} + int session_release(Session *s) { assert(s); @@ -651,10 +712,11 @@ int session_release(Session *s) { if (s->timer_event_source) return 0; - /* In systemd, session release is triggered by user jobs - dying. In elogind we don't have that so go ahead and stop - now. */ - return session_stop(s, false); + return sd_event_add_time(s->manager->event, + &s->timer_event_source, + CLOCK_MONOTONIC, + now(CLOCK_MONOTONIC) + RELEASE_USEC, 0, + release_timeout_callback, s); } bool session_is_active(Session *s) { @@ -859,7 +921,10 @@ bool session_check_gc(Session *s, bool drop_not_started) { return true; } - if (cg_is_empty_recursive (SYSTEMD_CGROUP_CONTROLLER, s->id, false) > 0) + if (s->scope_job && manager_job_is_active(s->manager, s->scope_job)) + return true; + + if (s->scope && manager_unit_is_active(s->manager, s->scope)) return true; return false; @@ -882,7 +947,7 @@ SessionState session_get_state(Session *s) { if (s->stopping || s->timer_event_source) return SESSION_CLOSING; - if (s->fifo_fd < 0) + if (s->scope_job || s->fifo_fd < 0) return SESSION_OPENING; if (session_is_active(s)) @@ -894,23 +959,10 @@ SessionState session_get_state(Session *s) { int session_kill(Session *s, KillWho who, int signo) { assert(s); - if (who == KILL_LEADER) { - if (s->leader <= 0) - return -ESRCH; - - /* FIXME: verify that leader is in cgroup? */ + if (!s->scope) + return -ESRCH; - 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 { - bool sigcont = false; - bool ignore_self = true; - bool rem = true; - return cg_kill_recursive (SYSTEMD_CGROUP_CONTROLLER, s->id, signo, - sigcont, ignore_self, rem, NULL); - } + return manager_kill_unit(s->manager, s->scope, who, signo, NULL); } static int session_open_vt(Session *s) { diff --git a/src/login/logind.c b/src/login/logind.c index 7520f1345..78753bca4 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1169,7 +1169,7 @@ int main(int argc, char *argv[]) { goto finish; } - log_debug("systemd-logind running as pid "PID_FMT, getpid()); + log_debug("logind running as pid "PID_FMT, getpid()); sd_notify(false, "READY=1\n" @@ -1177,7 +1177,7 @@ int main(int argc, char *argv[]) { r = manager_run(m); - log_debug("systemd-logind stopped as pid "PID_FMT, getpid()); + log_debug("logind stopped as pid "PID_FMT, getpid()); finish: sd_notify(false, -- 2.30.2