]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rtcwake: test for available suspend modes
authorLawrence Rust <lawrence@softsystem.co.uk>
Thu, 10 Feb 2011 09:02:20 +0000 (10:02 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 28 Feb 2011 09:21:12 +0000 (10:21 +0100)
Signed-off-by: Lawrence Rust <lawrence@softsystem.co.uk>
sys-utils/rtcwake.c

index da8c085feaec745479a419f869a540a2a835705b..5b54537a32cd5e8a872e4e68746c3459b96a81cb 100644 (file)
@@ -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
                 */