Hi,

Currently, when you hibernate your thinkpad using the hibernate
button (Fn+F12), /etc/apm/hibernate does not get executed. It is
only when you hibernate using 'ZZZ'.

The diff below makes the hibernate button behave like the suspend
one.

I have chosen 0x000D as the value for APM_USER_HIBERNATE_REQ: is
it right? If it's not please suggest a valid alternative.

Cheers!
David

Index: sys/arch/amd64/include/apmvar.h
===================================================================
RCS file: /cvs/src/sys/arch/amd64/include/apmvar.h,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 apmvar.h
--- sys/arch/amd64/include/apmvar.h     8 Jul 2012 18:02:45 -0000       1.5
+++ sys/arch/amd64/include/apmvar.h     4 Feb 2015 10:35:22 -0000
@@ -172,6 +172,7 @@
 #define                APM_USER_SUSPEND_REQ    0x000A
 #define                APM_SYS_STANDBY_RESUME  0x000B
 #define                APM_CAPABILITY_CHANGE   0x000C  /* apm v1.2 */
+#define                APM_USER_HIBERNATE_REQ  0x000D
 /* 0x000d - 0x00ff     Reserved system events */
 /* 0x0100 - 0x01ff     Reserved device events */
 /* 0x0200 - 0x02ff     OEM-defined APM events */
Index: sys/arch/i386/include/apmvar.h
===================================================================
RCS file: /cvs/src/sys/arch/i386/include/apmvar.h,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 apmvar.h
--- sys/arch/i386/include/apmvar.h      8 Jul 2012 18:02:45 -0000       1.19
+++ sys/arch/i386/include/apmvar.h      4 Feb 2015 10:35:22 -0000
@@ -171,6 +171,7 @@
 #define                APM_USER_SUSPEND_REQ    0x000A
 #define                APM_SYS_STANDBY_RESUME  0x000B
 #define                APM_CAPABILITY_CHANGE   0x000C  /* apm v1.2 */
+#define                APM_USER_HIBERNATE_REQ  0x000D
 /* 0x000d - 0x00ff     Reserved system events */
 /* 0x0100 - 0x01ff     Reserved device events */
 /* 0x0200 - 0x02ff     OEM-defined APM events */
Index: sys/dev/acpi/acpithinkpad.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpithinkpad.c,v
retrieving revision 1.42
diff -u -p -u -p -r1.42 acpithinkpad.c
--- sys/dev/acpi/acpithinkpad.c 13 Dec 2014 05:29:50 -0000      1.42
+++ sys/dev/acpi/acpithinkpad.c 4 Feb 2015 10:35:22 -0000
@@ -347,8 +347,9 @@ thinkpad_hotkey(struct aml_node *node, i
                        break;
                case THINKPAD_BUTTON_HIBERNATE:
 #if defined(HIBERNATE) && !defined(SMALL_KERNEL)
-                       acpi_addtask(sc->sc_acpi, acpi_sleep_task, 
-                           sc->sc_acpi, ACPI_STATE_S4);
+                       if (acpi_record_event(sc->sc_acpi, 
APM_USER_HIBERNATE_REQ))
+                               acpi_addtask(sc->sc_acpi, acpi_sleep_task, 
+                                   sc->sc_acpi, ACPI_STATE_S4);
 #endif
                        handled = 1;
                        break;
Index: usr.sbin/apmd/apmd.c
===================================================================
RCS file: /cvs/src/usr.sbin/apmd/apmd.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 apmd.c
--- usr.sbin/apmd/apmd.c        16 Jan 2015 06:40:15 -0000      1.74
+++ usr.sbin/apmd/apmd.c        4 Feb 2015 10:35:23 -0000
@@ -348,7 +348,7 @@ int
 main(int argc, char *argv[])
 {
        const char *fname = apmdev;
-       int ctl_fd, sock_fd, ch, suspends, standbys, resumes;
+       int ctl_fd, sock_fd, ch, suspends, standbys, hibernates, resumes;
        int statonly = 0;
        int powerstatus = 0, powerbak = 0, powerchange = 0;
        int noacsleep = 0;
@@ -487,7 +487,7 @@ main(int argc, char *argv[])
                        continue;
 
                if (ev->ident == ctl_fd) {
-                       suspends = standbys = resumes = 0;
+                       suspends = standbys = hibernates = resumes = 0;
                        syslog(LOG_DEBUG, "apmevent %04x index %d",
                            (int)APM_EVENT_TYPE(ev->data),
                            (int)APM_EVENT_INDEX(ev->data));
@@ -503,6 +503,9 @@ main(int argc, char *argv[])
                        case APM_STANDBY_REQ:
                                standbys++;
                                break;
+                       case APM_USER_HIBERNATE_REQ:
+                               hibernates++;
+                               break;
 #if 0
                        case APM_CANCEL:
                                suspends = standbys = 0;
@@ -536,6 +539,8 @@ main(int argc, char *argv[])
                                suspend(ctl_fd);
                        else if (standbys)
                                stand_by(ctl_fd);
+                       else if (hibernates)
+                               hibernate(ctl_fd);
                        else if (resumes) {
                                do_etc_file(_PATH_APM_ETC_RESUME);
                                syslog(LOG_NOTICE,

Reply via email to