chiark / gitweb /
Handle suspend/hibernate/hybrid-suspend/shutdown/reboot directly
authorAndy Wingo <wingo@pobox.com>
Sun, 23 Aug 2015 12:54:39 +0000 (14:54 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:15:07 +0000 (10:15 +0100)
* configure.ac: Get paths of halt and reboot.
* Makefile.am (systemsleepdir, systemshutdowndir): New variables.  Look
  in them for hooks to run.

* src/login/logind-action.c: Inline the salient bits from systemd's
  system-sleep.c here.

* src/login/logind-dbus.c (execute_shutdown_or_sleep): Call our own
  shutdown_or_sleep helper instead of invoking a systemd method.

* src/login/logind.h: Declare shutdown_or_sleep.

src/login/logind-action.c
src/login/logind-dbus.c
src/login/logind.h

index 16e1d9b59f6ce97a2b91db73fb23849343848335..7a57e1ba222ff63dead57fc6aa02f95e6b808dfd 100644 (file)
@@ -226,7 +226,8 @@ static int write_state(FILE **f, char **states) {
         return r;
 }
 
-static int do_sleep(const char *arg_verb, const char **modes, const char **states) {
+static int do_sleep(const char *arg_verb) {
+        _cleanup_strv_free_ char **modes = NULL, **states = NULL;
         char *arguments[] = {
                 NULL,
                 (char*) "pre",
@@ -237,6 +238,10 @@ static int do_sleep(const char *arg_verb, const char **modes, const char **state
         int r;
         _cleanup_fclose_ FILE *f = NULL;
 
+        r = parse_sleep_config(arg_verb, &modes, &states);
+        if (r < 0)
+                return r;
+
         /* This file is opened first, so that if we hit an error,
          * we can abort before modifying any state. */
         f = fopen("/sys/power/state", "we");
@@ -272,7 +277,7 @@ static int do_sleep(const char *arg_verb, const char **modes, const char **state
         return r;
 }
 
-int shutdown_or_sleep(Manager *m, HandleAction action) {
+int shutdown_or_sleep(HandleAction action) {
         switch (action) {
         case HANDLE_POWEROFF:
                 return run_helper(HALT);
@@ -283,11 +288,11 @@ int shutdown_or_sleep(Manager *m, HandleAction action) {
         case HANDLE_KEXEC:
                 return run_helper(KEXEC);
         case HANDLE_SUSPEND:
-                return do_sleep("suspend", m->suspend_mode, m->suspend_state);
+                return do_sleep("suspend");
         case HANDLE_HIBERNATE:
-                return do_sleep("hibernate", m->hibernate_mode, m->hibernate_state);
+                return do_sleep("hibernate");
         case HANDLE_HYBRID_SLEEP:
-                return do_sleep("hybrid-sleep", m->hybrid_sleep_mode, m->hybrid_sleep_state);
+                return do_sleep("hybrid-sleep");
         default:
                 return -EINVAL;
         }
index 448f66c93f3864537e4ac12ac132b8c40b82c486..bf1e7ee8ea8d5a4620d53acf5284cc81443f96b1 100644 (file)
@@ -1422,10 +1422,6 @@ static int execute_shutdown_or_sleep(
                 InhibitWhat w,
                 HandleAction action,
                 sd_bus_error *error) {
-
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
-        const char *p;
-        char *c;
         int r;
 
         assert(m);
@@ -1436,26 +1432,10 @@ static int execute_shutdown_or_sleep(
 
         /* FIXME: here do the thing.  */
 
-        r = sd_bus_call_method(
-                        m->bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "StartUnit",
-                        error,
-                        &reply,
-                        "ss", NULL, "replace-irreversibly");
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_read(reply, "o", &p);
+        r = shutdown_or_sleep(action);
         if (r < 0)
                 return r;
 
-        c = strdup(p);
-        if (!c)
-                return -ENOMEM;
-
         /* Make sure the lid switch is ignored for a while (?) */
         manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
 
index d1fabf5aa7f7905d78183a6df2cf0c0f73a92161..6644ac08688c9629aab80712c7db60fa3b549d25 100644 (file)
@@ -143,6 +143,7 @@ bool manager_is_docked_or_external_displays(Manager *m);
 extern const sd_bus_vtable manager_vtable[];
 
 int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, InhibitWhat w, sd_bus_error *error);
+int shutdown_or_sleep(HandleAction action);
 
 int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;