[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#780697: marked as done (systemd-shim: does not support hybrid-sleep)



Your message dated Mon, 16 Jan 2017 17:49:28 +0000
with message-id <E1cTBPM-000EY4-7C@fasolo.debian.org>
and subject line Bug#780697: fixed in systemd-shim 10-3~exp2
has caused the Debian Bug report #780697,
regarding systemd-shim: does not support hybrid-sleep
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
780697: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=780697
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: systemd-shim
Version: 9-1
Severity: normal
Tags: upstream patch

Hi,

the systemd-shim is currently lacking support for hybrid sleep.
Since e.g. upower by default tries to trigger hybrid sleep on laptops
when the battery goes critically low, this can lead to data loss.

(To make the current situation worse, invoking
org.freedesktop.login1.Manager.HybridSleep on the dbus fails with the
misleading error message

  Error org.freedesktop.DBus.Error.FileNotFound: Unknown unit: hybrid-sleep.target

which does *not* imply that /lib/systemd/system/hybrid-sleep.target does
not exist.)

I have cooked up a patch that adds hybrid sleep support to the systemd
shim.  It would be great if you could apply it to the Debian package.

Thanks,
Nikolaus

-- System Information:
Debian Release: 8.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Foreign Architectures: armhf

Kernel: Linux 3.16.0-4-686-pae (SMP w/2 CPU cores)
Locale: LANG=de_DE.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages systemd-shim depends on:
ii  cgmanager     0.36-2
ii  libc6         2.19-17
ii  libglib2.0-0  2.42.1-1

systemd-shim recommends no packages.

Versions of packages systemd-shim suggests:
ii  pm-utils  1.4.1-15

-- no debconf information
diff --git a/src/power-unit.c b/src/power-unit.c
index 45dc70c..b55c1b7 100644
--- a/src/power-unit.c
+++ b/src/power-unit.c
@@ -32,7 +32,8 @@ const gchar *power_cmds[] = {
   [POWER_OFF] = "/sbin/shutdown -h now",
   [POWER_REBOOT] = "/sbin/reboot",
   [POWER_SUSPEND] = "/usr/sbin/pm-suspend",
-  [POWER_HIBERNATE] = "/usr/sbin/pm-hibernate"
+  [POWER_HIBERNATE] = "/usr/sbin/pm-hibernate",
+  [POWER_HYBRID_SLEEP] = "/usr/sbin/pm-suspend-hybrid"
 };
 
 typedef struct
@@ -45,6 +46,61 @@ G_DEFINE_TYPE (PowerUnit, power_unit, UNIT_TYPE)
 
 gboolean in_shutdown;
 
+static gint
+set_hibernation_mode (const gchar *mode, gchar **previous_mode)
+{
+  gint fd, cnt;
+
+  g_return_val_if_fail (mode != NULL, -1);
+
+  fd = open ("/sys/power/disk", O_RDWR);
+  if (fd == -1)
+    {
+      g_warning ("Could not open /sys/power/disk");
+      return -1;
+    }
+
+  if (previous_mode)
+    {
+      /* When reading /sys/power/disk, each supported mode is output with a
+       * space appended, and the active mode is put in brackets.
+       */
+      gchar hibernation_modes[sizeof "platform [shutdown] reboot suspend \n"];
+      gchar *active_hibernation_mode, *end;
+
+      *previous_mode = NULL;
+
+      cnt = read (fd, hibernation_modes, sizeof hibernation_modes);
+      if (cnt == -1 || cnt == sizeof hibernation_modes)
+        goto parse_error;
+
+      active_hibernation_mode = strchr (hibernation_modes, '[');
+      if (active_hibernation_mode == NULL)
+        goto parse_error;
+      ++active_hibernation_mode;
+      end = strchr (active_hibernation_mode, ']');
+      if (end == NULL)
+        goto parse_error;
+      *end = '\0';
+
+      if (!g_str_equal (active_hibernation_mode, "disabled"))
+        *previous_mode = g_strdup (active_hibernation_mode);
+    }
+
+  cnt = write (fd, mode, strlen (mode));
+  if (cnt != strlen (mode))
+    goto error;
+
+  close (fd);
+  return 0;
+
+parse_error:
+  g_warning ("Error decoding /sys/power/disk");
+error:
+  close (fd);
+  return -1;
+}
+
 static void
 power_unit_start (Unit *unit)
 {
@@ -89,7 +145,8 @@ power_unit_start (Unit *unit)
        * timestamp of the event that caused the suspend all the way
        * down.
        */
-      if (pu->action == POWER_SUSPEND && last_suspend_time + G_TIME_SPAN_SECOND > g_get_monotonic_time ())
+      if ((pu->action == POWER_SUSPEND || pu->action == POWER_HYBRID_SLEEP) &&
+          last_suspend_time + G_TIME_SPAN_SECOND > g_get_monotonic_time ())
         return;
 
       /* pm-utils might not have been installed, so go the direct route
@@ -104,6 +161,13 @@ power_unit_start (Unit *unit)
         {
           const gchar *kind;
           gint fd;
+          gchar *previous_hibernation_mode;
+
+          if (pu->action == POWER_HYBRID_SLEEP)
+            {
+              if (set_hibernation_mode ("suspend", &previous_hibernation_mode) != 0)
+                g_warning ("Could not set hibernation mode");
+            }
 
           fd = open ("/sys/power/state", O_WRONLY);
           if (fd == -1)
@@ -116,9 +180,16 @@ power_unit_start (Unit *unit)
           if (write (fd, kind, strlen (kind)) != strlen (kind))
             g_warning ("Failed to write() to /sys/power/state?!?");
           close (fd);
+
+          if (previous_hibernation_mode)
+            {
+              if (set_hibernation_mode (previous_hibernation_mode, NULL) != 0)
+                g_warning ("Could not reset hibernation mode");
+              g_free (previous_hibernation_mode);
+            }
         }
 
-      if (pu->action == POWER_SUSPEND)
+      if (pu->action == POWER_SUSPEND || pu->action == POWER_HYBRID_SLEEP)
         last_suspend_time = g_get_monotonic_time ();
     }
 }
diff --git a/src/unit.c b/src/unit.c
index d04c94e..27d21ef 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -46,6 +46,9 @@ lookup_unit (const gchar  *unit_name,
   else if (g_str_equal (unit_name, "hibernate.target"))
     unit = power_unit_new (POWER_HIBERNATE);
 
+  else if (g_str_equal (unit_name, "hybrid-sleep.target"))
+    unit = power_unit_new (POWER_HYBRID_SLEEP);
+
   else if (g_str_equal (unit_name, "reboot.target"))
     unit = power_unit_new (POWER_REBOOT);
 
diff --git a/src/unit.h b/src/unit.h
index 8e83925..a93821b 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -54,6 +54,7 @@ typedef enum
   POWER_REBOOT,
   POWER_SUSPEND,
   POWER_HIBERNATE,
+  POWER_HYBRID_SLEEP,
   N_POWER_ACTIONS
 } PowerAction;
 

--- End Message ---
--- Begin Message ---
Source: systemd-shim
Source-Version: 10-3~exp2

We believe that the bug you reported is fixed in the latest version of
systemd-shim, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 780697@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Ian Jackson <ijackson@chiark.greenend.org.uk> (supplier of updated systemd-shim package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Mon, 16 Jan 2017 17:24:44 +0000
Source: systemd-shim
Binary: systemd-shim
Architecture: source
Version: 10-3~exp2
Distribution: experimental
Urgency: medium
Maintainer: Debian QA Group <packages@qa.debian.org>
Changed-By: Ian Jackson <ijackson@chiark.greenend.org.uk>
Description:
 systemd-shim - shim for systemd
Closes: 780697 851566
Changes:
 systemd-shim (10-3~exp2) experimental; urgency=medium
 .
   * QA upload.
 .
   [ Ian Jackson ]
   * Wrapper script moved to libexec, as it contains an arch-specific path
     and is therefore itself arch-specific.  Closes:#851566.
   * Fix my email address in changelog entry for 10-3~exp1.
 .
   [ Nikolaus Schulz ]
   * Support hybrid-sleep.  Closes:#780697.
Checksums-Sha1:
 be475f14bda75f0b3b90adade7a75b7c6e0d249d 1830 systemd-shim_10-3~exp2.dsc
 1c59360f5f56596d3b14d665ac6e27ee5948d50e 8896 systemd-shim_10-3~exp2.debian.tar.xz
Checksums-Sha256:
 8f370c53bbb47290a4891e51d995e137b71e59bf4ba9f2c9277eba07e7a2f6b4 1830 systemd-shim_10-3~exp2.dsc
 07ac1ab00f5ddd72a53e13712b3a4e583ed9f792bad5a073ed207c03dbb9d6e7 8896 systemd-shim_10-3~exp2.debian.tar.xz
Files:
 30055400f84077e88072ebd5c6f2e243 1830 admin extra systemd-shim_10-3~exp2.dsc
 90bc99961b5d8dd439bccb4ce4e45811 8896 admin extra systemd-shim_10-3~exp2.debian.tar.xz

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEVZrkbC1rbTJl58uh4+M5I0i1DTkFAlh9AnsACgkQ4+M5I0i1
DTmyDggAiJoMP3gWfK3YXi15WrwRlH2prEPJ+lRgWli2wJ/JXboW0vVUkdrEM5gt
D3vFf63AboeqYBDKu/ZGg+jpmCigv5v2vCR7Z0PfIxB9WHG7/zZriu9KLoHuhFJi
34MNvAc8WJAUbVO8SFeyDXobgmAlRVJFFTkm5Ef1A4h7KvftxR1d5jhBLzevXBnC
mmtfRXYGnpZZItW/x2bBA7gtvWQo3Ufm2WMk7ureN8riFJfGsRJE2mKbzs6gAQ3+
zpDVrLrl44YuJ2YsOlHOfsskwzh1oD/8MQfjNl1TmI991mt2xO9+YABuysj2gVTp
wEMbQX/JvD5vjMTfmbSWYjAa/rgcZQ==
=efHc
-----END PGP SIGNATURE-----

--- End Message ---

Reply to: