Package: sleepd
Version: 1.2.16
Severity: wishlist

Several times sleepd has annoyed me by suspending my notebook just as
I started to use it.  The scenario is as follows:

 - plug into AC power
 - spend an hour doing something on the other side of the room
 - come to get the machine, unplug it
 - watch it go into suspension

Of course, I figured out a workaround - to hit any key before
unplugging it.  

However, my mental model for sleepd is "suspend if nothing has
happened for the last N minutes", and it seems that gaining or losing
AC power should count as "something has happened".  Here's a patch for
one possible implementation.

                     - Jim Van Zandt

--- sleepd.c-orig       2005-11-25 20:24:22.000000000 -0500
+++ sleepd.c    2005-11-25 20:24:25.000000000 -0500
@@ -26,6 +26,10 @@
 int max_unused=10 * 60; /* in seconds */
 int check_ac=0;
 int ac_max_unused;
+double fraction=0.5;           /* upon loss of AC power, assume we're
+                                * no further than this fraction
+                                * through the waiting time before
+                                * sleeping */
 char *sleep_command="apm -s";
 int autoprobe=1;
 int daemonize=1;
@@ -125,6 +129,7 @@
        long irq_count[MAX_IRQS]; /* holds previous counters of the irq's */
        int activity, i, sleep_now=0, total_unused=0, do_this_one=0, probed=0;
        int sleep_battery=0;
+       int prev_ac_line_status=0;
        long v;
        time_t nowtime, oldtime=0;
        FILE *f;
@@ -204,10 +209,17 @@
                                        sleep_now = total_unused >= 
ac_max_unused;
                                }
                        }
+                       else if ((ai.ac_line_status == 0) &&
+                                (prev_ac_line_status == 1 )) {
+                               if (total_unused > fraction*max_unused)
+                                       total_unused = fraction*max_unused;
+                       }
                        else if (max_unused > 0) {
                                sleep_now = total_unused >= max_unused;
                        }
 
+                       prev_ac_line_status = ai.ac_line_status;
+
                        if (sleep_now && ! no_sleep && ! 
require_unused_and_battery) {
                                syslog(LOG_NOTICE, "system inactive for %ds; 
forcing sleep", total_unused);
                                if (system(sleep_command) != 0)


-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'oldstable'), (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.14
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to