[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 Wed, 18 Jan 2017 12:19:22 +0000
with message-id <E1cTpD0-000B96-KC@fasolo.debian.org>
and subject line Bug#780697: fixed in systemd-shim 10-3
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

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: Wed, 18 Jan 2017 12:02:27 +0000
Source: systemd-shim
Binary: systemd-shim
Architecture: source
Version: 10-3
Distribution: unstable
Urgency: high
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 844785 851566
Changes:
 systemd-shim (10-3) unstable; urgency=high
 .
   * QA upload.
   * Upload to unstable, for stretch.
   * No code 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.
 .
 systemd-shim (10-3~exp1) experimental; urgency=high
 .
   QA upload:
   * Install wrapper script to mount /sys/fs/cgroup/systemd.
     Fixes "not authorised" problem with various desktop services,
     when running with newer systemd.  Closes:#844785 in Debian.
     [Michael Biebl, Ian Jackson]
   * Add debian/.gitignore.
Checksums-Sha1:
 ac9bd21e32dafb614761dbdaf44bdb47ba1ace5b 1805 systemd-shim_10-3.dsc
 5fef21f4c86f3461130da8675f427e5380b81566 8948 systemd-shim_10-3.debian.tar.xz
Checksums-Sha256:
 c9e672cbde072b53853774ece75d3562fb539f80feb7f1aa9ce7936fd8a59c6f 1805 systemd-shim_10-3.dsc
 a74e2cacfae5b6db343472742d5d63dfafd90f77bd0210f9e50331b1b445d6e9 8948 systemd-shim_10-3.debian.tar.xz
Files:
 0165bf4d49a9ff08ac5e3077aff13f1f 1805 admin extra systemd-shim_10-3.dsc
 ddcd87c81360b744208329d95510ccd6 8948 admin extra systemd-shim_10-3.debian.tar.xz

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

iQEzBAEBCAAdFiEEVZrkbC1rbTJl58uh4+M5I0i1DTkFAlh/WZQACgkQ4+M5I0i1
DTkT9Qf+M+7Oaz7FtZmKd5vSHwB2N1yTrfkWicGVapo3BcS9/OPPpdsQo1C8oIyI
lNbt3k/ms7f7WeoQLuGGHL1qngzdg75cxOnhqZqXuoFScSlhj6Juo6n+UeYi6kUj
QDXRd36uyXLUmYE/1tcREl80MnpzxdWny6ntXqMfG4eGT8RFPgGKZYWx2xd9VfUG
Hx9ALGB21hY2a8iYx03Na61FoL6muBGw5CW6B3W+tlV1Tqgr/8ZQf1Brom1OfQa0
UYv5/+2DL3imjvjU1GWe1X13BY16ZDEjh2a6cxvhxGHqvb+KI03Ef8YU96D7hxmk
cbcOpqgJ02y4kC+/O0JGkmLwNRCpzg==
=5sqA
-----END PGP SIGNATURE-----

--- End Message ---

Reply to: