2013-04-13 13:09:53 +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)
|
|
|
|
---
|
|
|
|
src/sleep/sleep.c | 27 ++++++++++++++++++++++++---
|
|
|
|
1 file changed, 24 insertions(+), 3 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
|
2013-04-19 22:31:17 +02:00
|
|
|
index f5e78c1..8d91117 100644
|
2013-04-13 13:09:53 +02:00
|
|
|
--- a/src/sleep/sleep.c
|
|
|
|
+++ b/src/sleep/sleep.c
|
2013-02-20 09:34:16 +01:00
|
|
|
@@ -22,6 +22,7 @@
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2013-04-13 13:09:53 +02:00
|
|
|
@@ -32,6 +33,9 @@
|
2013-02-20 09:34:16 +01:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
const char *verb;
|
|
|
|
char* arguments[4];
|
|
|
|
+ const char *pmtools;
|
|
|
|
+ bool delegate_to_pmutils = false;
|
|
|
|
+ struct stat buf;
|
|
|
|
int r;
|
|
|
|
FILE *f;
|
|
|
|
|
2013-04-13 13:09:53 +02:00
|
|
|
@@ -45,17 +49,27 @@ int main(int argc, char *argv[]) {
|
2013-02-20 09:34:16 +01:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (streq(argv[1], "suspend"))
|
|
|
|
+ if (streq(argv[1], "suspend")) {
|
|
|
|
verb = "mem";
|
|
|
|
- else if (streq(argv[1], "hibernate") || streq(argv[1], "hybrid-sleep"))
|
|
|
|
+ pmtools = "/usr/sbin/pm-suspend";
|
|
|
|
+ }
|
|
|
|
+ else if (streq(argv[1], "hibernate") || streq(argv[1], "hybrid-sleep")) {
|
|
|
|
verb = "disk";
|
|
|
|
+ if (streq(argv[1], "hibernate"))
|
|
|
|
+ pmtools = "/usr/sbin/pm-hibernate";
|
|
|
|
+ else
|
|
|
|
+ pmtools = "/usr/sbin/pm-suspend-hybrid";
|
|
|
|
+ }
|
|
|
|
else {
|
|
|
|
log_error("Unknown action '%s'.", argv[1]);
|
|
|
|
r = -EINVAL;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ delegate_to_pmutils = (stat(pmtools, &buf) >= 0 && S_ISREG(buf.st_mode) && (buf.st_mode & 0111));
|
|
|
|
+
|
|
|
|
/* Configure the hibernation mode */
|
|
|
|
+ if (!delegate_to_pmutils) {
|
|
|
|
if (streq(argv[1], "hibernate")) {
|
2013-04-19 22:31:17 +02:00
|
|
|
if (write_string_file("/sys/power/disk", "platform") < 0)
|
|
|
|
write_string_file("/sys/power/disk", "shutdown");
|
2013-04-13 13:09:53 +02:00
|
|
|
@@ -65,13 +79,14 @@ int main(int argc, char *argv[]) {
|
2013-04-19 22:31:17 +02:00
|
|
|
write_string_file("/sys/power/disk", "shutdown");
|
2013-02-20 09:34:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
f = fopen("/sys/power/state", "we");
|
|
|
|
if (!f) {
|
|
|
|
log_error("Failed to open /sys/power/state: %m");
|
|
|
|
r = -errno;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
-
|
|
|
|
+ }
|
|
|
|
arguments[0] = NULL;
|
|
|
|
arguments[1] = (char*) "pre";
|
|
|
|
arguments[2] = argv[1];
|
2013-04-13 13:09:53 +02:00
|
|
|
@@ -97,11 +112,16 @@ int main(int argc, char *argv[]) {
|
2013-02-20 09:34:16 +01:00
|
|
|
"SLEEP=hybrid-sleep",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
+ if (delegate_to_pmutils) {
|
|
|
|
+ r = -system(pmtools);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
fputs(verb, f);
|
|
|
|
fputc('\n', f);
|
|
|
|
fflush(f);
|
|
|
|
|
|
|
|
r = ferror(f) ? -errno : 0;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (streq(argv[1], "suspend"))
|
|
|
|
log_struct(LOG_INFO,
|
2013-04-13 13:09:53 +02:00
|
|
|
@@ -119,6 +139,7 @@ int main(int argc, char *argv[]) {
|
2013-02-20 09:34:16 +01:00
|
|
|
arguments[1] = (char*) "post";
|
|
|
|
execute_directory(SYSTEM_SLEEP_PATH, NULL, arguments);
|
|
|
|
|
|
|
|
+ if (!delegate_to_pmutils)
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
finish:
|