chiark / gitweb /
logind: process session/inhibitor fds at higher priority
[elogind.git] / src / login / logind.c
index 8693627f241b556679a4bc85e54c6a96535f0b60..e0cd70448eb4bb8ccd3043d2c429443f662857b8 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
@@ -36,6 +34,7 @@
 #include "fd-util.h"
 #include "formats-util.h"
 #include "logind.h"
+#include "selinux-util.h"
 #include "signal-util.h"
 #include "strv.h"
 #include "udev-util.h"
 #include "musl_missing.h"
 
 static void manager_free(Manager *m);
+static int  manager_parse_config_file(Manager *m);
 
 static Manager *manager_new(void) {
+#ifdef ENABLE_DEBUG_ELOGIND
+        int dbg_cnt;
+#endif // ENABLE_DEBUG_ELOGIND
         Manager *m;
         int r;
 
@@ -60,8 +63,7 @@ static Manager *manager_new(void) {
 
         m->console_active_fd = -1;
 
-/// elogind does not support autospawning of vts
-#if 0
+#if 0 /// elogind does not support autospawning of vts
         m->reserve_vt_fd = -1;
 
         m->n_autovts = 6;
@@ -82,7 +84,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->user_tasks_max = UINT64_C(12288);
 
         m->devices = hashmap_new(&string_hash_ops);
         m->seats = hashmap_new(&string_hash_ops);
@@ -116,22 +118,68 @@ static Manager *manager_new(void) {
         if (r < 0)
                 goto fail;
 
-        m->suspend_mode = NULL;
-        m->suspend_state = strv_new("mem", "standby", "freeze", NULL);
-        if (!m->suspend_state)
-                goto fail;
-        m->hibernate_mode = strv_new("platform", "shutdown", NULL);
-        if (!m->hibernate_mode)
-                goto fail;
-        m->hibernate_state = strv_new("disk", NULL);
-        if (!m->hibernate_state)
-                goto fail;
-        m->hybrid_sleep_mode = strv_new("suspend", "platform", "shutdown", NULL);
-        if (!m->hybrid_sleep_mode)
-                goto fail;
-        m->hybrid_sleep_state = strv_new("disk", NULL);
-        if (!m->hybrid_sleep_state)
-                goto fail;
+        m->suspend_mode       = NULL;
+        m->suspend_state      = NULL;
+        m->hibernate_mode     = NULL;
+        m->hibernate_state    = NULL;
+        m->hybrid_sleep_mode  = NULL;
+        m->hybrid_sleep_state = NULL;
+
+        manager_parse_config_file(m);
+
+        /* Set default Sleep config if not already set by logind.conf */
+        if (!m->suspend_state) {
+                m->suspend_state = strv_new("mem", "standby", "freeze", NULL);
+                if (!m->suspend_state)
+                        goto fail;
+        }
+        if (!m->hibernate_mode) {
+                m->hibernate_mode = strv_new("platform", "shutdown", NULL);
+                if (!m->hibernate_mode)
+                        goto fail;
+        }
+        if (!m->hibernate_state) {
+                m->hibernate_state = strv_new("disk", NULL);
+                if (!m->hibernate_state)
+                        goto fail;
+        }
+        if (!m->hybrid_sleep_mode) {
+                m->hybrid_sleep_mode = strv_new("suspend", "platform", "shutdown", NULL);
+                if (!m->hybrid_sleep_mode)
+                        goto fail;
+        }
+        if (!m->hybrid_sleep_state) {
+                m->hybrid_sleep_state = strv_new("disk", NULL);
+                if (!m->hybrid_sleep_state)
+                        goto fail;
+        }
+
+#ifdef ENABLE_DEBUG_ELOGIND
+        dbg_cnt = -1;
+        while (m->suspend_mode && m->suspend_mode[++dbg_cnt])
+                log_debug_elogind("suspend_mode[%d] = %s",
+                                  dbg_cnt, m->suspend_mode[dbg_cnt]);
+        dbg_cnt = -1;
+        while (m->suspend_state[++dbg_cnt])
+                log_debug_elogind("suspend_state[%d] = %s",
+                                  dbg_cnt, m->suspend_state[dbg_cnt]);
+        dbg_cnt = -1;
+        while (m->hibernate_mode[++dbg_cnt])
+                log_debug_elogind("hibernate_mode[%d] = %s",
+                                  dbg_cnt, m->hibernate_mode[dbg_cnt]);
+        dbg_cnt = -1;
+        while (m->hibernate_state[++dbg_cnt])
+                log_debug_elogind("hibernate_state[%d] = %s",
+                                  dbg_cnt, m->hibernate_state[dbg_cnt]);
+        dbg_cnt = -1;
+        while (m->hybrid_sleep_mode[++dbg_cnt])
+                log_debug_elogind("hybrid_sleep_mode[%d] = %s",
+                                  dbg_cnt, m->hybrid_sleep_mode[dbg_cnt]);
+        dbg_cnt = -1;
+        while (m->hybrid_sleep_state[++dbg_cnt])
+                log_debug_elogind("hybrid_sleep_state[%d] = %s",
+                                  dbg_cnt, m->hybrid_sleep_state[dbg_cnt]);
+#endif // ENABLE_DEBUG_ELOGIND
 
         m->udev = udev_new();
         if (!m->udev)
@@ -218,8 +266,7 @@ static void manager_free(Manager *m) {
         sd_bus_unref(m->bus);
         sd_event_unref(m->event);
 
-/// elogind does not support autospawning of vts
-#if 0
+#if 0 /// elogind does not support autospawning of vts
         safe_close(m->reserve_vt_fd);
 #endif // 0
 
@@ -564,8 +611,7 @@ static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t rev
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
         _cleanup_udev_device_unref_ struct udev_device *d = NULL;
         Manager *m = userdata;
@@ -614,8 +660,7 @@ static int manager_dispatch_console(sd_event_source *s, int fd, uint32_t revents
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 static int manager_reserve_vt(Manager *m) {
         _cleanup_free_ char *p = NULL;
 
@@ -669,7 +714,7 @@ static int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus
 }
 
 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);
@@ -715,8 +760,7 @@ static int manager_connect_bus(Manager *m) {
         if (r < 0)
                 return log_error_errno(r, "Failed to add user enumerator: %m");
 
-/// elogind does not support systemd as PID 1
-#if 0
+#if 0 /// elogind does not support systemd as PID 1
         r = sd_bus_add_match(m->bus,
                              NULL,
                              "type='signal',"
@@ -778,7 +822,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");
 
@@ -955,8 +999,7 @@ static int manager_connect_udev(Manager *m) {
         }
 
         /* Don't bother watching VCSA devices, if nobody cares */
-/// elogind does not support autospawning of vts
-#if 0
+#if 0 /// elogind does not support autospawning of vts
         if (m->n_autovts > 0 && m->console_active_fd >= 0) {
 
                 m->udev_vcsa_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
@@ -1155,8 +1198,7 @@ static int manager_startup(Manager *m) {
         manager_gc(m, false);
 
         /* Reserve the special reserved VT */
-/// elogind does not support autospawning of vts
-#if 0
+#if 0 /// elogind does not support autospawning of vts
         manager_reserve_vt(m);
 #endif // 0
 
@@ -1208,8 +1250,7 @@ static int manager_run(Manager *m) {
 }
 
 static int manager_parse_config_file(Manager *m) {
-/// elogind parses its own config file
-#if 0
+#if 0 /// elogind parses its own config file
 
         assert(m);
 
@@ -1219,20 +1260,16 @@ static int manager_parse_config_file(Manager *m) {
                                  config_item_perf_lookup, logind_gperf_lookup,
                                  false, m);
 #else
-        const char *unit = NULL, *logind_conf, *sections;
-        FILE *file = NULL;
-        bool relaxed = false, allow_include = false, warn = true;
+        const char* logind_conf = getenv("ELOGIND_CONF_FILE");
 
         assert(m);
 
-        logind_conf = getenv("ELOGIND_CONF_FILE");
         if (!logind_conf)
                 logind_conf = PKGSYSCONFDIR "/logind.conf";
-        sections = "Login\0Sleep\0";
 
-        return config_parse(unit, logind_conf, file, sections,
+        return config_parse(NULL, logind_conf, NULL, "Login\0Sleep\0",
                             config_item_perf_lookup, logind_gperf_lookup,
-                            relaxed, allow_include, warn, m);
+                            false, false, true, m);
 #endif // 0
 }
 
@@ -1258,13 +1295,18 @@ 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
          * 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
+#if 0 /// elogind can not rely on systemd to help, so we need a bit more effort than this
         mkdir_label("/run/systemd/seats", 0755);
         mkdir_label("/run/systemd/users", 0755);
         mkdir_label("/run/systemd/sessions", 0755);
@@ -1292,8 +1334,6 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        manager_parse_config_file(m);
-
         r = manager_startup(m);
         if (r < 0) {
                 log_error_errno(r, "Failed to fully start up daemon: %m");