chiark / gitweb /
Incorporate sleep.conf into logind.conf
authorSven Eden <yamakuzure@gmx.net>
Thu, 2 Feb 2017 08:10:41 +0000 (09:10 +0100)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:23:13 +0000 (10:23 +0100)
* src/login/logind-action.c (shutdown_or_sleep, do_sleep): Take modes
  from the manager instead of parsing them ourselves.

* src/login/logind-dbus.c (execute_shutdown_or_sleep): Adapt to
  shutdown_or_sleep prototype change.

* src/login/logind-gperf.gperf: Add config items from sleep.conf.
* src/login/logind.c (manager_new): Wire up defaults for new config
  items.
  (manager_free): Free new config items.
  (manager_parse_config_file): Arrange to parse a single
  elogind/logind.conf file, not grovelling all over the filesystem.
  Take the file from the ELOGIND_CONF_FILE environment variable if
  present.

Makefile.am
src/login/logind-action.c
src/login/logind-action.h
src/login/logind-dbus.c
src/login/logind-gperf.gperf
src/login/logind.c
src/login/logind.conf [moved from src/login/elogind.conf with 84% similarity]
src/login/logind.h

index 6e8805898aa6d564b3a6a6e56015c8b29f17285f..9800c47f15bf7b412afb180c16c01e25b02028f3 100644 (file)
@@ -730,7 +730,7 @@ dist_dbuspolicy_DATA += \
        src/login/org.freedesktop.login1.conf
 
 dist_pkgsysconf_DATA += \
-       src/login/elogind.conf
+       src/login/logind.conf
 
 polkitpolicy_files += \
        src/login/org.freedesktop.login1.policy
@@ -791,9 +791,6 @@ sysctl.d/%: sysctl.d/%.in
 %.pc: %.pc.in
        $(SED_PROCESS)
 
-%.conf: %.conf.in
-       $(SED_PROCESS)
-
 shell-completion/%: shell-completion/%.in
        $(SED_PROCESS)
 
index eba097c61dcb4f0f656a7b294bc4de73d3bc3ad8..5406cd45bd8b1fc17e7303cd36418997e3eaa2aa 100644 (file)
@@ -240,8 +240,7 @@ static int write_state(FILE **f, char **states) {
         return r;
 }
 
-static int do_sleep(const char *arg_verb) {
-        _cleanup_strv_free_ char **modes = NULL, **states = NULL;
+static int do_sleep(const char *arg_verb, char **modes, char **states) {
         char *arguments[] = {
                 NULL,
                 (char*) "pre",
@@ -288,7 +287,10 @@ static int do_sleep(const char *arg_verb) {
         return r;
 }
 
-int shutdown_or_sleep(HandleAction action) {
+int shutdown_or_sleep(Manager *m, HandleAction action) {
+
+        assert(m);
+
         switch (action) {
         case HANDLE_POWEROFF:
                 return run_helper(HALT);
@@ -299,11 +301,11 @@ int shutdown_or_sleep(HandleAction action) {
         case HANDLE_KEXEC:
                 return run_helper(KEXEC);
         case HANDLE_SUSPEND:
-                return do_sleep("suspend");
+                return do_sleep("suspend", m->suspend_mode, m->suspend_state);
         case HANDLE_HIBERNATE:
-                return do_sleep("hibernate");
+                return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
         case HANDLE_HYBRID_SLEEP:
-                return do_sleep("hybrid-sleep");
+                return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);
         default:
                 return -EINVAL;
         }
index 5269237c61566fcc6e0ff9c0f9f3a9080268c049..99b06bff8b7a40973ec6ec29c71f7cd0e2e9f856 100644 (file)
@@ -44,7 +44,7 @@ int manager_handle_action(
                 bool ignore_inhibited,
                 bool is_edge);
 
-int shutdown_or_sleep(HandleAction action);
+int shutdown_or_sleep(Manager *m, HandleAction action);
 
 const char* handle_action_to_string(HandleAction h) _const_;
 HandleAction handle_action_from_string(const char *s) _pure_;
index 5245c889803b843eab1f02201d47306e894f8269..b0c15e25332bc5065cf8c5fefc8c31fd1b98ec67 100644 (file)
@@ -1466,7 +1466,7 @@ static int execute_shutdown_or_sleep(
                         &reply,
                         "ss", NULL, "replace-irreversibly");
 #else
-        r = shutdown_or_sleep(action);
+        r = shutdown_or_sleep(m, action);
 #endif // 0
         if (r < 0)
                 return r;
index d9fa06c1f672f6658e9e8addcbecfd98741a7ad1..9705dd5b13a2324d75838045f2d21fd50eafbf8c 100644 (file)
@@ -32,3 +32,9 @@ Login.IdleAction,                  config_parse_handle_action, 0, offsetof(Manag
 Login.IdleActionSec,               config_parse_sec,           0, offsetof(Manager, idle_action_usec)
 Login.RuntimeDirectorySize,        config_parse_tmpfs_size,    0, offsetof(Manager, runtime_dir_size)
 Login.RemoveIPC,                   config_parse_bool,          0, offsetof(Manager, remove_ipc)
+Sleep.SuspendMode,                 config_parse_strv,          0, offsetof(Manager, suspend_mode)
+Sleep.SuspendState,                config_parse_strv,          0, offsetof(Manager, suspend_state)
+Sleep.HibernateMode,               config_parse_strv,          0, offsetof(Manager, hibernate_mode)
+Sleep.HibernateState,              config_parse_strv,          0, offsetof(Manager, hibernate_state)
+Sleep.HybridSleepMode,             config_parse_strv,          0, offsetof(Manager, hybrid_sleep_mode)
+Sleep.HybridSleepState,            config_parse_strv,          0, offsetof(Manager, hybrid_sleep_state)
index 09007c2554343aef4ab7d6304c45c4b7b7ab4343..d60241342216549b5d8cc795a76db252a4f86e5b 100644 (file)
@@ -99,6 +99,23 @@ 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->udev = udev_new();
         if (!m->udev)
                 goto fail;
@@ -197,6 +214,14 @@ 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);
+
         free(m);
 }
 
@@ -1133,13 +1158,29 @@ 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[]) {
similarity index 84%
rename from src/login/elogind.conf
rename to src/login/logind.conf
index 85e297dd38bff9e03e089253117199b63f5864a6..6103e070de1f9570402779d6cc9ad3a731bad5c3 100644 (file)
 #IdleActionSec=30min
 #RuntimeDirectorySize=10%
 #RemoveIPC=yes
+
+[Sleep]
+#SuspendState=mem standby freeze
+#SuspendMode=
+#HibernateState=disk
+#HibernateMode=platform shutdown
+#HybridSleepState=disk
+#HybridSleepMode=suspend platform shutdown
index 67ebbd88cff1a8244df9cff8ca2d445c692bdc63..0b6422fc186af68a861663d858e7777fb32e07e1 100644 (file)
@@ -152,6 +152,10 @@ struct Manager {
 
         bool remove_ipc;
 
+        char **suspend_state,      **suspend_mode;
+        char **hibernate_state,    **hibernate_mode;
+        char **hybrid_sleep_state, **hybrid_sleep_mode;
+
         Hashmap *polkit_registry;
 
         usec_t holdoff_timeout_usec;