chiark / gitweb /
Prep v234: Apply missing upstream fixes in src/login (3/6)
[elogind.git] / src / login / logind.c
index 9e637c7..d46358e 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
 ***/
 
 #include <errno.h>
-#include <libudev.h>
 #include <fcntl.h>
 #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 "strv.h"
-#include "conf-parser.h"
-#include "bus-util.h"
+
+#include "alloc-util.h"
 #include "bus-error.h"
-#include "udev-util.h"
-#include "formats-util.h"
+#include "bus-util.h"
+#include "conf-parser.h"
+#include "def.h"
+#include "dirent-util.h"
+#include "fd-util.h"
+#include "format-util.h"
+#include "logind.h"
+#include "selinux-util.h"
 #include "signal-util.h"
+#include "strv.h"
+#include "udev-util.h"
+/// Additional includes needed by elogind
+#include "cgroup.h"       // From src/core/
+#include "elogind.h"
 #include "label.h"
-#include "logind.h"
-#include "cgroup.h"
-#include "mount-setup.h"
-#include "virt.h"
+#include "musl_missing.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->pin_cgroupfs_fd = -1;
-
-        m->console_active_fd = -1;
-
-/// elogind does not support autospawning of vts
-#if 0
-        m->reserve_vt_fd = -1;
-
+static void manager_reset_config(Manager *m) {
+#if 0 /// elogind does not support autospawning of vts
         m->n_autovts = 6;
         m->reserve_vt = 6;
 #endif // 0
@@ -67,14 +62,44 @@ 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);
+#if 1 /// elogind needs an Add-On for sleep configuration
+        elogind_manager_reset_config(m);
+#endif // 1
+}
+
+static Manager *manager_new(void) {
+        Manager *m;
+        int r;
+
+        m = new0(Manager, 1);
+        if (!m)
+                return NULL;
+
+        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);
@@ -86,45 +111,14 @@ static Manager *manager_new(void) {
         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 1 /// elogind needs some more data
+        r = elogind_manager_new(m);
         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;
-
+#endif // 1
         m->udev = udev_new();
         if (!m->udev)
                 goto fail;
@@ -135,6 +129,8 @@ static Manager *manager_new(void) {
 
         sd_event_set_watchdog(m->event, true);
 
+        manager_reset_config(m);
+
         return m;
 
 fail:
@@ -150,7 +146,8 @@ static void manager_free(Manager *m) {
         Inhibitor *i;
         Button *b;
 
-        assert(m);
+        if (!m)
+                return;
 
         while ((session = hashmap_first(m->sessions)))
                 session_free(session);
@@ -195,12 +192,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");
@@ -210,18 +207,12 @@ 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
-
-        /* Avoid the creation of new processes forked by the
-         * kernel; at this point, we will not listen to the
-         * signals anyway */
-        if (detect_container(NULL) <= 0)
-                (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
-
-        manager_shutdown_cgroup(m, true);
+#if 1 /// elogind has to free its own data
+        elogind_manager_free(m);
+#endif // 1
 
         strv_free(m->kill_only_users);
         strv_free(m->kill_exclude_users);
@@ -229,14 +220,9 @@ static void manager_free(Manager *m) {
         free(m->scheduled_shutdown_type);
         free(m->scheduled_shutdown_tty);
         free(m->wall_message);
-
-        strv_free(m->suspend_mode);
-        strv_free(m->suspend_state);
-        strv_free(m->hibernate_mode);
-        strv_free(m->hibernate_state);
-        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);
 }
 
@@ -352,8 +338,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 +374,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 +409,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) {
@@ -453,10 +436,71 @@ static int manager_enumerate_users(Manager *m) {
         return r;
 }
 
+static int manager_attach_fds(Manager *m) {
+        _cleanup_strv_free_ char **fdnames = NULL;
+        int n, i, fd;
+
+        /* Upon restart, PID1 will send us back all fds of session devices
+         * that we previously opened. Each file descriptor is associated
+         * with a given session. The session ids are passed through FDNAMES. */
+
+        n = sd_listen_fds_with_names(true, &fdnames);
+        if (n <= 0)
+                return n;
+
+        for (i = 0; i < n; i++) {
+                struct stat st;
+                SessionDevice *sd;
+                Session *s;
+                char *id;
+
+                fd = SD_LISTEN_FDS_START + i;
+
+                id = startswith(fdnames[i], "session-");
+                if (!id)
+                        continue;
+
+                s = hashmap_get(m->sessions, id);
+                if (!s) {
+                        /* If the session doesn't exist anymore, the associated session
+                         * device attached to this fd doesn't either. Let's simply close
+                         * this fd. */
+                        log_debug("Failed to attach fd for unknown session: %s", id);
+                        close_nointr(fd);
+                        continue;
+                }
+
+                if (fstat(fd, &st) < 0) {
+                        /* The device is allowed to go away at a random point, in which
+                         * case fstat failing is expected. */
+                        log_debug_errno(errno, "Failed to stat device fd for session %s: %m", id);
+                        close_nointr(fd);
+                        continue;
+                }
+
+                sd = hashmap_get(s->devices, &st.st_rdev);
+                if (!sd) {
+                        /* Weird we got an fd for a session device which wasn't
+                        * recorded in the session state file... */
+                        log_warning("Got fd for missing session device [%u:%u] in session %s",
+                                    major(st.st_rdev), minor(st.st_rdev), s->id);
+                        close_nointr(fd);
+                        continue;
+                }
+
+                log_debug("Attaching fd to session device [%u:%u] for session %s",
+                          major(st.st_rdev), minor(st.st_rdev), s->id);
+
+                session_device_attach_fd(sd, fd, s->was_active);
+        }
+
+        return 0;
+}
+
 static int manager_enumerate_sessions(Manager *m) {
         _cleanup_closedir_ DIR *d = NULL;
         struct dirent *de;
-        int r = 0;
+        int r = 0, k;
 
         assert(m);
 
@@ -466,13 +510,11 @@ 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) {
                 struct Session *s;
-                int k;
 
                 if (!dirent_is_file(de))
                         continue;
@@ -486,7 +528,6 @@ static int manager_enumerate_sessions(Manager *m) {
                 k = manager_add_session(m, de->d_name, &s);
                 if (k < 0) {
                         log_error_errno(k, "Failed to add session by file name %s: %m", de->d_name);
-
                         r = k;
                         continue;
                 }
@@ -498,6 +539,12 @@ static int manager_enumerate_sessions(Manager *m) {
                         r = k;
         }
 
+        /* We might be restarted and PID1 could have sent us back the
+         * session device fds we previously saved. */
+        k = manager_attach_fds(m);
+        if (k < 0)
+                log_warning_errno(k, "Failed to reattach session device fds: %m");
+
         return r;
 }
 
@@ -513,8 +560,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) {
@@ -567,8 +613,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;
@@ -617,8 +662,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;
 
@@ -643,36 +687,8 @@ static int manager_reserve_vt(Manager *m) {
 }
 #endif // 0
 
-static int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus_error *error) {
-        Manager *m = userdata;
-        Session *s;
-        const char *cgroup;
-        int r;
-
-        assert(message);
-        assert(m);
-
-        r = sd_bus_message_read(message, "s", &cgroup);
-        if (r < 0) {
-                bus_log_parse_error(r);
-                return 0;
-        }
-
-        s = hashmap_get(m->sessions, cgroup);
-
-        if (!s) {
-                log_warning("Session not found: %s", cgroup);
-                return 0;
-        }
-
-        session_finalize(s);
-        session_free(s);
-
-        return 0;
-}
-
 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);
@@ -686,14 +702,6 @@ static int manager_connect_bus(Manager *m) {
         if (r < 0)
                 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_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/seat", "org.freedesktop.login1.Seat", seat_vtable, seat_object_find, m);
         if (r < 0)
                 return log_error_errno(r, "Failed to add seat object vtable: %m");
@@ -718,8 +726,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',"
@@ -729,7 +736,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 +747,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 +757,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 +768,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,19 +778,28 @@ 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);
         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");
 
+#if 0 /// elogind has to setup its release agent
         return 0;
+#else
+        elogind_bus_setup_system(m);
+        r = elogind_setup_cgroups_agent(m);
+
+        return r;
+#endif // 0
 }
 
 static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo *si, void *data) {
@@ -847,8 +863,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);
@@ -957,8 +972,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");
@@ -1093,6 +1107,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_nulstr(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;
@@ -1104,6 +1155,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)
@@ -1157,8 +1214,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
 
@@ -1209,32 +1265,6 @@ 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;
-
-        assert(m);
-
-/// elogind parses its own config file
-#if 0
-        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);
-#endif // 0
-
-        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,
-                            config_item_perf_lookup, logind_gperf_lookup,
-                            relaxed, allow_include, warn, m);
-}
-
 int main(int argc, char *argv[]) {
         Manager *m = NULL;
         int r;
@@ -1243,11 +1273,11 @@ int main(int argc, char *argv[]) {
         log_set_target(LOG_TARGET_AUTO);
         log_set_facility(LOG_AUTH);
         log_parse_environment();
-        log_open();
-
 #ifdef ENABLE_DEBUG_ELOGIND
         log_set_max_level(LOG_DEBUG);
+        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
 #endif // ENABLE_DEBUG_ELOGIND
+        log_open();
 
         umask(0022);
 
@@ -1257,11 +1287,22 @@ 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. */
+#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);
+#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 +1318,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 +1334,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,14 +1342,14 @@ 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,
                   "STOPPING=1\n"
                   "STATUS=Shutting down...");
 
-                manager_free(m);
+        manager_free(m);
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }