diff options
Diffstat (limited to 'src/login/logind.c')
-rw-r--r-- | src/login/logind.c | 176 |
1 files changed, 96 insertions, 80 deletions
diff --git a/src/login/logind.c b/src/login/logind.c index e2fb496289..a9a06f5e28 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -20,34 +18,31 @@ ***/ #include <errno.h> -#include <libudev.h> #include <fcntl.h> #include <string.h> #include <unistd.h> +#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 "signal-util.h" #include "logind.h" +#include "selinux-util.h" +#include "signal-util.h" +#include "strv.h" +#include "udev-util.h" +#include "cgroup-util.h" static void manager_free(Manager *m); -static Manager *manager_new(void) { - Manager *m; - int r; - - m = new0(Manager, 1); - if (!m) - return NULL; - - m->console_active_fd = -1; - m->reserve_vt_fd = -1; - +static void manager_reset_config(Manager *m) { m->n_autovts = 6; m->reserve_vt = 6; m->remove_ipc = true; @@ -57,14 +52,39 @@ static Manager *manager_new(void) { m->handle_hibernate_key = HANDLE_HIBERNATE; m->handle_lid_switch = HANDLE_SUSPEND; m->handle_lid_switch_docked = HANDLE_IGNORE; + m->power_key_ignore_inhibited = false; + m->suspend_key_ignore_inhibited = false; + m->hibernate_key_ignore_inhibited = false; m->lid_switch_ignore_inhibited = true; + m->holdoff_timeout_usec = 30 * USEC_PER_SEC; m->idle_action_usec = 30 * USEC_PER_MINUTE; m->idle_action = HANDLE_IGNORE; - m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); - m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */ + m->runtime_dir_size = physical_memory_scale(10U, 100U); /* 10% */ + m->user_tasks_max = system_tasks_max_scale(DEFAULT_USER_TASKS_MAX_PERCENTAGE, 100U); /* 33% */ + m->sessions_max = 8192; + m->inhibitors_max = 8192; + + m->kill_user_processes = KILL_USER_PROCESSES; + + m->kill_only_users = strv_free(m->kill_only_users); + m->kill_exclude_users = strv_free(m->kill_exclude_users); +} + +static Manager *manager_new(void) { + Manager *m; + int r; + + m = new0(Manager, 1); + if (!m) + return NULL; + + m->console_active_fd = -1; + m->reserve_vt_fd = -1; + + m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); m->devices = hashmap_new(&string_hash_ops); m->seats = hashmap_new(&string_hash_ops); @@ -76,14 +96,7 @@ static Manager *manager_new(void) { 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) - goto fail; - - m->kill_exclude_users = strv_new("root", NULL); - if (!m->kill_exclude_users) + if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units) goto fail; m->udev = udev_new(); @@ -96,6 +109,8 @@ static Manager *manager_new(void) { sd_event_set_watchdog(m->event, true); + manager_reset_config(m); + return m; fail: @@ -141,8 +156,6 @@ static void manager_free(Manager *m) { hashmap_free(m->user_units); hashmap_free(m->session_units); - set_free_free(m->busnames); - sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->inhibit_timeout_source); sd_event_source_unref(m->scheduled_shutdown_timeout_source); @@ -158,17 +171,12 @@ static void manager_free(Manager *m) { safe_close(m->console_active_fd); - if (m->udev_seat_monitor) - udev_monitor_unref(m->udev_seat_monitor); - if (m->udev_device_monitor) - udev_monitor_unref(m->udev_device_monitor); - if (m->udev_vcsa_monitor) - udev_monitor_unref(m->udev_vcsa_monitor); - if (m->udev_button_monitor) - udev_monitor_unref(m->udev_button_monitor); + udev_monitor_unref(m->udev_seat_monitor); + udev_monitor_unref(m->udev_device_monitor); + udev_monitor_unref(m->udev_vcsa_monitor); + udev_monitor_unref(m->udev_button_monitor); - if (m->udev) - udev_unref(m->udev); + udev_unref(m->udev); if (m->unlink_nologin) (void) unlink("/run/nologin"); @@ -302,8 +310,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) { @@ -339,8 +346,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) { @@ -375,8 +381,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) { @@ -416,8 +421,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) { @@ -463,8 +467,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) { @@ -588,7 +591,7 @@ static int manager_reserve_vt(Manager *m) { } static int manager_connect_bus(Manager *m) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert(m); @@ -629,17 +632,6 @@ static int manager_connect_bus(Manager *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'," @@ -697,7 +689,7 @@ static int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to register name: %m"); - r = sd_bus_attach_event(m->bus, m->event, 0); + r = sd_bus_attach_event(m->bus, m->event, SD_EVENT_PRIORITY_NORMAL); if (r < 0) return log_error_errno(r, "Failed to attach bus to event loop: %m"); @@ -765,8 +757,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); @@ -923,8 +914,8 @@ static void manager_gc(Manager *m, bool drop_not_started) { session_get_state(session) != SESSION_CLOSING) session_stop(session, false); - /* Normally, this should make the session busy again, - * if it doesn't then let's get rid of it + /* Normally, this should make the session referenced + * again, if it doesn't then let's get rid of it * immediately */ if (!session_check_gc(session, drop_not_started)) { session_finalize(session); @@ -1008,6 +999,30 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us return 0; } +static int manager_parse_config_file(Manager *m) { + assert(m); + + return config_parse_many_nulstr(PKGSYSCONFDIR "/logind.conf", + CONF_PATHS_NULSTR("systemd/logind.conf.d"), + "Login\0", + config_item_perf_lookup, logind_gperf_lookup, + false, m); +} + +static int manager_dispatch_reload_signal(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { + Manager *m = userdata; + int r; + + manager_reset_config(m); + r = manager_parse_config_file(m); + if (r < 0) + log_warning_errno(r, "Failed to parse config file, using defaults: %m"); + else + log_info("Config file reloaded."); + + return 0; +} + static int manager_startup(Manager *m) { int r; Seat *seat; @@ -1019,6 +1034,12 @@ static int manager_startup(Manager *m) { assert(m); + assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGHUP, -1) >= 0); + + r = sd_event_add_signal(m->event, NULL, SIGHUP, manager_dispatch_reload_signal, m); + if (r < 0) + return log_error_errno(r, "Failed to register SIGHUP handler: %m"); + /* Connect to console */ r = manager_connect_console(m); if (r < 0) @@ -1121,16 +1142,6 @@ static int manager_run(Manager *m) { } } -static int manager_parse_config_file(Manager *m) { - assert(m); - - return config_parse_many("/etc/systemd/logind.conf", - CONF_DIRS_NULSTR("systemd/logind.conf"), - "Login\0", - config_item_perf_lookup, logind_gperf_lookup, - false, m); -} - int main(int argc, char *argv[]) { Manager *m = NULL; int r; @@ -1148,6 +1159,12 @@ int main(int argc, char *argv[]) { goto finish; } + r = mac_selinux_init(); + if (r < 0) { + log_error_errno(r, "Could not initialize labelling: %m"); + goto finish; + } + /* Always create the directories people can create inotify * watches in. Note that some applications might check for the * existence of /run/systemd/seats/ to determine whether @@ -1186,8 +1203,7 @@ finish: "STOPPING=1\n" "STATUS=Shutting down..."); - if (m) - manager_free(m); + manager_free(m); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } |