forked from pool/systemd
fc3ae7490c
- Update to new upstream release 221 OBS-URL: https://build.opensuse.org/request/show/313261 OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd?expand=0&rev=875
98 lines
2.8 KiB
Diff
98 lines
2.8 KiB
Diff
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, 22 insertions(+), 5 deletions(-)
|
|
|
|
Index: systemd-221/src/sleep/sleep.c
|
|
===================================================================
|
|
--- systemd-221.orig/src/sleep/sleep.c
|
|
+++ systemd-221/src/sleep/sleep.c
|
|
@@ -23,6 +23,7 @@
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <getopt.h>
|
|
+#include <stdlib.h>
|
|
|
|
#include "sd-messages.h"
|
|
#include "log.h"
|
|
@@ -34,6 +35,8 @@
|
|
#include "def.h"
|
|
|
|
static char* arg_verb = NULL;
|
|
+static bool delegate_to_pmutils = false;
|
|
+static const char *pmtools;
|
|
|
|
static int write_mode(char **modes) {
|
|
int r = 0;
|
|
@@ -51,10 +54,6 @@ static int write_mode(char **modes) {
|
|
if (r == 0)
|
|
r = k;
|
|
}
|
|
-
|
|
- if (r < 0)
|
|
- log_error_errno(r, "Failed to write mode to /sys/power/disk: %m");
|
|
-
|
|
return r;
|
|
}
|
|
|
|
@@ -95,6 +94,8 @@ static int execute(char **modes, char **
|
|
int r;
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
+ if (!delegate_to_pmutils) {
|
|
+
|
|
/* 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");
|
|
@@ -105,6 +106,7 @@ static int execute(char **modes, char **
|
|
r = write_mode(modes);
|
|
if (r < 0)
|
|
return r;
|
|
+ }
|
|
|
|
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, arguments);
|
|
|
|
@@ -113,8 +115,10 @@ static int execute(char **modes, char **
|
|
LOG_MESSAGE("Suspending system..."),
|
|
"SLEEP=%s", arg_verb,
|
|
NULL);
|
|
-
|
|
+ if (!delegate_to_pmutils)
|
|
r = write_state(&f, states);
|
|
+ else
|
|
+ r = -system(pmtools);
|
|
if (r < 0)
|
|
return r;
|
|
|
|
@@ -154,6 +158,7 @@ static int parse_argv(int argc, char *ar
|
|
};
|
|
|
|
int c;
|
|
+ struct stat buf;
|
|
|
|
assert(argc >= 0);
|
|
assert(argv);
|
|
@@ -191,6 +196,18 @@ static int parse_argv(int argc, char *ar
|
|
return -EINVAL;
|
|
}
|
|
|
|
+ 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 */;
|
|
}
|
|
|