X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Flogin%2Flogind.c;h=8693627f241b556679a4bc85e54c6a96535f0b60;hb=da4b83e77bc603745cf4a365d7f013301ef7fa89;hp=2e4342b0aedf4af9792bae02018107ac46fca38e;hpb=eaca07ccfdf5d7dabc50afc7e539c2413dd69d3e;p=elogind.git diff --git a/src/login/logind.c b/src/login/logind.c index 2e4342b0a..8693627f2 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -20,24 +20,31 @@ ***/ #include -#include #include #include #include +#include "libudev.h" #include "sd-daemon.h" -#include "strv.h" -#include "conf-parser.h" -#include "bus-util.h" + +#include "alloc-util.h" #include "bus-error.h" -#include "udev-util.h" +#include "bus-util.h" +#include "conf-parser.h" +#include "def.h" +#include "dirent-util.h" +#include "fd-util.h" #include "formats-util.h" +#include "logind.h" #include "signal-util.h" +#include "strv.h" +#include "udev-util.h" + +/// additional includes elogind needs +#include "cgroup.h" // From src/core/ #include "label.h" -#include "logind.h" -#include "cgroup.h" -#include "mount-setup.h" -#include "virt.h" +#include "mount-setup.h" // From src/core +#include "musl_missing.h" static void manager_free(Manager *m); @@ -75,6 +82,7 @@ static Manager *manager_new(void) { m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */ + m->user_tasks_max = UINT64_C(4096); m->devices = hashmap_new(&string_hash_ops); m->seats = hashmap_new(&string_hash_ops); @@ -215,12 +223,6 @@ static void manager_free(Manager *m) { safe_close(m->reserve_vt_fd); #endif // 0 - /* Avoid the creation of new processes forked by the - * kernel; at this point, we will not listen to the - * signals anyway */ - if (detect_container() <= 0) - (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER); - manager_shutdown_cgroup(m, true); strv_free(m->kill_only_users); @@ -352,8 +354,7 @@ static int manager_enumerate_seats(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/seats: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/seats: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -389,8 +390,7 @@ static int manager_enumerate_linger_users(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -425,8 +425,7 @@ static int manager_enumerate_users(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/users: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/users: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -466,8 +465,7 @@ static int manager_enumerate_sessions(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/sessions: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/sessions: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -513,8 +511,7 @@ static int manager_enumerate_inhibitors(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m"); } FOREACH_DIRENT(de, d, return -errno) { @@ -729,7 +726,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_job_removed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for JobRemoved: %m"); + return log_error_errno(r, "Failed to add match for JobRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -740,7 +737,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_unit_removed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for UnitRemoved: %m"); + return log_error_errno(r, "Failed to add match for UnitRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -750,7 +747,7 @@ static int manager_connect_bus(Manager *m) { "member='PropertiesChanged'", match_properties_changed, m); if (r < 0) - log_warning_errno(r, "Failed to add match for PropertiesChanged: %m"); + return log_error_errno(r, "Failed to add match for PropertiesChanged: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -761,7 +758,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_reloading, m); if (r < 0) - log_warning_errno(r, "Failed to add match for Reloading: %m"); + return log_error_errno(r, "Failed to add match for Reloading: %m"); r = sd_bus_call_method( m->bus, @@ -771,8 +768,10 @@ static int manager_connect_bus(Manager *m) { "Subscribe", &error, NULL, NULL); - if (r < 0) - log_notice("Failed to enable subscription: %s", bus_error_message(&error, r)); + if (r < 0) { + log_error("Failed to enable subscription: %s", bus_error_message(&error, r)); + return r; + } #endif // 0 r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0); @@ -847,8 +846,7 @@ static int manager_connect_console(Manager *m) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m"); - return -errno; + return log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m"); } r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m); @@ -1210,20 +1208,22 @@ static int manager_run(Manager *m) { } static int manager_parse_config_file(Manager *m) { - const char *unit = NULL, *logind_conf, *sections; - FILE *file = NULL; - bool relaxed = false, allow_include = false, warn = true; +/// elogind parses its own config file +#if 0 assert(m); -/// elogind parses its own config file -#if 0 - return config_parse_many("/etc/systemd/logind.conf", - CONF_DIRS_NULSTR("systemd/logind.conf"), + return config_parse_many(PKGSYSCONFDIR "/logind.conf", + CONF_PATHS_NULSTR("systemd/logind.conf.d"), "Login\0", config_item_perf_lookup, logind_gperf_lookup, false, m); -#endif // 0 +#else + const char *unit = NULL, *logind_conf, *sections; + FILE *file = NULL; + bool relaxed = false, allow_include = false, warn = true; + + assert(m); logind_conf = getenv("ELOGIND_CONF_FILE"); if (!logind_conf) @@ -1233,6 +1233,7 @@ static int manager_parse_config_file(Manager *m) { return config_parse(unit, logind_conf, file, sections, config_item_perf_lookup, logind_gperf_lookup, relaxed, allow_include, warn, m); +#endif // 0 } int main(int argc, char *argv[]) { @@ -1262,6 +1263,12 @@ int main(int argc, char *argv[]) { * existence of /run/systemd/seats/ to determine whether * logind is available, so please always make sure this check * stays in. */ +/// elogind can not rely on systemd to help, so we need a bit more effort than this +#if 0 + mkdir_label("/run/systemd/seats", 0755); + mkdir_label("/run/systemd/users", 0755); + mkdir_label("/run/systemd/sessions", 0755); +#else r = mkdir_label("/run/systemd", 0755); if ( (r < 0) && (-EEXIST != r) ) return log_error_errno(r, "Failed to create /run/systemd : %m"); @@ -1277,6 +1284,7 @@ int main(int argc, char *argv[]) { r = mkdir_label("/run/systemd/machines", 0755); if ( r < 0 && (-EEXIST != r) ) return log_error_errno(r, "Failed to create /run/systemd/machines : %m"); +#endif // 0 m = manager_new(); if (!m) { @@ -1292,7 +1300,7 @@ int main(int argc, char *argv[]) { goto finish; } - log_debug("logind running as pid "PID_FMT, getpid()); + log_debug("elogind running as pid "PID_FMT, getpid()); sd_notify(false, "READY=1\n" @@ -1300,7 +1308,7 @@ int main(int argc, char *argv[]) { r = manager_run(m); - log_debug("logind stopped as pid "PID_FMT, getpid()); + log_debug("elogind stopped as pid "PID_FMT, getpid()); finish: sd_notify(false,