#include <string.h>
#include <unistd.h>
+#include "label.h"
#include "sd-daemon.h"
#include "strv.h"
#include "conf-parser.h"
return NULL;
m->console_active_fd = -1;
- m->reserve_vt_fd = -1;
- m->n_autovts = 6;
- m->reserve_vt = 6;
m->remove_ipc = true;
m->inhibit_delay_max = 5 * USEC_PER_SEC;
m->handle_power_key = HANDLE_POWEROFF;
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->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)
+ if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames)
goto fail;
m->kill_exclude_users = strv_new("root", NULL);
if (!m->kill_exclude_users)
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->udev = udev_new();
if (!m->udev)
goto fail;
sd_event_set_watchdog(m->event, true);
+
return m;
fail:
hashmap_free(m->inhibitors);
hashmap_free(m->buttons);
- 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_bus_unref(m->bus);
sd_event_unref(m->event);
- safe_close(m->reserve_vt_fd);
-
strv_free(m->kill_only_users);
strv_free(m->kill_exclude_users);
- free(m->action_job);
+ 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);
+
free(m);
}
return 0;
}
-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;
- const char *name;
-
- assert(m);
-
- d = udev_monitor_receive_device(m->udev_vcsa_monitor);
- if (!d)
- return -ENOMEM;
-
- name = udev_device_get_sysname(d);
-
- /* Whenever a VCSA device is removed try to reallocate our
- * VTs, to make sure our auto VTs never go away. */
-
- if (name && startswith(name, "vcsa") && streq_ptr(udev_device_get_action(d), "remove"))
- seat_preallocate_vts(m->seat0);
-
- return 0;
-}
-
static int manager_dispatch_button_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;
}
-static int manager_reserve_vt(Manager *m) {
- _cleanup_free_ char *p = NULL;
-
- assert(m);
-
- if (m->reserve_vt <= 0)
- return 0;
-
- if (asprintf(&p, "/dev/tty%u", m->reserve_vt) < 0)
- return log_oom();
-
- m->reserve_vt_fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
- if (m->reserve_vt_fd < 0) {
-
- /* Don't complain on VT-less systems */
- if (errno != ENOENT)
- log_warning_errno(errno, "Failed to pin reserved VT: %m");
- return -errno;
- }
-
- return 0;
-}
-
static int manager_connect_bus(Manager *m) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
if (r < 0)
return log_error_errno(r, "Failed to add user enumerator: %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',"
- "path='/org/freedesktop/systemd1'",
- match_job_removed, m);
- if (r < 0)
- return log_error_errno(r, "Failed to add match for JobRemoved: %m");
-
- r = sd_bus_add_match(m->bus,
- NULL,
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.systemd1.Manager',"
- "member='UnitRemoved',"
- "path='/org/freedesktop/systemd1'",
- match_unit_removed, m);
- if (r < 0)
- return log_error_errno(r, "Failed to add match for UnitRemoved: %m");
-
- r = sd_bus_add_match(m->bus,
- NULL,
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged'",
- match_properties_changed, m);
- if (r < 0)
- return log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
-
- r = sd_bus_add_match(m->bus,
- NULL,
- "type='signal',"
- "sender='org.freedesktop.systemd1',"
- "interface='org.freedesktop.systemd1.Manager',"
- "member='Reloading',"
- "path='/org/freedesktop/systemd1'",
- match_reloading, m);
- if (r < 0)
- return log_error_errno(r, "Failed to add match for Reloading: %m");
-
- r = sd_bus_call_method(
- m->bus,
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "Subscribe",
- &error,
- NULL, NULL);
- if (r < 0) {
- log_error("Failed to enable subscription: %s", bus_error_message(&error, r));
- return r;
- }
-
r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0);
if (r < 0)
return log_error_errno(r, "Failed to register name: %m");
return r;
}
- /* Don't bother watching VCSA devices, if nobody cares */
- if (m->n_autovts > 0 && m->console_active_fd >= 0) {
-
- m->udev_vcsa_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
- if (!m->udev_vcsa_monitor)
- return -ENOMEM;
-
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_vcsa_monitor, "vc", NULL);
- if (r < 0)
- return r;
-
- r = udev_monitor_enable_receiving(m->udev_vcsa_monitor);
- if (r < 0)
- return r;
-
- r = sd_event_add_io(m->event, &m->udev_vcsa_event_source, udev_monitor_get_fd(m->udev_vcsa_monitor), EPOLLIN, manager_dispatch_vcsa_udev, m);
- if (r < 0)
- return r;
- }
-
return 0;
}
/* Remove stale objects before we start them */
manager_gc(m, false);
- /* Reserve the special reserved VT */
- manager_reserve_vt(m);
-
/* And start everything */
HASHMAP_FOREACH(seat, m->seats, i)
seat_start(seat);
if (manager_dispatch_delayed(m) > 0)
continue;
- if (m->action_what != 0 && !m->action_job) {
+ if (m->action_what != 0) {
usec_t x, y;
x = now(CLOCK_MONOTONIC);
}
static int manager_parse_config_file(Manager *m) {
+ const char *unit, *logind_conf, *sections;
+ FILE *file;
+ bool relaxed, allow_include, warn;
+
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);
+ unit = NULL;
+ logind_conf = getenv("ELOGIND_CONF_FILE");
+ if (!logind_conf)
+ logind_conf = PKGSYSCONFDIR "/logind.conf";
+ sections = "Login\0Sleep\0";
+ file = NULL;
+ relaxed = false;
+ allow_include = false;
+ warn = true;
+
+ 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[]) {
mkdir_label("/run/systemd/seats", 0755);
mkdir_label("/run/systemd/users", 0755);
mkdir_label("/run/systemd/sessions", 0755);
+ mkdir_label("/run/systemd/machines", 0755);
m = manager_new();
if (!m) {
goto finish;
}
- log_debug("systemd-logind running as pid "PID_FMT, getpid());
+ log_debug("logind running as pid "PID_FMT, getpid());
sd_notify(false,
"READY=1\n"
r = manager_run(m);
- log_debug("systemd-logind stopped as pid "PID_FMT, getpid());
+ log_debug("logind stopped as pid "PID_FMT, getpid());
finish:
sd_notify(false,