***/
#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 "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);
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;
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);
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);
strv_free(m->kill_only_users);
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) {
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) {
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) {
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) {
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) {
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;
return 0;
}
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
static int manager_reserve_vt(Manager *m) {
_cleanup_free_ char *p = NULL;
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',"
"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,
"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,
"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,
"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,
"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 (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);
}
/* 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");
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
}
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;
+#if 0 /// elogind parses its own config file
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)
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[]) {
* 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");
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) {
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"
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,