[Pm-utils] [PATCH 1/6] Backend autodetection, take 2 (pm-utils 1.2.1)

Victor Lowther victor.lowther at gmail.com
Wed Sep 17 20:22:35 PDT 2008


This is a rework of the last backend autodetection patch series.

Along with readding s2ram support, I have also made a couple of other changes
to bring pm-utils more in line with the way things are done in the Real World.

Assuming there are no major objections, this patch series will go into 
pm-utils 1.2.1.

Modified pm-pmu to take a --check parameter

This allow us to check and see if suspending via pmu will do The Right
Thing before actually performing a suspend via pmu.
---
 src/pm-pmu.c |   56 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/src/pm-pmu.c b/src/pm-pmu.c
index 475477e..1fa7b38 100644
--- a/src/pm-pmu.c
+++ b/src/pm-pmu.c
@@ -41,12 +41,18 @@ typedef u_int32_t __u32;
 #endif
 
 static int
-pmu_sleep(const int fd)
+pmu_can_sleep(const int fd)
 {
     unsigned long arg = 0;
-
     if (ioctl(fd, PMU_IOC_CAN_SLEEP, &arg) < 0 || arg != 1)
         return 1;
+    return 0;
+}
+    
+static int
+pmu_sleep(const int fd)
+{
+    unsigned long arg = 0;
 
     if (ioctl(fd, PMU_IOC_SLEEP, arg) < 0)
         return 1;
@@ -56,33 +62,43 @@ pmu_sleep(const int fd)
 static inline int
 print_usage(FILE *output, int retval)
 {
-    fprintf(output, "usage: pm-pmu --suspend\n");
+    fprintf(output, "usage: pm-pmu --suspend | --check\n");
     return retval;
 }
 
 int main(int argc, char *argv[])
 {
+    int task=0,fd=0,ret=0;
     if (argc != 2)
         return print_usage(stderr, 1);
-
     if (!strcmp(argv[1], "--help")) {
-        return print_usage(stdout, 0);
-    } else if (access("/dev/pmu", W_OK)) {
-        return 1;
-    } else if (!strcmp(argv[1], "--suspend")) {
-        int fd, ret;
-
-        if ((fd = open("/dev/pmu", O_RDWR)) < 0) {
-            perror("open");
-            return 1;
-        }
-
-        ret = pmu_sleep(fd);
-        close(fd);
-        return ret;
+        task=1;
+    } else if (!strcmp(argv[1],"--check")) {
+        task=2;
+    } else if (!strcmp(argv[1],"--suspend")) {
+        task=3;
     }
-    
-    return print_usage(stderr, 1);
+    switch (task) {
+        case 0: ret = print_usage(stderr, 1); break;
+        case 1: ret = print_usage(stdout, 0); break;
+        case 2: /* this is intentional */
+        case 3:
+            if (access("/dev/pmu", W_OK)) {
+                ret = 1;
+            } else {
+                if ((fd = open("/dev/pmu", O_RDWR)) < 0) {
+                    perror("open");
+                    return 1;
+                }
+            
+                ret = pmu_can_sleep(fd);
+                if (!ret && task == 3) 
+                    ret = pmu_sleep(fd);
+                close(fd);
+            }
+            break;
+    }
+   return ret; 
 }
 
 /*
-- 
1.5.6.5



More information about the Pm-utils mailing list