[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: [PATCH] KLaptop daemon, 2.6.13 kernel change
From: Ivor Hewitt <ivor () ivor ! org>
Date: 2005-09-05 20:58:27
Message-ID: 200509052158.27357.ivor () ivor ! org
[Download RAW message or body]
Hi,
In kernel 2.6.13 the /proc/acpi/sleep interface has been deprecated (it can be
enabled but is disabled and deprecated by default)
The attached patch adds support for the new /sys/power/state interface to the
klaptop-daemon as well. Is it ok to get this into the 3.5 release?
Cheers,
--
Ivor Hewitt.
["klaptop-sys.diff" (text/x-diff)]
Index: acpi_helper.cpp
===================================================================
--- acpi_helper.cpp (revision 454662)
+++ acpi_helper.cpp (working copy)
@@ -78,6 +78,25 @@
exit(0);
}
+/* Write string to new acpi power interface */
+void write_to_power(const char * str)
+{
+ int fd;
+ /* Broken imitation of typing sync <enter> sync <enter>
+ on the command line before shutting down the machine;
+ part of the lore of UNIX machines. */
+ sync();
+ sync();
+ fd = open("/sys/power/state", O_RDWR);
+ if (fd < 0)
+ exit(1);
+
+ write(fd, str, strlen(str));
+ close(fd);
+ setuid(getuid()); // drop all priority asap
+ exit(0);
+}
+
/* Run the program @param path, if it exists and seems safe to do so.
Returns only if the program does not exist; if the program exists
and is unsafe, exit; if the program exists and is safe, run it
@@ -110,17 +129,29 @@
int fd;
int i;
int toshibalcd_val = 0;
+ bool useSysPower=false;
+ fd = open("/sys/power/state", O_RDWR);
+ if (fd >= 0)
+ useSysPower=true;
+ close(fd);
+
::close(0); // we're setuid - this is just in case
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "--suspend") == 0 || strcmp(argv[i], "-suspend") == 0) {
/* Returns only if suspend does not exist. */
run_program("/usr/sbin/suspend");
- write_to_proc_sleep(3);
+ if (useSysPower)
+ write_to_power("mem");
+ else
+ write_to_proc_sleep(3);
exit(0);
} else
if (strcmp(argv[i], "--standby") == 0 || strcmp(argv[i], "-standby") == 0) {
- write_to_proc_sleep(1);
+ if (useSysPower)
+ write_to_power("standby");
+ else
+ write_to_proc_sleep(1);
exit(0);
} else
if (strcmp(argv[i], "--standby2") == 0 || strcmp(argv[i], "-standby2") == 0) {
@@ -129,7 +160,10 @@
} else
if (strcmp(argv[i], "--hibernate") == 0 || strcmp(argv[i], "-hibernate") == 0) {
run_program("/usr/sbin/hibernate");
- write_to_proc_sleep(4);
+ if (useSysPower)
+ write_to_power("disk");
+ else
+ write_to_proc_sleep(4);
exit(0);
} else
if (strcmp(argv[i], "--software-suspend") == 0 || strcmp(argv[i], "-software-suspend") == 0) {
@@ -287,4 +321,6 @@
exit(1);
}
goto usage;
+
}
+
Index: portable.cpp
===================================================================
--- portable.cpp (revision 454662)
+++ portable.cpp (working copy)
@@ -689,8 +689,27 @@
if (known != last_seed) {
known = last_seed;
mask = 0;
+
+ QFile p("/sys/power/state");
QFile f("/proc/acpi/sleep");
- if (f.open(IO_ReadOnly)) {
+
+ if (p.open(IO_ReadOnly)) {
+ QString l;
+ p.readLine(l,500);
+ QStringList ll = QStringList::split(' ',l,false);
+ for (QValueListIterator<QString> i = ll.begin(); i!=ll.end(); i++) {
+ QString s = *i;
+
+ if (s.compare("standby")==0)
+ mask |= (1<<1);
+ else if (s.compare("mem")==0)
+ mask |= (1<<3);
+ else if (s.compare("disk")==0)
+ mask |= (1<<4);
+ }
+ p.close();
+ }
+ else if (f.open(IO_ReadOnly)) {
QString l;
f.readLine(l, 500);
QStringList ll = QStringList::split(' ',l,false);
@@ -1363,7 +1382,9 @@
if (known != last_seed) {
known = last_seed;
known_res = (::access("/proc/acpi/sleep", R_OK|W_OK)==0 && ::acpi_helper_ok(1)) ||
- (::access("/proc/acpi/sleep", R_OK)==0 && ::acpi_helper_ok(0));
+ (::access("/proc/acpi/sleep", R_OK)==0 && ::acpi_helper_ok(0)) ||
+ (::access("/sys/power/state", R_OK|W_OK)==0 && ::acpi_helper_ok(1)) ||
+ (::access("/sys/power/state", R_OK)==0 && ::acpi_helper_ok(0));
}
return(known_res);
}
=
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib=
e <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic