summaryrefslogtreecommitdiff
path: root/src/login/logind.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/login/logind.c')
-rw-r--r--src/login/logind.c261
1 files changed, 149 insertions, 112 deletions
diff --git a/src/login/logind.c b/src/login/logind.c
index e0cd70448..4c0b1df0e 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -22,7 +22,11 @@
#include <string.h>
#include <unistd.h>
+#if 0 /// elogind needs the systems udev header
#include "libudev.h"
+#else
+#include <libudev.h>
+#endif // 0
#include "sd-daemon.h"
#include "alloc-util.h"
@@ -46,26 +50,14 @@
#include "musl_missing.h"
static void manager_free(Manager *m);
-static int manager_parse_config_file(Manager *m);
-static Manager *manager_new(void) {
+static void manager_reset_config(Manager *m) {
+
#ifdef ENABLE_DEBUG_ELOGIND
int dbg_cnt;
#endif // ENABLE_DEBUG_ELOGIND
- Manager *m;
- int r;
-
- m = new0(Manager, 1);
- if (!m)
- return NULL;
-
- m->pin_cgroupfs_fd = -1;
-
- m->console_active_fd = -1;
#if 0 /// elogind does not support autospawning of vts
- m->reserve_vt_fd = -1;
-
m->n_autovts = 6;
m->reserve_vt = 6;
#endif // 0
@@ -76,83 +68,37 @@ 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->user_tasks_max = UINT64_C(12288);
-
- m->devices = hashmap_new(&string_hash_ops);
- m->seats = hashmap_new(&string_hash_ops);
- m->sessions = hashmap_new(&string_hash_ops);
- m->users = hashmap_new(NULL);
- 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->running_as = MANAGER_SYSTEM;
- m->test_run = false;
-
- if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units)
- goto fail;
-
- m->kill_exclude_users = strv_new("root", NULL);
- if (!m->kill_exclude_users)
- goto fail;
-
- /* If elogind should be its own controller, mount its cgroup */
- if (streq(SYSTEMD_CGROUP_CONTROLLER, "name=elogind")) {
- r = mount_setup(true);
- if (r < 0)
- goto fail;
- }
-
- /* Make cgroups */
- r = manager_setup_cgroup(m);
- if (r < 0)
- goto fail;
+ m->user_tasks_max = 12288;
+ m->sessions_max = 8192;
+ m->inhibitors_max = 8192;
- 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;
+ m->kill_user_processes = KILL_USER_PROCESSES;
- manager_parse_config_file(m);
+ m->kill_only_users = strv_free(m->kill_only_users);
+ m->kill_exclude_users = strv_free(m->kill_exclude_users);
/* Set default Sleep config if not already set by logind.conf */
- if (!m->suspend_state) {
+ if (!m->suspend_state)
m->suspend_state = strv_new("mem", "standby", "freeze", NULL);
- if (!m->suspend_state)
- goto fail;
- }
- if (!m->hibernate_mode) {
+ if (!m->hibernate_mode)
m->hibernate_mode = strv_new("platform", "shutdown", NULL);
- if (!m->hibernate_mode)
- goto fail;
- }
- if (!m->hibernate_state) {
+ if (!m->hibernate_state)
m->hibernate_state = strv_new("disk", NULL);
- if (!m->hibernate_state)
- goto fail;
- }
- if (!m->hybrid_sleep_mode) {
+ 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) {
+ 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;
@@ -180,6 +126,57 @@ static Manager *manager_new(void) {
log_debug_elogind("hybrid_sleep_state[%d] = %s",
dbg_cnt, m->hybrid_sleep_state[dbg_cnt]);
#endif // ENABLE_DEBUG_ELOGIND
+}
+
+static Manager *manager_new(void) {
+ Manager *m;
+ int r;
+
+ m = new0(Manager, 1);
+ if (!m)
+ return NULL;
+
+ m->pin_cgroupfs_fd = -1;
+ m->console_active_fd = -1;
+#if 0 /// UNNEEDED by elogind
+ m->reserve_vt_fd = -1;
+#endif // 0
+
+ m->idle_action_not_before_usec = now(CLOCK_MONOTONIC);
+
+ m->devices = hashmap_new(&string_hash_ops);
+ m->seats = hashmap_new(&string_hash_ops);
+ m->sessions = hashmap_new(&string_hash_ops);
+ m->users = hashmap_new(NULL);
+ 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->test_run = false;
+
+ if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units)
+ goto fail;
+
+ /* If elogind should be its own controller, mount its cgroup */
+ if (streq(SYSTEMD_CGROUP_CONTROLLER, "name=elogind")) {
+ r = mount_setup(true);
+ if (r < 0)
+ goto fail;
+ }
+
+ /* Make cgroups */
+ r = manager_setup_cgroup(m);
+ if (r < 0)
+ 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;
m->udev = udev_new();
if (!m->udev)
@@ -191,6 +188,8 @@ static Manager *manager_new(void) {
sd_event_set_watchdog(m->event, true);
+ manager_reset_config(m);
+
return m;
fail:
@@ -251,12 +250,12 @@ static void manager_free(Manager *m) {
safe_close(m->console_active_fd);
- 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);
+ 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);
- udev_unref(m->udev);
+ udev_unref(m->udev);
if (m->unlink_nologin)
(void) unlink("/run/nologin");
@@ -286,6 +285,9 @@ static void manager_free(Manager *m) {
strv_free(m->hybrid_sleep_mode);
strv_free(m->hybrid_sleep_state);
+#if 0 /// UNNEEDED by elogind
+ free(m->action_job);
+#endif // 0
free(m);
}
@@ -686,14 +688,26 @@ static int manager_reserve_vt(Manager *m) {
#endif // 0
static int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
Manager *m = userdata;
- Session *s;
const char *cgroup;
+ Session *s;
+ uid_t sender_uid;
int r;
assert(message);
assert(m);
+ /* only accept org.freedesktop.systemd1.Agent from UID=0 */
+ r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_creds_get_euid(creds, &sender_uid);
+ if (r < 0 || sender_uid != 0)
+ return 0;
+
+ /* parse 'cgroup-empty' notification */
r = sd_bus_message_read(message, "s", &cgroup);
if (r < 0) {
bus_log_parse_error(r);
@@ -729,12 +743,14 @@ static int manager_connect_bus(Manager *m) {
return log_error_errno(r, "Failed to add manager object vtable: %m");
/* elogind relies on signals from its release agent */
- r = sd_bus_add_match(m->bus, NULL,
- "type='signal',"
- "interface='org.freedesktop.elogind.Agent',"
- "member='Released',"
- "path='/org/freedesktop/elogind/agent'",
- signal_agent_released, m);
+ r = sd_bus_add_match(
+ m->bus,
+ NULL,
+ "type='signal',"
+ "interface='org.freedesktop.elogind.Agent',"
+ "member='Released',"
+ "path='/org/freedesktop/elogind/agent'",
+ signal_agent_released, m);
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/seat", "org.freedesktop.login1.Seat", seat_vtable, seat_object_find, m);
if (r < 0)
@@ -1134,6 +1150,43 @@ 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) {
+#if 0 /// elogind parses its own config file
+ assert(m);
+
+ 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);
+#else
+ const char* logind_conf = getenv("ELOGIND_CONF_FILE");
+
+ assert(m);
+
+ if (!logind_conf)
+ logind_conf = PKGSYSCONFDIR "/logind.conf";
+
+ return config_parse(NULL, logind_conf, NULL, "Login\0Sleep\0",
+ config_item_perf_lookup, logind_gperf_lookup,
+ false, false, true, m);
+#endif // 0
+}
+
+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;
@@ -1145,6 +1198,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)
@@ -1249,30 +1308,6 @@ static int manager_run(Manager *m) {
}
}
-static int manager_parse_config_file(Manager *m) {
-#if 0 /// elogind parses its own config file
-
- assert(m);
-
- 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);
-#else
- const char* logind_conf = getenv("ELOGIND_CONF_FILE");
-
- assert(m);
-
- if (!logind_conf)
- logind_conf = PKGSYSCONFDIR "/logind.conf";
-
- return config_parse(NULL, logind_conf, NULL, "Login\0Sleep\0",
- config_item_perf_lookup, logind_gperf_lookup,
- false, false, true, m);
-#endif // 0
-}
-
int main(int argc, char *argv[]) {
Manager *m = NULL;
int r;
@@ -1334,6 +1369,8 @@ 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");
@@ -1355,7 +1392,7 @@ finish:
"STOPPING=1\n"
"STATUS=Shutting down...");
- manager_free(m);
+ manager_free(m);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}