2013-04-23 11:39:56 +02:00
|
|
|
From: Frederic Crozat <fcrozat@suse.com>
|
|
|
|
Date: Tue, 19 Feb 2013 11:20:31 +0100
|
|
|
|
Subject: Forward suspend / hibernate calls to pm-utils
|
|
|
|
|
|
|
|
forward suspend/hibernation calls to pm-utils, if installed (bnc#790157)
|
|
|
|
---
|
2015-03-27 09:39:40 +01:00
|
|
|
src/sleep/sleep.c | 27 ++++++++++++++++++++++-----
|
|
|
|
1 file changed, 22 insertions(+), 5 deletions(-)
|
2013-04-23 11:39:56 +02:00
|
|
|
|
2015-03-27 09:39:40 +01:00
|
|
|
Index: systemd/src/sleep/sleep.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd.orig/src/sleep/sleep.c
|
|
|
|
+++ systemd/src/sleep/sleep.c
|
2013-06-05 13:16:22 +02:00
|
|
|
@@ -24,6 +24,7 @@
|
2013-02-20 17:46:33 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2013-06-05 13:16:22 +02:00
|
|
|
#include <getopt.h>
|
2013-02-20 17:46:33 +01:00
|
|
|
+#include <stdlib.h>
|
|
|
|
|
2015-03-27 09:39:40 +01:00
|
|
|
#include "sd-id128.h"
|
|
|
|
#include "sd-messages.h"
|
|
|
|
@@ -36,6 +37,8 @@
|
|
|
|
#include "def.h"
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
static char* arg_verb = NULL;
|
|
|
|
+static bool delegate_to_pmutils = false;
|
|
|
|
+static const char *pmtools;
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
static int write_mode(char **modes) {
|
|
|
|
int r = 0;
|
2015-03-27 09:39:40 +01:00
|
|
|
@@ -53,10 +56,6 @@ static int write_mode(char **modes) {
|
|
|
|
if (r == 0)
|
2013-06-05 13:16:22 +02:00
|
|
|
r = k;
|
2013-02-20 17:46:33 +01:00
|
|
|
}
|
2015-03-27 09:39:40 +01:00
|
|
|
-
|
2013-06-05 13:16:22 +02:00
|
|
|
- if (r < 0)
|
2015-03-27 09:39:40 +01:00
|
|
|
- log_error_errno(r, "Failed to write mode to /sys/power/disk: %m");
|
|
|
|
-
|
2013-06-05 13:16:22 +02:00
|
|
|
return r;
|
|
|
|
}
|
2015-03-27 09:39:40 +01:00
|
|
|
|
|
|
|
@@ -97,6 +96,8 @@ static int execute(char **modes, char **
|
|
|
|
int r;
|
2014-03-11 09:24:11 +01:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2013-06-05 13:16:22 +02:00
|
|
|
|
|
|
|
+ if (!delegate_to_pmutils) {
|
2013-02-20 17:46:33 +01:00
|
|
|
+
|
2013-06-05 13:16:22 +02:00
|
|
|
/* This file is opened first, so that if we hit an error,
|
2014-03-11 09:24:11 +01:00
|
|
|
* we can abort before modifying any state. */
|
2013-02-20 17:46:33 +01:00
|
|
|
f = fopen("/sys/power/state", "we");
|
2015-03-27 09:39:40 +01:00
|
|
|
@@ -107,6 +108,7 @@ static int execute(char **modes, char **
|
2013-06-05 13:16:22 +02:00
|
|
|
r = write_mode(modes);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-02-20 17:46:33 +01:00
|
|
|
+ }
|
2013-06-05 13:16:22 +02:00
|
|
|
|
2015-03-27 09:39:40 +01:00
|
|
|
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, arguments);
|
|
|
|
|
|
|
|
@@ -115,8 +117,10 @@ static int execute(char **modes, char **
|
|
|
|
LOG_MESSAGE("Suspending system..."),
|
|
|
|
"SLEEP=%s", arg_verb,
|
2013-06-05 13:16:22 +02:00
|
|
|
NULL);
|
|
|
|
-
|
|
|
|
+ if (!delegate_to_pmutils)
|
2014-03-11 09:24:11 +01:00
|
|
|
r = write_state(&f, states);
|
2013-06-05 13:16:22 +02:00
|
|
|
+ else
|
|
|
|
+ r = -system(pmtools);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2015-03-27 09:39:40 +01:00
|
|
|
@@ -156,6 +160,7 @@ static int parse_argv(int argc, char *ar
|
2013-06-05 13:16:22 +02:00
|
|
|
};
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
int c;
|
|
|
|
+ struct stat buf;
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
assert(argc >= 0);
|
|
|
|
assert(argv);
|
2015-03-27 09:39:40 +01:00
|
|
|
@@ -193,6 +198,18 @@ static int parse_argv(int argc, char *ar
|
2013-06-05 13:16:22 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-02-20 17:46:33 +01:00
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
+ if (streq(arg_verb, "suspend")) {
|
|
|
|
+ pmtools = "/usr/sbin/pm-suspend";
|
|
|
|
+ }
|
|
|
|
+ else if (streq(arg_verb, "hibernate") || streq(arg_verb, "hybrid-sleep")) {
|
|
|
|
+ if (streq(arg_verb, "hibernate"))
|
|
|
|
+ pmtools = "/usr/sbin/pm-hibernate";
|
|
|
|
+ else
|
|
|
|
+ pmtools = "/usr/sbin/pm-suspend-hybrid";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ delegate_to_pmutils = (stat(pmtools, &buf) >= 0 && S_ISREG(buf.st_mode) && (buf.st_mode & 0111));
|
|
|
|
+
|
|
|
|
return 1 /* work to do */;
|
|
|
|
}
|
2013-02-20 17:46:33 +01:00
|
|
|
|