summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-09-17 19:19:18 -0500
committerVictor Lowther <victor.lowther@gmail.com>2008-09-17 19:19:18 -0500
commit15c62582af5193f10fb7e612c2b1abb8072f793f (patch)
treefeddfe247eb257384f054daee22c6592bf870fb8 /src
parentdd430a021b2d413a1b6ffc8e9fbe104b2f72f35f (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/pm-pmu.c56
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;
}
/*