tag 510676 patch
thanks

On Sun, 2009-01-04 at 11:52:27 +0000, Stephen Gran wrote:
> /etc/default/hdparm isn't read because the init script isn't executed at
> all.  To do that, it would need to be called by one of the power
> management stacks (whichever one that happens to be at the moment).
> 
> Is there an infrastructure guaranteed to be in place for this hook?  I
> know about the /etc/acpid shell script farm, but my understanding is
> that the world is moving to things like pm or probably something else
> altogether at this point.  I'm happy to provide something, if something
> exists to provide.
> 
> Patches, of course, are even better.

I prepared a fix for this some time ago but wanted to test it for a
while and forgot to send it. The attached patch includes two pm-utils
scripts to handle sleep and power events. I've moved the apmd script
to its own directory to avoid confusion (it's in git diff -C form to
reduce size).

thanks,
guillem
diff --git a/debian/20hdparm b/debian/apm/event.d/20hdparm
similarity index 100%
rename from debian/20hdparm
rename to debian/apm/event.d/20hdparm
diff --git a/debian/hdparm.install b/debian/hdparm.install
index f5bc91d..b901b8e 100644
--- a/debian/hdparm.install
+++ b/debian/hdparm.install
@@ -1,4 +1,5 @@
-debian/20hdparm		etc/apm/event.d/
+debian/apm/		etc/
+debian/pm/		etc/
 debian/tmp/sbin/hdparm
 contrib/fix_standby.c   usr/share/doc/hdparm/contrib
 contrib/idectl          usr/share/doc/hdparm/contrib
diff --git a/debian/pm/power.d/20hdparm b/debian/pm/power.d/20hdparm
new file mode 100755
index 0000000..dedd7cc
--- /dev/null
+++ b/debian/pm/power.d/20hdparm
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+. "${PM_FUNCTIONS}"
+
+# The PM_DRIVES setting specifies the drives to be changed.  Set
+# this to an empty string to disable any changes.
+#PM_DRIVES=
+
+# The spindown timeout is set to the value of PM_SPINDOWN when the
+# computer is running on battery power.  When the computer is on AC
+# power, the spindown timeout is disabled.  The number specified here
+# is encoded in a complicated way.  See the man page for hdparm(8) for
+# details.  For small timeouts, numbers between 1 and 240 specify
+# multiples of 5 seconds.  So the default value of 18 means 18*5=90
+# seconds, or 1.5 minutes.
+PM_SPINDOWN=18
+
+HDPARM=/sbin/hdparm
+
+help ()
+{
+    cat <<"EOF"
+---
+$0: Change hard drives power settings
+
+Enable or disable the hard drives spin down setting.
+
+This hook has 2 parameters:
+PM_DRIVES = list of hard drives.
+PM_SPINDOWN = timeout.
+EOF
+}
+
+can_run ()
+{
+  command_exists hdparm || exit $NA
+
+  [ -n "${PM_DRIVES}" ] || exit $NA
+
+  for DRIVE in $PM_DRIVES; do
+    [ -b "${DRIVE}" ] || exit $NA
+  done
+
+  [ "${PM_SPINDOWN}" -gt 0 ] || exit $NA
+}
+
+power_conserve ()
+{
+  can_run
+
+  # Set IDE hard disk spindown time to a short time.
+  for DRIVE in $PM_DRIVES; do
+    printf "Lowering hard drive %s spin down time..." "$DRIVE"
+    "${HDPARM}" -q -S "${PM_SPINDOWN}" "${DRIVE}" && echo Done || \
+      echo Failed.
+  done
+}
+
+power_performance ()
+{
+  can_run
+
+  # Disable IDE hard disk spindown.
+  for DRIVE in $PM_DRIVES; do
+    printf "Disabling hard drive %s spin down time..." "$DRIVE"
+    "${HDPARM}" -q -S 0 "${DRIVE}" && echo Done || \
+      echo Failed.
+  done
+}
+
+case $1 in
+  true)
+    power_performance
+    ;;
+  false)
+    power_conserve
+    ;;
+  help)
+    help
+    ;;
+  *)
+    exit $NA
+    ;;
+esac
diff --git a/debian/pm/sleep.d/20hdparm b/debian/pm/sleep.d/20hdparm
new file mode 100755
index 0000000..3778e91
--- /dev/null
+++ b/debian/pm/sleep.d/20hdparm
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# This script reinitializes the hard disk settings on resume.
+
+case $1 in
+  resume|thaw)
+    /usr/sbin/invoke-rc.d hdparm start >/dev/null
+    ;;
+  suspend|hibernate)
+    # Not needed
+    ;;
+esac
diff --git a/debian/rules b/debian/rules
index f343b88..5076abf 100755
--- a/debian/rules
+++ b/debian/rules
@@ -31,3 +31,5 @@ common-install-prehook-arch::
 	install -d $(CURDIR)/debian/tmp/sbin
 binary-predeb/hdparm::
 	chmod 755 $(CURDIR)/debian/hdparm/etc/apm/event.d/20hdparm
+	chmod 755 $(CURDIR)/debian/hdparm/etc/pm/sleep.d/20hdparm
+	chmod 755 $(CURDIR)/debian/hdparm/etc/pm/power.d/20hdparm

Reply via email to