summaryrefslogtreecommitdiffstats
path: root/sys-utils/rtcwake.c
diff options
context:
space:
mode:
authorLawrence Rust2011-02-10 10:02:20 +0100
committerKarel Zak2011-02-28 10:21:12 +0100
commite6d1dc94165943374451f3c7639c0ed0a2c3a6b3 (patch)
tree18f75efa74ff2c801c4de7f4762124ab3527f7de /sys-utils/rtcwake.c
parentdmesg.c: cleanups -- use err(), xalloc() (diff)
downloadkernel-qcow2-util-linux-e6d1dc94165943374451f3c7639c0ed0a2c3a6b3.tar.gz
kernel-qcow2-util-linux-e6d1dc94165943374451f3c7639c0ed0a2c3a6b3.tar.xz
kernel-qcow2-util-linux-e6d1dc94165943374451f3c7639c0ed0a2c3a6b3.zip
rtcwake: test for available suspend modes
Signed-off-by: Lawrence Rust <lawrence@softsystem.co.uk>
Diffstat (limited to 'sys-utils/rtcwake.c')
-rw-r--r--sys-utils/rtcwake.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index da8c085fe..5b54537a3 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -247,6 +247,24 @@ static int setup_alarm(int fd, time_t *wakeup)
return 0;
}
+static int is_suspend_available(const char *suspend)
+{
+ int rc;
+ char buf[32];
+ FILE *f = fopen(SYS_POWER_STATE_PATH, "r");
+
+ if (!f)
+ return -1;
+
+ if (fgets(buf, sizeof buf, f) == NULL)
+ rc = -1;
+ else
+ rc = strstr(buf, suspend) != NULL;
+
+ fclose(f);
+ return rc;
+}
+
static void suspend_system(const char *suspend)
{
FILE *f = fopen(SYS_POWER_STATE_PATH, "w");
@@ -501,6 +519,11 @@ int main(int argc, char **argv)
alarm, sys_time, rtc_time, seconds);
if (strcmp(suspend, "show") && strcmp(suspend, "disable")) {
+ if (strcmp(suspend, "no") && strcmp(suspend, "on") &&
+ strcmp(suspend, "off") && is_suspend_available(suspend) <= 0) {
+ errx(EXIT_FAILURE, _("suspend to \"%s\" unavailable"), suspend);
+ }
+
/* care about alarm setup only if the show|disable
* modes are not set
*/