diff options
author | Andy Wingo <wingo@pobox.com> | 2015-08-23 11:50:26 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2015-08-23 11:50:26 +0200 |
commit | 08e1896fb7a00a758c3a71a99e54f0ff69da2fbd (patch) | |
tree | d958aed788d80d9bc7bb3ded3f8c9ca1aef20f7b /src | |
parent | 16e56d9f1ae28f17cf360a6daaab668b6cd66e61 (diff) |
Remove systemd subscription and user/session units
This removes attempts by logind to listen to systemd messages over the
bus, and to start and/or manage units associated with sessions and
users.
Diffstat (limited to 'src')
-rw-r--r-- | src/login/logind-core.c | 37 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 190 | ||||
-rw-r--r-- | src/login/logind-session-dbus.c | 3 | ||||
-rw-r--r-- | src/login/logind-session.c | 110 | ||||
-rw-r--r-- | src/login/logind-session.h | 2 | ||||
-rw-r--r-- | src/login/logind-user.c | 174 | ||||
-rw-r--r-- | src/login/logind-user.h | 6 | ||||
-rw-r--r-- | src/login/logind.c | 76 | ||||
-rw-r--r-- | src/login/logind.h | 9 |
9 files changed, 17 insertions, 590 deletions
diff --git a/src/login/logind-core.c b/src/login/logind-core.c index ace82fe1e5..67b03623ac 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -311,49 +311,24 @@ int manager_process_button_device(Manager *m, struct udev_device *d) { } int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { - _cleanup_free_ char *unit = NULL; - Session *s; - int r; - assert(m); assert(session); - if (pid < 1) - return -EINVAL; - - r = cg_pid_get_unit(pid, &unit); - if (r < 0) - return 0; - - s = hashmap_get(m->session_units, unit); - if (!s) - return 0; - - *session = s; - return 1; + /* Without cgroups, we have no way to map from pid to + session. */ + return 0; } int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) { - _cleanup_free_ char *unit = NULL; - User *u; - int r; - assert(m); assert(user); if (pid < 1) return -EINVAL; - r = cg_pid_get_slice(pid, &unit); - if (r < 0) - return 0; - - u = hashmap_get(m->user_units, unit); - if (!u) - return 0; - - *user = u; - return 1; + /* Without cgroups, we have no way to map from pid to + user. */ + return 0; } int manager_get_idle_hint(Manager *m, dual_timestamp *t) { diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index c5f2faee76..9e8cf05390 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2065,196 +2065,6 @@ static int session_jobs_reply(Session *s, const char *unit, const char *result) return r; } -int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { - const char *path, *result, *unit; - Manager *m = userdata; - Session *session; - uint32_t id; - User *user; - int r; - - assert(bus); - assert(message); - assert(m); - - r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result); - if (r < 0) { - bus_log_parse_error(r); - return r; - } - - if (m->action_job && streq(m->action_job, path)) { - log_info("Operation finished."); - - /* Tell people that they now may take a lock again */ - send_prepare_for(m, m->action_what, false); - - free(m->action_job); - m->action_job = NULL; - m->action_unit = NULL; - m->action_what = 0; - return 0; - } - - session = hashmap_get(m->session_units, unit); - if (session) { - - if (streq_ptr(path, session->scope_job)) { - free(session->scope_job); - session->scope_job = NULL; - } - - session_jobs_reply(session, unit, result); - - session_save(session); - session_add_to_gc_queue(session); - } - - user = hashmap_get(m->user_units, unit); - if (user) { - - if (streq_ptr(path, user->service_job)) { - free(user->service_job); - user->service_job = NULL; - } - - if (streq_ptr(path, user->slice_job)) { - free(user->slice_job); - user->slice_job = NULL; - } - - LIST_FOREACH(sessions_by_user, session, user->sessions) { - session_jobs_reply(session, unit, result); - } - - user_save(user); - user_add_to_gc_queue(user); - } - - return 0; -} - -int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { - const char *path, *unit; - Manager *m = userdata; - Session *session; - User *user; - int r; - - assert(bus); - assert(message); - assert(m); - - r = sd_bus_message_read(message, "so", &unit, &path); - if (r < 0) { - bus_log_parse_error(r); - return r; - } - - session = hashmap_get(m->session_units, unit); - if (session) - session_add_to_gc_queue(session); - - user = hashmap_get(m->user_units, unit); - if (user) - user_add_to_gc_queue(user); - - return 0; -} - -int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { - _cleanup_free_ char *unit = NULL; - Manager *m = userdata; - const char *path; - Session *session; - User *user; - int r; - - assert(bus); - assert(message); - assert(m); - - path = sd_bus_message_get_path(message); - if (!path) - return 0; - - r = unit_name_from_dbus_path(path, &unit); - if (r == -EINVAL) /* not a unit */ - return 0; - if (r < 0) - return r; - - session = hashmap_get(m->session_units, unit); - if (session) - session_add_to_gc_queue(session); - - user = hashmap_get(m->user_units, unit); - if (user) - user_add_to_gc_queue(user); - - return 0; -} - -int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { - Manager *m = userdata; - Session *session; - Iterator i; - int b, r; - - assert(bus); - - r = sd_bus_message_read(message, "b", &b); - if (r < 0) { - bus_log_parse_error(r); - return r; - } - - if (b) - return 0; - - /* systemd finished reloading, let's recheck all our sessions */ - log_debug("System manager has been reloaded, rechecking sessions..."); - - HASHMAP_FOREACH(session, m->sessions, i) - session_add_to_gc_queue(session); - - return 0; -} - -int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) { - const char *name, *old, *new; - Manager *m = userdata; - Session *session; - Iterator i; - int r; - - - char *key; - - r = sd_bus_message_read(message, "sss", &name, &old, &new); - if (r < 0) { - bus_log_parse_error(r); - return r; - } - - if (isempty(old) || !isempty(new)) - return 0; - - key = set_remove(m->busnames, (char*) old); - if (!key) - return 0; - - /* Drop all controllers owned by this name */ - - free(key); - - HASHMAP_FOREACH(session, m->sessions, i) - if (session_is_controller(session, old)) - session_drop_controller(session); - - return 0; -} - int manager_send_changed(Manager *manager, const char *property, ...) { char **l; diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index b119c8321b..f71798b208 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -711,9 +711,6 @@ int session_send_create_reply(Session *s, sd_bus_error *error) { if (!s->create_message) return 0; - if (!sd_bus_error_is_set(error) && (s->scope_job || s->user->service_job)) - return 0; - c = s->create_message; s->create_message = NULL; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index f55dca3858..08ca8072ae 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -118,13 +118,6 @@ 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); @@ -192,11 +185,6 @@ 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); @@ -315,8 +303,6 @@ 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, @@ -491,46 +477,6 @@ int session_activate(Session *s) { return 0; } -static int session_start_scope(Session *s) { - int r; - - assert(s); - assert(s->user); - 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; - - free(s->scope_job); - s->scope_job = job; - } - } - - if (s->scope) - hashmap_put(s->manager->session_units, s->scope, s); - - return 0; -} - int session_start(Session *s) { int r; @@ -546,13 +492,6 @@ int session_start(Session *s) { if (r < 0) return r; - /* Create cgroup */ -#if 0 - r = session_start_scope(s); - if (r < 0) - return r; -#endif - log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO, LOG_MESSAGE_ID(SD_MESSAGE_SESSION_START), "SESSION_ID=%s", s->id, @@ -590,38 +529,8 @@ int session_start(Session *s) { return 0; } -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 = 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; -} - int session_stop(Session *s, bool force) { - int r; + int r = 0; assert(s); @@ -633,9 +542,6 @@ int session_stop(Session *s, bool force) { /* We are going down, don't care about FIFOs anymore */ session_remove_fifo(s); - /* Kill cgroup */ - r = session_stop_scope(s, force); - s->stopping = true; user_elect_display(s->user); @@ -921,12 +827,6 @@ bool session_check_gc(Session *s, bool drop_not_started) { return true; } - 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; } @@ -947,7 +847,7 @@ SessionState session_get_state(Session *s) { if (s->stopping || s->timer_event_source) return SESSION_CLOSING; - if (s->scope_job || s->fifo_fd < 0) + if (s->fifo_fd < 0) return SESSION_OPENING; if (session_is_active(s)) @@ -959,10 +859,8 @@ SessionState session_get_state(Session *s) { int session_kill(Session *s, KillWho who, int signo) { assert(s); - if (!s->scope) - return -ESRCH; - - return manager_kill_unit(s->manager, s->scope, who, signo, NULL); + /* No way to kill the session without cgroups. */ + return -ESRCH; } static int session_open_vt(Session *s) { diff --git a/src/login/logind-session.h b/src/login/logind-session.h index 9305dca83f..14117bd888 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -89,8 +89,8 @@ struct Session { char *service; char *desktop; + /* Always NULL. */ char *scope; - char *scope_job; Seat *seat; unsigned int vtnr; diff --git a/src/login/logind-user.c b/src/login/logind-user.c index c0d0b967ae..539c316ad6 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -81,19 +81,6 @@ void user_free(User *u) { while (u->sessions) session_free(u->sessions); - if (u->slice) { - hashmap_remove(u->manager->user_units, u->slice); - free(u->slice); - } - - if (u->service) { - hashmap_remove(u->manager->user_units, u->service); - free(u->service); - } - - free(u->slice_job); - free(u->service_job); - free(u->runtime_path); hashmap_remove(u->manager->users, UID_TO_PTR(u->uid)); @@ -134,16 +121,6 @@ int user_save(User *u) { if (u->runtime_path) fprintf(f, "RUNTIME=%s\n", u->runtime_path); - if (u->service) - fprintf(f, "SERVICE=%s\n", u->service); - if (u->service_job) - fprintf(f, "SERVICE_JOB=%s\n", u->service_job); - - if (u->slice) - fprintf(f, "SLICE=%s\n", u->slice); - if (u->slice_job) - fprintf(f, "SLICE_JOB=%s\n", u->slice_job); - if (u->display) fprintf(f, "DISPLAY=%s\n", u->display->id); @@ -265,10 +242,6 @@ int user_load(User *u) { r = parse_env_file(u->state_file, NEWLINE, "RUNTIME", &u->runtime_path, - "SERVICE", &u->service, - "SERVICE_JOB", &u->service_job, - "SLICE", &u->slice, - "SLICE_JOB", &u->slice_job, "DISPLAY", &display, "REALTIME", &realtime, "MONOTONIC", &monotonic, @@ -365,72 +338,6 @@ fail: return r; } -static int user_start_slice(User *u) { - char *job; - int r; - - assert(u); - - if (!u->slice) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char lu[DECIMAL_STR_MAX(uid_t) + 1], *slice; - sprintf(lu, UID_FMT, u->uid); - - r = build_subslice(SPECIAL_USER_SLICE, lu, &slice); - if (r < 0) - return r; - - r = manager_start_unit(u->manager, slice, &error, &job); - if (r < 0) { - log_error("Failed to start user slice: %s", bus_error_message(&error, r)); - free(slice); - } else { - u->slice = slice; - - free(u->slice_job); - u->slice_job = job; - } - } - - if (u->slice) - hashmap_put(u->manager->user_units, u->slice, u); - - return 0; -} - -static int user_start_service(User *u) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; - int r; - - assert(u); - - if (!u->service) { - char lu[DECIMAL_STR_MAX(uid_t) + 1], *service; - sprintf(lu, UID_FMT, u->uid); - - service = unit_name_build("user", lu, ".service"); - if (!service) - return log_oom(); - - r = manager_start_unit(u->manager, service, &error, &job); - if (r < 0) { - log_error("Failed to start user service: %s", bus_error_message(&error, r)); - free(service); - } else { - u->service = service; - - free(u->service_job); - u->service_job = job; - } - } - - if (u->service) - hashmap_put(u->manager->user_units, u->service, u); - - return 0; -} - int user_start(User *u) { int r; @@ -446,18 +353,6 @@ int user_start(User *u) { if (r < 0) return r; -#if 0 - /* Create cgroup */ - r = user_start_slice(u); - if (r < 0) - return r; - - /* Spawn user systemd */ - r = user_start_service(u); - if (r < 0) - return r; -#endif - if (!dual_timestamp_is_set(&u->timestamp)) dual_timestamp_get(&u->timestamp); @@ -471,50 +366,6 @@ int user_start(User *u) { return 0; } -static int user_stop_slice(User *u) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; - int r; - - assert(u); - - if (!u->slice) - return 0; - - r = manager_stop_unit(u->manager, u->slice, &error, &job); - if (r < 0) { - log_error("Failed to stop user slice: %s", bus_error_message(&error, r)); - return r; - } - - free(u->slice_job); - u->slice_job = job; - - return r; -} - -static int user_stop_service(User *u) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; - int r; - - assert(u); - - if (!u->service) - return 0; - - r = manager_stop_unit(u->manager, u->service, &error, &job); - if (r < 0) { - log_error("Failed to stop user service: %s", bus_error_message(&error, r)); - return r; - } - - free(u->service_job); - u->service_job = job; - - return r; -} - static int user_remove_runtime_path(User *u) { int r; @@ -561,16 +412,6 @@ int user_stop(User *u, bool force) { r = k; } - /* Kill systemd */ - k = user_stop_service(u); - if (k < 0) - r = k; - - /* Kill cgroup */ - k = user_stop_slice(u); - if (k < 0) - r = k; - u->stopping = true; user_save(u); @@ -677,12 +518,6 @@ bool user_check_gc(User *u, bool drop_not_started) { if (user_check_linger_file(u) > 0) return true; - if (u->slice_job && manager_job_is_active(u->manager, u->slice_job)) - return true; - - if (u->service_job && manager_job_is_active(u->manager, u->service_job)) - return true; - return false; } @@ -704,9 +539,6 @@ UserState user_get_state(User *u) { if (u->stopping) return USER_CLOSING; - if (u->slice_job || u->service_job) - return USER_OPENING; - if (u->sessions) { bool all_closing = true; @@ -732,10 +564,8 @@ UserState user_get_state(User *u) { int user_kill(User *u, int signo) { assert(u); - if (!u->slice) - return -ESRCH; - - return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL); + /* FIXME: No way to kill a user without systemd. */ + return -ESRCH; } void user_elect_display(User *u) { diff --git a/src/login/logind-user.h b/src/login/logind-user.h index be5b56883c..607fe1bf7b 100644 --- a/src/login/logind-user.h +++ b/src/login/logind-user.h @@ -47,12 +47,12 @@ struct User { char *state_file; char *runtime_path; + /* These are always NULL, and here just for logind-user-dbus.c + to easily provide a NULL value for the user's service and + slice properties. */ char *service; char *slice; - char *service_job; - char *slice_job; - Session *display; dual_timestamp timestamp; diff --git a/src/login/logind.c b/src/login/logind.c index 845a229230..5856c336f6 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -66,13 +66,9 @@ Manager *manager_new(void) { m->inhibitors = hashmap_new(&string_hash_ops); m->buttons = hashmap_new(&string_hash_ops); - m->user_units = hashmap_new(&string_hash_ops); - m->session_units = hashmap_new(&string_hash_ops); - m->busnames = set_new(&string_hash_ops); - if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames || - !m->user_units || !m->session_units) + if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames) goto fail; m->kill_exclude_users = strv_new("root", NULL); @@ -131,9 +127,6 @@ void manager_free(Manager *m) { hashmap_free(m->inhibitors); hashmap_free(m->buttons); - hashmap_free(m->user_units); - hashmap_free(m->session_units); - set_free_free(m->busnames); sd_event_source_unref(m->idle_action_event_source); @@ -584,73 +577,6 @@ static int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to add user enumerator: %m"); - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," - "sender='org.freedesktop.DBus'," - "interface='org.freedesktop.DBus'," - "member='NameOwnerChanged'," - "path='/org/freedesktop/DBus'", - match_name_owner_changed, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for NameOwnerChanged: %m"); - - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.systemd1.Manager'," - "member='JobRemoved'," - "path='/org/freedesktop/systemd1'", - match_job_removed, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for JobRemoved: %m"); - - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.systemd1.Manager'," - "member='UnitRemoved'," - "path='/org/freedesktop/systemd1'", - match_unit_removed, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for UnitRemoved: %m"); - - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.DBus.Properties'," - "member='PropertiesChanged'", - match_properties_changed, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for PropertiesChanged: %m"); - - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," - "sender='org.freedesktop.systemd1'," - "interface='org.freedesktop.systemd1.Manager'," - "member='Reloading'," - "path='/org/freedesktop/systemd1'", - match_reloading, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for Reloading: %m"); - - r = sd_bus_call_method( - m->bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "Subscribe", - &error, - NULL, NULL); - if (r < 0) { - log_warning("Failed to subscribe to org.freedesktop.systemd1.Manager: %s", - bus_error_message(&error, r)); - } - r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0); if (r < 0) return log_error_errno(r, "Failed to register name: %m"); diff --git a/src/login/logind.h b/src/login/logind.h index 486278c772..1629415b7e 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -73,9 +73,6 @@ struct Manager { unsigned long session_counter; unsigned long inhibit_counter; - Hashmap *session_units; - Hashmap *user_units; - usec_t inhibit_delay_max; /* If an action is currently being executed or is delayed, @@ -151,12 +148,6 @@ bool manager_is_docked_or_multiple_displays(Manager *m); extern const sd_bus_vtable manager_vtable[]; -int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error); -int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error); -int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error); -int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error); -int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error); - int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error); int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_; |