diff options
author | Sven Eden <sven.eden@prydeworx.com> | 2018-11-08 07:53:08 +0100 |
---|---|---|
committer | Sven Eden <sven.eden@prydeworx.com> | 2018-11-08 08:02:57 +0100 |
commit | 918e88d5024ce206d678799d4e455fb6d980db49 (patch) | |
tree | 58eafe6b8fc8955aef4303fd2ef97216b30ff4ee /src | |
parent | 2f5ca87f222ec5ae62e5c2f17b53046905ecfbca (diff) |
Prep v239.2: Fix migration errors in login
Diffstat (limited to 'src')
-rw-r--r-- | src/login/elogind-dbus.c | 2 | ||||
-rw-r--r-- | src/login/logind-core.c | 31 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 4 | ||||
-rw-r--r-- | src/login/logind-session-dbus.c | 2 | ||||
-rw-r--r-- | src/login/logind-session.c | 11 | ||||
-rw-r--r-- | src/login/logind-user.c | 108 | ||||
-rw-r--r-- | src/login/logind.c | 10 | ||||
-rw-r--r-- | src/login/logind.h | 4 | ||||
-rw-r--r-- | src/login/user-runtime-dir.c | 4 |
9 files changed, 78 insertions, 98 deletions
diff --git a/src/login/elogind-dbus.c b/src/login/elogind-dbus.c index f359e1867..03ec05029 100644 --- a/src/login/elogind-dbus.c +++ b/src/login/elogind-dbus.c @@ -83,7 +83,7 @@ static int run_helper(const char *helper, const char *arg_verb) { arguments[0] = NULL; arguments[1] = (char*)arg_verb; arguments[2] = NULL; - execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, arguments); + execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, arguments, NULL); r = safe_fork_full(helper, NULL, 0, FORK_RESET_SIGNALS|FORK_REOPEN_LOG, NULL); diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 1d85278c6..e7517794c 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -6,7 +6,7 @@ #include <sys/types.h> #include <linux/vt.h> #if ENABLE_UTMP -//#include <utmpx.h> +#include <utmpx.h> #endif #include "alloc-util.h" @@ -17,7 +17,7 @@ #include "fd-util.h" #include "logind.h" #include "parse-util.h" -//#include "path-util.h" +#include "path-util.h" #include "process-util.h" #include "strv.h" #include "terminal-util.h" @@ -357,28 +357,29 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **ret) { if (!pid_is_valid(pid)) return -EINVAL; + s = hashmap_get(m->sessions_by_leader, PID_TO_PTR(pid)); + if (!s) { #if 0 /// elogind does not support systemd units, but its own session system + r = cg_pid_get_unit(pid, &unit); + if (r < 0) + goto not_found; + s = hashmap_get(m->session_units, unit); if (!s) goto not_found; - } #else - log_debug_elogind("Searching session for PID %u", pid); - r = cg_pid_get_session(pid, &session_name); - if (r < 0) - goto not_found; - s = hashmap_get(m->sessions_by_leader, PID_TO_PTR(pid)); - if (!s) { - r = cg_pid_get_unit(pid, &unit); + log_debug_elogind("Searching session for PID %u", pid); + r = cg_pid_get_session(pid, &session_name); if (r < 0) goto not_found; - s = hashmap_get(m->sessions, session_name); - log_debug_elogind("Session Name \"%s\" -> Session \"%s\"", - session_name, s && s->id ? s->id : "NULL"); - if (NULL == s) - goto not_found; + s = hashmap_get(m->sessions, session_name); + log_debug_elogind("Session Name \"%s\" -> Session \"%s\"", + session_name, s && s->id ? s->id : "NULL"); + if (NULL == s) + goto not_found; #endif // 0 + } if (ret) *ret = s; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 872bcf881..44f08c583 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2349,10 +2349,10 @@ static int method_can_shutdown_or_sleep( if (sleep_verb) { #if 0 /// elogind needs to have the manager being passed r = can_sleep(sleep_verb); - if (IN_SET(r, 0, -ENOSPC, -EADV)) #else r = can_sleep(m, sleep_verb); #endif // 0 + if (IN_SET(r, 0, -ENOSPC, -EADV)) return sd_bus_reply_method_return(message, "s", "na"); if (r < 0) return r; @@ -2391,11 +2391,11 @@ static int method_can_shutdown_or_sleep( goto finish; } } - } #else log_debug_elogind("CanShutDownOrSleep: %s [%d] %s blocked", sleep_verb, handle, blocked ? "is" : "not"); #endif // 0 + } if (multiple_sessions) { r = bus_test_polkit(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, UID_INVALID, &challenge, error); diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index b50f4440e..e7f64fd61 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -689,6 +689,7 @@ int session_send_lock_all(Manager *m, bool lock) { return r; } +#if 0 /// elogind does not support scope and service jobs static bool session_ready(Session *s) { assert(s); @@ -697,6 +698,7 @@ static bool session_ready(Session *s) { return !s->scope_job && !s->user->service_job; } +#endif // 0 int session_send_create_reply(Session *s, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *c = NULL; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 27dcf83a6..dce0f7377 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -5,7 +5,7 @@ #include <linux/kd.h> #include <linux/vt.h> #include <signal.h> -//#include <stdio_ext.h> +#include <stdio_ext.h> #include <string.h> #include <sys/ioctl.h> #include <unistd.h> @@ -120,10 +120,12 @@ Session* session_free(Session *s) { LIST_REMOVE(sessions_by_seat, s->seat->sessions, s); } +#if 0 /// elogind does not support systemd units and scope_jobs if (s->scope) { hashmap_remove(s->manager->session_units, s->scope); free(s->scope); } +#endif // 0 if (pid_is_valid(s->leader)) (void) hashmap_remove_value(s->manager->sessions_by_leader, PID_TO_PTR(s->leader), s); @@ -668,7 +670,6 @@ static int session_start_scope(Session *s, sd_bus_message *properties, sd_bus_er return 0; } -int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error) { #else static int session_start_cgroup(Session *s) { int r; @@ -689,6 +690,8 @@ static int session_start_cgroup(Session *s) { return 0; } #endif // 0 + +int session_start(Session *s, sd_bus_message *properties, sd_bus_error *error) { int r; assert(s); @@ -1137,7 +1140,9 @@ static void session_remove_fifo(Session *s) { } bool session_may_gc(Session *s, bool drop_not_started) { +#if 0 /// UNNEEDED by elogind int r; +#endif // 0 assert(s); @@ -1153,7 +1158,6 @@ bool session_may_gc(Session *s, bool drop_not_started) { } #if 0 /// elogind supports neither scopes nor jobs -#endif // 0 if (s->scope_job) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; @@ -1173,6 +1177,7 @@ bool session_may_gc(Session *s, bool drop_not_started) { if (r != 0) return false; } +#endif // 0 return true; } diff --git a/src/login/logind-user.c b/src/login/logind-user.c index d299250c4..78822c921 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -90,6 +90,7 @@ int user_new(User **ret, if (r < 0) return r; +#if 0 /// elogind does not support systemd units r = hashmap_put(m->user_units, u->slice, u); if (r < 0) return r; @@ -101,6 +102,7 @@ int user_new(User **ret, r = hashmap_put(m->user_units, u->runtime_dir_service, u); if (r < 0) return r; +#endif // 0 *ret = TAKE_PTR(u); return 0; @@ -116,6 +118,7 @@ User *user_free(User *u) { while (u->sessions) session_free(u->sessions); +#if 0 /// elogind does not support systemd units if (u->service) hashmap_remove_value(u->manager->user_units, u->service, u); @@ -124,6 +127,7 @@ User *user_free(User *u) { if (u->slice) hashmap_remove_value(u->manager->user_units, u->slice, u); +#endif // 0 hashmap_remove_value(u->manager->users, UID_TO_PTR(u->uid), u); @@ -319,8 +323,8 @@ int user_load(User *u) { r = parse_env_file(NULL, u->state_file, NEWLINE, #if 0 /// elogind neither supports service nor slice jobs -#endif // 0 "SERVICE_JOB", &u->service_job, +#endif // 0 "STOPPING", &stopping, "REALTIME", &realtime, "MONOTONIC", &monotonic, @@ -349,31 +353,24 @@ int user_load(User *u) { return 0; } +#if 0 /// elogind neither spawns systemd --user nor suports systemd units and services. static void user_start_service(User *u) { -#if 0 /// elogind can not ask systemd via dbus to start user services _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert(u); - u->service_job = mfree(u->service_job); -#else - assert(u); /* Start the service containing the "systemd --user" instance (user@.service). Note that we don't explicitly - * start the per-user slice or the elogind-runtime-dir@.service instance, as those are pulled in both by - * start the per-user slice or the elogind-runtime-dir@.service instance, as those are pulled in both by - * start the per-user slice or the elogind-runtime-dir@.service instance, as those are pulled in both by - * start the per-user slice or the elogind-runtime-dir@.service instance, as those are pulled in both by - * start the per-user slice or the elogind-runtime-dir@.service instance, as those are pulled in both by + * start the per-user slice or the systemd-runtime-dir@.service instance, as those are pulled in both by * user@.service and the session scopes as dependencies. */ - hashmap_put(u->manager->user_units, u->service, u); -#endif // 0 + u->service_job = mfree(u->service_job); r = manager_start_unit(u->manager, u->service, &error, &u->service_job); if (r < 0) log_warning_errno(r, "Failed to start user service '%s', ignoring: %s", u->service, bus_error_message(&error, r)); } +#endif // 0 int user_start(User *u) { assert(u); @@ -387,35 +384,24 @@ int user_start(User *u) { * so possibly pending units are stopped. */ u->stopping = false; -#if 0 /// elogind has to prepare the XDG_RUNTIME_DIR by itself if (!u->started) log_debug("Starting services for new user %s.", u->name); -#else - if (!u->started) { - log_debug("Starting services for new user %s.", u->name); - r = user_runtime_dir("start", u); - if (r < 0) - return r; - } - /* Save the user data so far, because pam_systemd will read the - * XDG_RUNTIME_DIR out of it while starting up systemd --user. - * We need to do user_save_internal() because we have not - * "officially" started yet. */ +#if 1 /// elogind has to prepare the XDG_RUNTIME_DIR by itself + int r; + r = user_runtime_dir("start", u); + if (r < 0) + return r; +#endif // 1 + /* Save the user data so far, because pam_systemd will read the XDG_RUNTIME_DIR out of it while starting up - * elogind --user. We need to do user_save_internal() because we have not "officially" started yet. */ - * elogind --user. We need to do user_save_internal() because we have not "officially" started yet. */ - * elogind --user. We need to do user_save_internal() because we have not "officially" started yet. */ - * elogind --user. We need to do user_save_internal() because we have not "officially" started yet. */ - * elogind --user. We need to do user_save_internal() because we have not "officially" started yet. */ + * systemd --user. We need to do user_save_internal() because we have not "officially" started yet. */ user_save_internal(u); - /* Spawn user systemd */ - r = user_start_service(u); - if (r < 0) - return r; +#if 0 /// elogind does not spawn user instances of systemd /* Start user@UID.service */ user_start_service(u); +#endif // 0 if (!u->started) { if (!dual_timestamp_is_set(&u->timestamp)) @@ -430,52 +416,21 @@ int user_start(User *u) { return 0; } -static int user_stop_slice(User *u) { +#if 0 /// elogind does not support user services and systemd units static void user_stop_service(User *u) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; int r; assert(u); assert(u->service); - 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; - if (r < 0) - return log_error_errno(r, "Failed to stop user slice: %s", bus_error_message(&error, r)); - - return r; - return free_and_replace(u->slice_job, job); -} - -static int user_stop_service(User *u) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; - int r; /* The reverse of user_start_service(). Note that we only stop user@UID.service here, and let StopWhenUnneeded= * deal with the slice and the user-runtime-dir@.service instance. */ - assert(u); u->service_job = mfree(u->service_job); - 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; - } r = manager_stop_unit(u->manager, u->service, &error, &u->service_job); if (r < 0) - return log_error_errno(r, "Failed to stop user service: %s", bus_error_message(&error, r)); - - free_and_replace(u->service_job, job); - return r; - return free_and_replace(u->service_job, job); log_warning_errno(r, "Failed to stop user service '%s', ignoring: %s", u->service, bus_error_message(&error, r)); } #endif // 0 @@ -495,9 +450,6 @@ int user_stop(User *u, bool force) { if (u->stopping) { /* Stop jobs have already been queued */ user_save(u); -#if 1 /// elogind must queue this user again - user_add_to_gc_queue(u); -#endif // 1 return 0; } @@ -510,16 +462,13 @@ int user_stop(User *u, bool force) { } #if 0 /// elogind does not support service or slice jobs -#endif // 0 user_stop_service(u); +#endif // 0 u->stopping = true; user_save(u); -#if 1 /// elogind must queue this user again - user_add_to_gc_queue(u); -#endif // 1 return r; } @@ -625,6 +574,7 @@ int user_check_linger_file(User *u) { return true; } +#if 0 /// elogind does not support systemd units static bool user_unit_active(User *u) { const char *i; int r; @@ -645,9 +595,12 @@ static bool user_unit_active(User *u) { return false; } +#endif // 0 bool user_may_gc(User *u, bool drop_not_started) { +#if 0 /// UNNEEDED by elogind int r; +#endif // 0 assert(u); @@ -670,7 +623,11 @@ bool user_may_gc(User *u, bool drop_not_started) { /* Is this a user that shall stay around forever ("linger")? Before we say "no" to GC'ing for lingering users, let's check * if any of the three units that we maintain for this user is still around. If none of them is, * there's no need to keep this user around even if lingering is enabled. */ +#if 0 /// elogind does not support systemd units if (user_check_linger_file(u) > 0 && user_unit_active(u)) +#else + if (user_check_linger_file(u) > 0) +#endif // 0 return false; #if 0 /// elogind neither supports service nor slice jobs @@ -678,16 +635,15 @@ bool user_may_gc(User *u, bool drop_not_started) { if (u->service_job) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; -#endif // 0 r = manager_job_is_active(u->manager, u->service_job, &error); if (r < 0) log_debug_errno(r, "Failed to determine whether job '%s' is pending, ignoring: %s", u->service_job, bus_error_message(&error, r)); if (r != 0) return false; } - /* Note that we don't care if the three units we manage for each user object are up or not, as we are managing * their state rather than tracking it. */ +#endif // 0 return true; } @@ -733,7 +689,11 @@ UserState user_get_state(User *u) { return all_closing ? USER_CLOSING : USER_ONLINE; } +#if 0 /// elogind does not support systemd units if (user_check_linger_file(u) > 0 && user_unit_active(u)) +#else + if (user_check_linger_file(u) > 0) +#endif // 0 return USER_LINGERING; return USER_CLOSING; diff --git a/src/login/logind.c b/src/login/logind.c index c5d526b4b..fcb70e1a9 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -49,11 +49,11 @@ static int manager_new(Manager **ret) { if (!m) return -ENOMEM; -#if 0 /// UNNEEDED by elogind -#endif // 0 *m = (Manager) { .console_active_fd = -1, +#if 0 /// elogind does not support autospawning of vts .reserve_vt_fd = -1, +#endif // 0 }; m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); @@ -66,10 +66,14 @@ static int manager_new(Manager **ret) { m->inhibitors = hashmap_new(&string_hash_ops); m->buttons = hashmap_new(&string_hash_ops); +#if 0 /// elogind does not support units m->user_units = hashmap_new(&string_hash_ops); m->session_units = hashmap_new(&string_hash_ops); if (!m->devices || !m->seats || !m->sessions || !m->sessions_by_leader || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units) +#else + if (!m->devices || !m->seats || !m->sessions || !m->sessions_by_leader || !m->users || !m->inhibitors || !m->buttons) +#endif // 0 return -ENOMEM; #if 1 /// elogind needs some more data @@ -138,8 +142,10 @@ static Manager* manager_unref(Manager *m) { hashmap_free(m->inhibitors); hashmap_free(m->buttons); +#if 0 /// elogind does not support systemd units. hashmap_free(m->user_units); hashmap_free(m->session_units); +#endif // 0 sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->inhibit_timeout_source); diff --git a/src/login/logind.h b/src/login/logind.h index 4c061a3cb..6db015e82 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -94,8 +94,10 @@ struct Manager { unsigned long session_counter; unsigned long inhibit_counter; +#if 0 /// elogind does not support units Hashmap *session_units; Hashmap *user_units; +#endif // 0 usec_t inhibit_delay_max; usec_t user_stop_delay; @@ -227,9 +229,9 @@ int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error, int manager_stop_unit(Manager *manager, const char *unit, 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); -#endif // 0 int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *error); int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *error); +#endif // 0 /* gperf lookup function */ const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length); diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c index d482f8237..aff039bc7 100644 --- a/src/login/user-runtime-dir.c +++ b/src/login/user-runtime-dir.c @@ -153,6 +153,7 @@ static int do_mount(const char *runtime_path, size_t runtime_dir_size, uid_t uid return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size); } +#if 0 /// elogind already has the runtime path static int do_umount(const char *user) { char runtime_path[sizeof("/run/user") + DECIMAL_STR_MAX(uid_t)]; uid_t uid; @@ -171,6 +172,9 @@ static int do_umount(const char *user) { } xsprintf(runtime_path, "/run/user/" UID_FMT, uid); +#else +static int do_umount(const char *runtime_path) { +#endif // 0 log_debug("Will remove %s", runtime_path); return user_remove_runtime_path(runtime_path); |