1 diff -Naur apmd-3.2.2.old/apmd.c apmd-3.2.2.orig/apmd.c
2 --- apmd-3.2.2.old/apmd.c 2006-11-05 01:09:14.000000000 +0200
3 +++ apmd-3.2.2.orig/apmd.c 2006-11-05 01:52:32.000000000 +0200
6 last_marked_time = time(0);
7 last_marked_content = apmi->battery_percentage;
8 - ioctl(apmd_fd, APM_IOC_SUSPEND, NULL);
9 + apm_suspend(apmd_fd);
13 diff -Naur apmd-3.2.2.old/apmlib.c apmd-3.2.2.orig/apmlib.c
14 --- apmd-3.2.2.old/apmlib.c 2006-11-05 01:09:14.000000000 +0200
15 +++ apmd-3.2.2.orig/apmlib.c 2006-11-05 01:50:58.000000000 +0200
18 #define BACKWARD_COMPAT 1
20 +#define SUSPEND_METHOD__NOT_DEFINED -1
21 +#define SUSPEND_METHOD__APM_IOCTL 0
22 +#define SUSPEND_METHOD__ECHO_SYS_POWER_STATE 1
24 +static int suspend_method_to_use = SUSPEND_METHOD__NOT_DEFINED;
27 + * Check from the some of the search strings is available in
28 + * /proc/cpuinfo (harware type for example)
30 + * Return 1 if available, 0 if not found
32 +int is_key_in_proc_cpuinfo(char *devlist[])
35 + char curBuffer[2048];
40 + // let's assume by default that string does not found
42 + /* read to /proc/cpuinfo to buffer */
43 + curFd = fopen("/proc/cpuinfo", "r");
44 + curBCount = fread(curBuffer, 1, sizeof(curBuffer), curFd);
46 + if (curBCount > 0) {
47 + /* make sure text in buffer is terminated */
48 + curBuffer[curBCount] = '\0';
49 + while((*devlist != NULL)) {
50 + curFound = strstr(curBuffer, *devlist);
51 + if (curFound != NULL) {
52 + // matched to one of the search keywords
62 +int check_suspend_method(void)
64 + if (suspend_method_to_use == SUSPEND_METHOD__NOT_DEFINED)
66 + char *curDevArr[] = {"HP iPAQ h6300", 0};
68 + // not checked yet, check now
69 + if (is_key_in_proc_cpuinfo(curDevArr)) {
70 + suspend_method_to_use = SUSPEND_METHOD__ECHO_SYS_POWER_STATE;
71 + printf("Using 'echo mem > sys/power/state' to suspend.\n");
74 + suspend_method_to_use = SUSPEND_METHOD__APM_IOCTL;
75 + printf("Using apm ioctl to suspend\n");
78 + return suspend_method_to_use;
82 * Return a string describing an APM event. From p. 16 of the Intel/Microsoft
84 int apm_suspend(int fd)
87 - return ioctl(fd, APM_IOC_SUSPEND, NULL) < 0 ? -errno : 0;
88 + if (check_suspend_method() == SUSPEND_METHOD__ECHO_SYS_POWER_STATE)
89 + return system("echo mem > /sys/power/state");
91 + return ioctl(fd, APM_IOC_SUSPEND, NULL) < 0 ? -errno : 0;
97 int apm_standby(int fd)
100 - return ioctl(fd, APM_IOC_STANDBY, NULL);
101 + if (check_suspend_method() == SUSPEND_METHOD__ECHO_SYS_POWER_STATE)
102 + return system("echo mem > /sys/power/state");
104 + return ioctl(fd, APM_IOC_STANDBY, NULL);