--- acpid-1.0.10.orig/debian/acpid.init
+++ acpid-1.0.10/debian/acpid.init
@@ -0,0 +1,82 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          acpid
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# X-Start-Before:    kdm gdm xdm hal
+# X-Stop-After:      kdm gdm xdm hal
+# Default-Start:     2 3 4 5
+# Default-Stop:      
+# Short-Description: Start the Advanced Configuration and Power Interface daemon
+# Description:       Provide a socket for X11, hald and others to multiplex
+#                    kernel ACPI events.
+### END INIT INFO
+
+set -e
+
+ACPID="/usr/sbin/acpid"
+DEFAULTS="/etc/default/acpid"
+
+# Check for daemon presence
+[ -x "$ACPID" ] || exit 0
+
+OPTIONS=""
+MODULES=""
+# Include acpid defaults if available
+[ -r "$DEFAULTS" ] && . "$DEFAULTS"
+
+# Get lsb functions
+. /lib/lsb/init-functions
+. /etc/default/rcS
+
+# As the name says. If the kernel supports modules, it'll try to load
+# the ones listed in "MODULES".
+load_modules() {
+    [ -f /proc/modules ] || return 0
+    if [ "$MODULES" = "all" ]; then
+        MODULES="$(sed -rn 's#^/lib/modules/[^/]+/kernel/(drivers|ubuntu)/acpi/([^/]+/)*(.*)\.ko:.*#\3#p' "/lib/modules/$(uname -r)/modules.dep")"
+    fi
+
+    if [ -z "$MODULES" ]; then
+        return
+    fi
+
+    log_begin_msg "Loading ACPI kernel modules..."
+    # work around a bug in initramfs which leaks this env var Launchpad #291619
+    # and a bug in modprobe --all --quiet which doesn't load all modules and
+    # exits with non-zero exit status Debian #504088
+    unset MODPROBE_OPTIONS
+    modprobe --all --use-blacklist $MODULES 2>/dev/null
+    log_end_msg $?
+}
+
+case "$1" in
+  start)
+    load_modules || true
+    log_begin_msg "Starting ACPI services..."
+    start-stop-daemon --start --quiet --oknodo --exec "$ACPID" -- $OPTIONS
+    log_end_msg $?
+    ;;
+  stop)
+    log_begin_msg "Stopping ACPI services..."
+    start-stop-daemon --stop --quiet --oknodo --retry 2 --exec "$ACPID"
+    log_end_msg $?
+    ;;
+  restart)
+    $0 stop
+    sleep 1
+    $0 start
+    ;;
+  reload|force-reload) 
+    log_begin_msg "Reloading ACPI services..."
+    start-stop-daemon --stop --signal 1 --exec "$ACPID"
+    log_end_msg $?
+    ;;
+  status)
+    status_of_proc "$ACPID" acpid
+    ;;
+  *)
+    log_success_msg "Usage: /etc/init.d/acpid {start|stop|restart|reload|force-reload|status}"
+    exit 1
+esac
+
--- acpid-1.0.10.orig/debian/rules
+++ acpid-1.0.10/debian/rules
@@ -0,0 +1,48 @@
+#!/usr/bin/make -f
+
+include /usr/share/quilt/quilt.make
+
+build: patch build-stamp
+build-stamp:
+	dh_testdir
+	chmod g-s -R *
+	$(MAKE)
+	$(MAKE) man
+	touch $@
+
+clean: unpatch
+	dh_testdir
+	dh_testroot
+	rm -f build-stamp
+	[ ! -f Makefile ] || $(MAKE) clean
+	dh_clean
+
+install: build
+	dh_testdir
+	dh_testroot
+	dh_clean
+	dh_installdirs
+
+binary: binary-arch binary-indep
+
+binary-indep:
+
+binary-arch: build install
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs -s Changelog
+	dh_installdocs -s
+	dh_installinit -s -- start 12 2 3 4 5 . 
+	dh_install -s
+	dh_installman -s
+	dh_link -s
+	dh_strip -s
+	dh_compress -s
+	dh_fixperms -s
+	dh_installdeb -s
+	dh_shlibdeps -s
+	dh_gencontrol -s
+	dh_md5sums -s
+	dh_builddeb -s
+
+.PHONY: build clean binary-indep binary-arch binary install
--- acpid-1.0.10.orig/debian/copyright
+++ acpid-1.0.10/debian/copyright
@@ -0,0 +1,14 @@
+This is the Debian GNU/Linux prepackaged version of acpid.
+It was packaged by Cajus Pollmeier <cajus@debian.org>
+from sources obtained from http://acpid.sourceforge.net.
+
+Copyright:
+
+Copyright (C) 2000 Andrew Henroid
+
+License:
+
+acpid is distributed under the terms of the GNU General Public License,
+version 2 or later. On Debian GNU/Linux system you can find a copy of this
+license in `/usr/share/common-licenses/GPL'.
+
--- acpid-1.0.10.orig/debian/changelog
+++ acpid-1.0.10/debian/changelog
@@ -0,0 +1,1059 @@
+acpid (1.0.10-5~bpo50+1) lenny-backports; urgency=high
+
+  * Rebuild for lenny-backports.
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 15 Dec 2009 13:19:41 +0100
+
+acpid (1.0.10-5) unstable; urgency=high
+
+  * Correct permissions that were incorrectly set by very old acpid versions.
+    This fixes CVE-2009-4235. (Closes: #560771)
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 15 Dec 2009 13:11:29 +0100
+
+acpid (1.0.10-4~bpo50+1) lenny-backports; urgency=low
+
+  * Rebuild for lenny-backports.
+
+ -- Michael Meskes <meskes@debian.org>  Sat, 28 Nov 2009 20:57:06 +0100
+
+acpid (1.0.10-4) unstable; urgency=low
+
+  * Updated netlink patch to version 6.
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 17 Nov 2009 14:50:01 +0100
+
+acpid (1.0.10-3~bpo50+1) lenny-backports; urgency=low
+
+  * Rebuild for lenny-backports.
+
+ -- Michael Meskes <meskes@debian.org>  Mon, 16 Nov 2009 12:06:06 +0100
+
+acpid (1.0.10-3) unstable; urgency=low
+
+  * Made acpid recommend correct version of acpi-support-base.
+  * Added missing input defines for Thinkpads. (Closes: #521280) -
+    thanks to Harald Braumann <harry@unheit.net>
+  * Fixed package description. (Closes: #549948) - thanks to Justin B
+    Rye <jbr@edlug.org.uk>
+  * Clarify some wording. - thanks to Thiemo Nagel
+    <thiemo.nagel@ph.tum.de>
+  * Bumped Standards-Version to 3.8.3, no changes needed.
+  * Fix some lintian warnings.
+  * Updated list of power managers. (Closes: #547326)
+  * Stopping for single user mode could be done by sendsigs as well.
+  * Updated to netlink patch to version 1.0.10-netlink5. (Closes:
+    #522756)
+
+ -- Michael Meskes <meskes@debian.org>  Mon, 09 Nov 2009 14:46:15 +0100
+
+acpid (1.0.10-2~bpo50+1) lenny-backports; urgency=low
+
+  * Rebuild for lenny-backports.
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 23 Jun 2009 13:54:57 +0200
+
+acpid (1.0.10-2) unstable; urgency=low
+
+  * Updated netlink patch to version 1.0.10-netlink2.
+  * Added patch to make acpid compile with gcc 4.4, closes: #526665
+
+ -- Michael Meskes <meskes@debian.org>  Mon, 04 May 2009 14:41:24 +0200
+
+acpid (1.0.10-1) unstable; urgency=high
+
+  * New upstream version fixing CVE-2009-0798.
+  * Removed fixfd patch which was applied upstream.
+  * Made example powerbtn.sh script work with kde4, closes: #526000
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 28 Apr 2009 09:24:25 +0200
+
+acpid (1.0.8-8) unstable; urgency=low
+
+  * Fixed netlink patch to not expect long option --netlink to carry an
+    argument, closes: #524223
+  * Do not remove /etc/acpi/ config at each upgrade, closes: #524528
+
+ -- Michael Meskes <meskes@debian.org>  Mon, 20 Apr 2009 14:04:32 +0200
+
+acpid (1.0.8-7) unstable; urgency=low
+
+  * Fixed ioctl call to use correct buffer size, closes: #521512
+  * Do not print error message for missing event file unless we are in debug
+    mode, closes: #521666
+  * Bumped Standards-Version to 3.8.1, no changes needed.
+
+ -- Michael Meskes <meskes@debian.org>  Sun, 29 Mar 2009 17:13:02 +0200
+
+acpid (1.0.8-6) unstable; urgency=low
+
+  * Start acpid even if /proc/acpi/event doesn't exist, closes: #516079
+  * Recommend acpi-support-base so a script handling power button pressing is
+    installed.
+  * If the power button script had been changed, not only rename it but also
+    keep a changed events file to not lose functionality, closes: #516083
+
+ -- Michael Meskes <meskes@debian.org>  Thu, 19 Feb 2009 10:03:40 +0100
+
+acpid (1.0.8-5) unstable; urgency=low
+
+  * Reverted redirection patch, it broke debug mode.
+
+ -- Michael Meskes <meskes@debian.org>  Thu, 19 Feb 2009 09:44:59 +0100
+
+acpid (1.0.8-4) unstable; urgency=low
+
+  * Added patch to correctly redirect stdin/stdout/stderr to /dev/null.
+  * Added patch by Ted Felix <ted@tedfelix.com> adding netlink support to
+    acpid, closes: #462467, #515773
+
+ -- Michael Meskes <meskes@debian.org>  Wed, 18 Feb 2009 12:05:51 +0100
+
+acpid (1.0.8-3) unstable; urgency=low
+
+  * Only conditionally restart hal on purge, closes: #515650
+  * Remove the remaining scriptlets in /etc/acpi. All files are still available
+    and installed as examples under /usr/share/doc/acpid/examples but not under
+    /etc/acpi anymore.
+  * Fixed GPL version information in copyright file.
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 17 Feb 2009 11:10:42 +0100
+
+acpid (1.0.8-2) unstable; urgency=low
+
+  [ Loic Minier ]
+  * Add git-buildpackage config debian/gbp.conf.
+
+  [ Michael Meskes ]
+  * Added patch by Harald Braumann <harry@unheit.net> to correctly open
+    /dev/null, closes: #483805
+  * Removed old syslog patch as upstream has the same/similar functionality
+    nowadays, closes: #496574
+  * Made powerbtn.sh script fall back to shutdown if dbus fails, closes: #492756
+  * Restart hal in case of acpid removal, closes: #505663
+
+ -- Michael Meskes <meskes@debian.org>  Wed, 11 Feb 2009 16:53:06 +0100
+
+acpid (1.0.8-1) unstable; urgency=low
+
+  [ Loic Minier ]
+  * Comment out OPTIONS in the acpid defaults file as -c /etc/acpi/events is
+    the default anyway; this paves the way to a future removal of this file.
+  * Test for /proc/acpi/event instead of /proc/acpi in init script;
+    see Debian #440870.
+  * Document rationale for hal restart in postinst.
+
+  [ Michael Meskes ]
+  * New upstream version.
+  * Moved our patches to debian/patches and added support for quilt.
+
+ -- Michael Meskes <meskes@debian.org>  Wed, 12 Nov 2008 14:29:15 +0100
+
+acpid (1.0.6-16) unstable; urgency=low
+
+  [ Loic Minier ]
+  * Reword hints in /etc/default/acpid; suggested by Julien Blache.
+  * Drop bogus space in modules.dep causing modules without dependencies to
+    not be loaded for MODULES="all".
+  * Check for read permissions on the defaults file before attempting to
+    source it.
+  * Don't load any module (MODULES default to empty string) when the default
+    file doesn't exist or doesn't specify MODULES.
+  * Ignore the result of load_modules.
+  * Unset MODPROBE_OPTIONS to work around a bug in initramfs which leaks this
+    env var Launchpad #291619 and a bug in modprobe --all --quiet which
+    doesn't load all modules and exits with non-zero exit status
+    Debian.org #504088; thanks Derrick Karpo and Julien Blache;
+    closes: #502704.
+
+  [ Michael Meskes ]
+  * Make sure there is no link created in runlevel 0 and 6 to stop acpid.
+  * Remove old links in runlevel 0 and 6, closes: #502613.
+  * Comment out MODULES setting in default file, so no module is loaded per
+    default.
+
+ -- Loic Minier <lool@dooz.org>  Sun, 02 Nov 2008 10:28:14 +0100
+
+acpid (1.0.6-15) unstable; urgency=low
+
+  [ Michael Meskes ]
+  * Fixed check for /proc/modules to not throw an error
+    closes: #502881, #502704
+
+  [ Loic Minier ]
+  * Fix above fix.  :-P
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 21 Oct 2008 12:55:00 +0200
+
+acpid (1.0.6-14) unstable; urgency=low
+
+  [ Loic Minier ]
+  * Merge support for the "status" action in the acpid init script from the
+    Ubuntu package; depend on lsb-base >= 3.2-14.
+  * Don't stop acpid in runlevels 0 and 6; from Ubuntu, closes:#495544 
+  * Fix support for Ubuntu kernels, stop guessing distro but always try to use
+    the ubuntu/acpi module dir if present; this allows using Ubuntu kernels on
+    Ubuntu, removes references to Ubuntu from a number of places, and makes
+    the script simpler to maintain and more efficient; also matches the
+    current Ubuntu script.
+  * Cleanup rules; drop DH_VERBOSE.
+  * Wrap build-deps and deps in control to get cleaner diffs.
+  * Add myself to uploaders.
+  * Drop obsolete information from README.Debian.
+  * Cleanup the awful init script.
+    - Drop support for *.o kernel module files; .ko is used since 2.5 kernels.
+    - Greatly simplify computing the list of available acpi modules by parsing
+      modules.dep(5) instead of running find and sh multiple times.
+    - Rename debian/acpid.init.d to debian/acpid.init to match debhelper's
+      documented name (debhelper does pick up .init.d as well, but this is
+      undocumented); this also avoid confusing vim which believe it's a D
+      file.
+    - Don't disable printk when loading ACPI modules; this is not only
+      fragile, broken, and intrusive, it's also out of the realm of acpid to
+      do.  This snippet:
+          [ "$VERBOSE" = "no" ] && echo "0 0 0 0" > /proc/sys/kernel/printk
+      can be moved to a more sensible place if it makes sense during boot, but
+      I doubt anybody wants that.
+    - Fix support for kernels without dynamic module loading; closes: #500659.
+  * Use Vcs-* instead of XS-Vcs-* and fix URLs to point at the new git repos;
+    closes: #501305.
+  * Remove obsolete conffile /etc/logrotate.d/acpid in preinst; thanks to
+    James Westby and Ubuntu; LP: #263888. It's interesting to note that this
+    caused the new acpid to die once per week when logrotation kicked in.
+    Closes: #487815, #491058, #495686
+  * Pass -s to dh_* commands in binary-arch.
+  * Resume shipping /etc/acpi/powerbtn.sh and /etc/acpi/events/powerbtn in
+    acpid.  They are also installed in the examples for people who symlink to
+    the examples.  Please note that powerbtn.sh disables itself when it
+    detects a running power management daemon such as gnome-power-manager or
+    kpowersave.
+  * Add -D_GNU_SOURCE in Makefile's CFLAGS to fix build with newer libc6 (such
+    as 2.8+20080809-1 in experimental or 2.8~20080505-0ubuntu7in Ubuntu
+    intrepid) in making "struct ucred" available; see
+    http://sourceware.org/bugzilla/show_bug.cgi?id=6545.
+
+  [ Michael Meskes ]
+  * Fixed path to hal pidfile, closes: #440870
+
+ -- Loic Minier <lool@dooz.org>  Mon, 13 Oct 2008 19:12:28 +0200
+
+acpid (1.0.6-13) unstable; urgency=low
+
+  * Check for distribution during build time, closes: #499825, #500003
+
+ -- Michael Meskes <meskes@debian.org>  Wed, 24 Sep 2008 12:26:45 +0200
+
+acpid (1.0.6-12) unstable; urgency=low
+
+  * Check for Ubuntu/Debian in apt sources list instead of /etc/issue,
+    closes: #499825, #499854
+
+ -- Michael Meskes <meskes@debian.org>  Tue, 23 Sep 2008 10:38:38 +0200
+
+acpid (1.0.6-11) unstable; urgency=low
+
+  * Changed maintainer to Debian Acpi Team.
+  * Do not call lsb-release on startup, closes: #491388
+
+ -- Michael Meskes <meskes@debian.org>  Wed, 27 Aug 2008 13:49:56 +0200
+
+acpid (1.0.6-10) unstable; urgency=low
+
+  * Removed Ubuntu version information.
+  * Back to only including some modules on default. Using all modules creates
+    strange error messages and even backtraces on some machines. ALL option
+    remains listed but commented out, closes: #484354
+  * Add video to list of modules, closes: #459237
+  * Made package lintian clean.
+  * In Debian do not load Ubuntu modules from Ubuntu directory. I do not see
+    any package providing this directory.
+  * Do only install powerbutton scripts as example,
+    closes: #481903, #484306, #253423
+  * Fixed watch file. 
+  * Clarified specification of acpid options, closes: #486788
+  * Bumped Standards-Version to 3.8.0
+
+ -- Michael Meskes <meskes@debian.org>  Fri, 20 Jun 2008 14:21:14 +0200
+
+acpid (1.0.6-9) unstable; urgency=low
+
+  * Don't depend on sysv-rc; closes: #481912
+
+ -- Anibal Monsalve Salazar <anibal@debian.org>  Fri, 23 May 2008 13:50:49 +1000
+
+acpid (1.0.6-8) unstable; urgency=low
+
+  * Update watch file 
+
+ -- Anibal Monsalve Salazar <anibal@debian.org>  Mon, 19 May 2008 19:31:31 +1000
+
+acpid (1.0.6-7) unstable; urgency=low
+
+  * Fix dash syntax error in acpid.init.d; closes: #481824
+
+ -- Anibal Monsalve Salazar <anibal@debian.org>  Mon, 19 May 2008 11:54:32 +1000
+
+acpid (1.0.6-6) unstable; urgency=low
+
+  * New maintainer; closes: #481580
+  * Merge Ubuntu changes
+    - Use MODULES="all"; closes: #449076
+    - Disable printk; closes: #449078
+    - Loading modules from the ubuntu directory; closes: #449080
+  * Limit syslog messages to >= NOTICE to avoid spamming unless in debug mode;
+    patch by Loic Minier; closes: #447200
+  * Include "--oknodo" in init script start action;
+    patch by Daniel Hahler; closes: #475785
+  * Don't fail during installation; closes: #447339
+  * Don't delete conffiles in /etc; closes: #444666
+  * Provide power button support; closes: #444676
+  * Fix typo in acpid.8; closes: #444065
+  * Fix "restart/start fails"; closes: #481327, #479517
+  * Fix "tar error messages on upgrade"; closes: #447099, #451220
+  * Fix "init script start/stop priorities not updated on upgrades";
+    closes: #462185
+  * Fix the following lintian issues:
+    W: acpid source: debian-rules-ignores-make-clean-error line 18
+
+ -- Anibal Monsalve Salazar <anibal@debian.org>  Sat, 17 May 2008 09:54:17 +1000
+
+acpid (1.0.6-5.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Correct dependency information provided in init.d script (Closes: #459493).
+
+ -- Petter Reinholdtsen <pere@debian.org>  Tue,  4 Mar 2008 13:53:46 +0100
+
+acpid (1.0.6-5) unstable; urgency=low
+
+  * New mantainer. (Closes: #455197)
+  * debian/control:
+    - Bump Standards-Version: 3.7.3.
+    - Build-depends debhelper >=5.
+    - Added Homepage header.
+  * debian/watch, added.
+
+ -- Jose Carlos Medeiros <debian@psabs.com.br>  Tue, 15 Jan 2008 18:02:33 -0200
+
+acpid (1.0.6-4) unstable; urgency=medium
+
+  * Add lost directory /etc/acpi/events to package again. (Closes: #444667)
+  * Improve the last NEWS.Debian entry to be more explicit.
+
+ -- Torsten Werner <twerner@debian.org>  Tue, 09 Oct 2007 07:44:46 +0200
+
+acpid (1.0.6-3) unstable; urgency=low
+
+  * Stop and start hal in postinst. (Closes: #352512, #380520, #440870)
+  * Start acpid earlier when booting. (Closes: #320094)
+  * Fix call to 'dpkg --compare-versions' in postinst.
+
+ -- Torsten Werner <twerner@debian.org>  Mon, 24 Sep 2007 07:41:16 +0200
+
+acpid (1.0.6-2) unstable; urgency=low
+
+  * Remove old logs and logrotate conffile.
+    (Closes: #178894, #360170, #443385)
+  * Add debian/NEWS with an explanation of the change.
+  * Revert any changes to acpid.c corresponding to the old log mechanism.
+    (Closes: #388048)
+  * Remove the old powerbtn scripts and provide them as examples.
+    (Closes: #285779, #354445, #386026, #400409, #401414, #417306, #422463, #425291, #427938)
+  * Add option -P to shutdown in powerbtn.sh. (Closes: #365972)
+
+ -- Torsten Werner <twerner@debian.org>  Sun, 23 Sep 2007 16:15:42 +0200
+
+acpid (1.0.6-1) unstable; urgency=low
+
+  * New upstream release (Closes: #442383)
+  * Change Maintainer field to myself as requested by the former maintainer.
+  * Add XS-Vcs-* headers.
+  * Install upstream's Changelog file.
+
+ -- Torsten Werner <twerner@debian.org>  Tue, 18 Sep 2007 16:48:54 +0200
+
+acpid (1.0.4-7.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Fixed typo in init script (Closes: #413729).
+
+ -- Nico Golde <nion@debian.org>  Thu, 29 Mar 2007 23:22:37 +0200
+
+acpid (1.0.4-7) unstable; urgency=low
+
+  * Fixed typo in manual page (Closes: #404680)
+  * Updated README (Closes: #360167)
+  * Include lsb compliant logging (Closes: #384687)
+  * Fixed logrotate/cron error if acpid is not running (Closes: #388038)
+  * Removed powerbutton scripts - these are contained in other packages
+    (Closes: #354445, #285779)
+  * Added lsb compliant init script styles (Closes: #383591)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon,  5 Mar 2007 09:33:07 +0100
+
+acpid (1.0.4-6) unstable; urgency=low
+
+  * Fixed powerptn.sh to respect shutdown changes (Closes: #365972)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu,  4 May 2006 08:47:06 +0200
+
+acpid (1.0.4-5ubuntu9) hardy; urgency=low
+
+  [ Daniel Hahler ]
+  * debian/acpid.postinst: Stop and start hal, if present.
+    This allows acpid to take /proc/acpi/event and hal will ignore this kernel
+    interface, when acpid is installed. (LP: #63450)
+  * debian/acpid.init.d: Add "--oknodo" to the start-stop-daemon call in
+    "start". The action must not fail, if acpid is already running.
+  
+  [ Michael Vogt ]
+  * debian/acpid.postinst: do not restart hal on dapper upgrades
+    (hal may hang forever because of a incompatible dbus)
+  * only restart if hal is actually running
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Wed, 16 Apr 2008 16:12:12 +0200
+
+acpid (1.0.4-5ubuntu8) gutsy; urgency=low
+
+  * Fix the broken Maintainer lines in debian/control.
+
+ -- Adam Conrad <adconrad@ubuntu.com>  Wed, 15 Aug 2007 23:47:42 +1000
+
+acpid (1.0.4-5ubuntu7) gutsy; urgency=low
+
+  * Build package for lpia.
+  * Set Ubuntu maintainer address.
+
+ -- Matthias Klose <doko@ubuntu.com>  Fri, 10 Aug 2007 21:43:04 +0000
+
+acpid (1.0.4-5ubuntu6) feisty; urgency=low
+
+  * Load drivers from ubuntu directory as well as kernel acpi directory
+
+ -- Matthew Garrett <mjg59@srcf.ucam.org>  Sat, 10 Mar 2007 15:04:34 +0000
+
+acpid (1.0.4-5ubuntu5) feisty; urgency=low
+
+  * KubuntuFeistyLaptop spec: change debian/powerbtn.sh for KDE sessions:
+    * single KDE session: issue KDE logout dialog for user to decide
+    * multiple KDE sessions: send shutdown request to all KDE sessions
+      (this is the same behaviour as before)
+
+ -- Luka Renko <lure@ubuntu.com>  Thu,  8 Feb 2007 10:28:09 +0100
+
+acpid (1.0.4-5ubuntu4) edgy; urgency=low
+
+  * Call modprobe with -b to allow user blacklisting.  Ubuntu: #49017
+
+ -- Scott James Remnant <scott@ubuntu.com>  Thu, 14 Sep 2006 15:13:52 +0100
+
+acpid (1.0.4-5ubuntu3) edgy; urgency=low
+
+  * Add forgotten versioned-dependency on sysv-rc to get new update-rc.d
+    behaviour.  Go me.
+
+ -- Scott James Remnant <scott@ubuntu.com>  Fri, 21 Jul 2006 01:22:57 +0100
+
+acpid (1.0.4-5ubuntu2) edgy; urgency=low
+
+  * Remove stop links from rc0 and rc6
+
+ -- Scott James Remnant <scott@ubuntu.com>  Thu, 20 Jul 2006 23:14:18 +0100
+
+acpid (1.0.4-5ubuntu1) edgy; urgency=low
+
+  * Merge from debian unstable, remaining changes:
+    - Lock file and groups,
+    - LSB init script,
+    - init script level change,
+    - load all modules by default,
+    - Power button handling changes.
+
+ -- Scott James Remnant <scott@ubuntu.com>  Tue, 11 Jul 2006 17:50:13 +0100
+
+acpid (1.0.4-5) unstable; urgency=low
+
+  * Fixed problem with logrotate and Xorg where the /proc/acpi/events gets
+    locked by Xorg.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 15 Jan 2006 22:23:05 +0100
+
+acpid (1.0.4-4) unstable; urgency=low
+
+  Changes by Michael Biebl:
+  * Adapted scripts in /etc/acpi/ to let powersaved process the acpi event if
+    it is running.
+  * Updated standards version to 3.6.2. 
+  * Cleaned up debian/rules, make use of dh_* tools. Created the necessary
+    acpid.* files.
+  * Cleaned up debian/*, removed unused and unnecessary files.
+  * Fixed package to make lintian/linda happy.
+
+  Changes by Cajus Pollmeier:
+  * Removed debconf integration (Closes: #336725, #336726, #333759, #331512)
+  * Fixed typo in acpi_listen manpage (Closes: #342743)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sat, 14 Jan 2006 11:52:33 +0100
+
+acpid (1.0.4-3) unstable; urgency=low
+
+  * Added russian debconf translations (Closes: #324084)
+  * Added portuguese debconf translations (Closes: #329872)
+  * Included alternative dependency to debconf-2.0
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu, 29 Sep 2005 11:08:25 +0200
+
+acpid (1.0.4-2) unstable; urgency=low
+
+  * Added logrotate control file (Closes: #306235)
+  * Added vietnamese debconf translations (Closes: #307598)
+  * Added basque debconf translations (Closes: #296865)
+  * Added italian debconf translations (Closes: #288224)
+  * Fixed amd64 specific type problem (Closes: #315070)
+  * Re-fixed amd64 specific type problem (Closes: #285063)
+  * Fixed copyright file by adding one missing original
+    author (Closes: #290053)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sat,  9 Jul 2005 12:39:49 +0200
+
+acpid (1.0.4-1ubuntu11) dapper; urgency=low
+
+  * Fix /etc/acpi/powerbtn.sh so that it doesn't bork if 'pidof' returns
+    multiple results.  This stops the machine displaying the logout
+    dialogue and then immediately shutting down anyway. 
+    (Closes: Ubuntu #46319)
+
+ -- Paul Sladen <ubuntu@paul.sladen.org>  Sat, 27 May 2006 15:54:53 +0100
+
+acpid (1.0.4-1ubuntu10) dapper; urgency=low
+
+  * Add support to set the group of the log file when acpid starts.
+    By default this will set it to the adm group.
+
+ -- Daniel Silverstone <daniel.silverstone@ubuntu.com>  Wed, 15 Feb 2006 14:04:49 +0000
+
+acpid (1.0.4-1ubuntu9) dapper; urgency=low
+
+  * Check for gnome-power-manager rather than PowerManager. The name changed
+    between dapper and breezy and without this, we would unconditionally shut
+    the system down on a powerbutton event.
+  * Also check for kded/klaptopdaemon and kpowersave for KDE options on the
+    same policy management.
+  * Closes: malone #31407
+
+ -- Daniel Silverstone <daniel.silverstone@ubuntu.com>  Wed, 15 Feb 2006 11:41:20 +0000
+
+acpid (1.0.4-1ubuntu8) breezy; urgency=low
+
+  * Shorten and simplify init script messages
+
+ -- Matt Zimmerman <mdz@ubuntu.com>  Thu, 15 Sep 2005 11:30:54 -0700
+
+acpid (1.0.4-1ubuntu7) breezy; urgency=low
+
+  * If power-manager is running, don't trigger the power button event
+    ourselves
+
+ -- Matthew Garrett <mjg59@srcf.ucam.org>  Tue, 30 Aug 2005 18:33:22 +0100
+
+acpid (1.0.4-1ubuntu6) breezy; urgency=low
+
+  * Start acpid before dbus is started - hal needs acpid to be running
+    already
+
+ -- Matthew Garrett <mjg59@srcf.ucam.org>  Tue, 30 Aug 2005 17:10:48 +0100
+
+acpid (1.0.4-1ubuntu5) breezy; urgency=low
+
+  * Interact with the new locking model in acpi-support
+  * Fix gcc-4.0 compile error
+
+ -- Matthew Garrett <mjg59@srcf.ucam.org>  Mon, 22 Aug 2005 22:12:52 +0100
+
+acpid (1.0.4-1ubuntu4) hoary; urgency=low
+
+  * Turn off kernel printks if we're not verbose during module loading 
+
+ -- Thom May <thom@ubuntu.com>  Wed,  2 Mar 2005 17:45:36 +0000
+
+acpid (1.0.4-1ubuntu3) hoary; urgency=low
+
+  * Check for the presence of a lockfile, and don't process events if it's
+    there (Ubuntu: #6026)
+
+ -- Thom May <thom@ubuntu.com>  Tue,  1 Feb 2005 12:27:44 +0000
+
+acpid (1.0.4-1ubuntu2) hoary; urgency=low
+
+  * Use the new -Q argument to modprobe, add depend on the correct
+    module-init-tools
+  * Default back to trying to autoload everything (Ubuntu #4077)
+
+ -- Thom May <thom@planetarytramp.net>  Fri, 14 Jan 2005 13:48:24 +0000
+
+acpid (1.0.4-1ubuntu1) hoary; urgency=low
+
+  * Resynchronise with Debian, resolved minor merging conflict.
+
+ -- Martin Pitt <martin.pitt@canonical.com>  Thu, 11 Nov 2004 10:38:26 +0100
+
+acpid (1.0.4-1) unstable; urgency=low
+
+  * New upstream release
+  * I'm dropping support for older, acpi broken kernels now. Time to
+    clean up.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon,  1 Nov 2004 11:49:33 +0100
+
+acpid (1.0.3-21ubuntu1) hoary; urgency=low
+
+  * Resynchronise with Debian.
+
+ -- Scott James Remnant <scott@canonical.com>  Wed, 27 Oct 2004 12:05:00 +0100
+
+acpid (1.0.3-21) unstable; urgency=low
+
+  *  Fixed dcop problem for shutdown (Closes:#274339)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri,  1 Oct 2004 11:10:24 +0200
+
+acpid (1.0.3-20) unstable; urgency=high
+
+  * Added detection for non files in run-parts code (Closes:#268203)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon, 30 Aug 2004 19:51:41 +0200
+
+acpid (1.0.3-19ubuntu12) warty; urgency=low
+
+  * Disable loading the platform specific acpi modules. (Warty #1451)
+
+ -- Thom May <thom@canonical.com>  Wed,  6 Oct 2004 14:18:58 +0100
+
+acpid (1.0.3-19ubuntu11) warty; urgency=low
+
+  * use xargs -r so we don't fail in the case of no acpi modules (Warty #1466)
+
+ -- Thom May <thom@planetarytramp.net>  Mon, 20 Sep 2004 12:36:52 +0100
+
+acpid (1.0.3-19ubuntu10) warty; urgency=low
+
+  * Added versioned depend on lsb-base
+
+ -- Nathaniel McCallum <npmccallum@canonical.com>  Fri,  3 Sep 2004 14:45:49 -0400
+
+acpid (1.0.3-19ubuntu9) warty; urgency=low
+
+  * log_warning_msg for failed modules, don't bomb out tho. (Warty 983, 991)
+
+ -- Thom May <thom@planetarytramp.net>  Fri,  3 Sep 2004 17:08:34 +0100
+
+acpid (1.0.3-19ubuntu8) warty; urgency=low
+
+  * If a module is already loaded, log_success_msg rather than log_warning_msg
+
+ -- Matt Zimmerman <mdz@alcor.net>  Thu,  2 Sep 2004 16:06:16 -0700
+
+acpid (1.0.3-19ubuntu7) warty; urgency=low
+
+  * debian/init: pretty initscript
+
+ -- Nathaniel McCallum <npmccallum@canonical.com>  Thu,  2 Sep 2004 15:06:13 -0400
+
+acpid (1.0.3-19ubuntu6) warty; urgency=low
+
+  * install initrd script 
+
+ -- Thom May <thom@planetarytramp.net>  Fri, 27 Aug 2004 17:14:00 +0100
+
+acpid (1.0.3-19ubuntu5) warty; urgency=low
+
+  * Revert -4, since that causes the acpid socket to be reaped
+
+ -- Thom May <thom@planetarytramp.net>  Tue, 24 Aug 2004 10:34:05 +0100
+
+acpid (1.0.3-19ubuntu4) warty; urgency=low
+
+  * Ensure acpid starts as early as possible, so we don't melt Scott's laptop
+
+ -- Thom May <thom@planetarytramp.net>  Thu, 19 Aug 2004 14:04:55 +0100
+
+acpid (1.0.3-19ubuntu3) warty; urgency=low
+
+  * Load all modules
+
+ -- Thom May <thom@planetarytramp.net>  Wed, 18 Aug 2004 14:11:45 +0100
+
+acpid (1.0.3-19ubuntu2) warty; urgency=low
+
+  * Get rid of FTBFS errors.
+
+ -- LaMont Jones <lamont@mmjgroup.com>  Sat, 31 Jul 2004 04:49:10 +0000
+
+acpid (1.0.3-19ubuntu1) warty; urgency=low
+
+  * Disable superfluous debconf note when acpi support is not present
+    (Warty Bug#289)
+
+ -- Matt Zimmerman <mdz@alcor.net>  Tue, 27 Jul 2004 13:26:05 -0700
+
+acpid (1.0.3-19) unstable; urgency=low
+
+  * Update dutch translations (Closes:#250719) 
+  * Added turkish translations (Closes:#252933) 
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri, 28 May 2004 19:41:16 +0200
+
+acpid (1.0.3-18) unstable; urgency=low
+
+  * Fixed manpage to contain hint to runparts stylish naming convention
+    in /etc/acpid/events (Closes:#250066)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sat, 22 May 2004 10:33:13 +0200
+
+acpid (1.0.3-17) unstable; urgency=low
+
+  * Added amd64 to list of supported architectures (Closes:#249055) 
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri, 14 May 2004 21:22:53 +0200
+
+acpid (1.0.3-16) unstable; urgency=low
+
+  * Added czech po-debconf translation (Closes:#247377)
+  * Modified init scripts start-stop daemon call to retry stopping
+    acpid after two seconds (Closes:#247130)
+  * Modified init script to check for ACPI presence in kernel
+    _before_ doing any actions (Closes:#247490)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri,  7 May 2004 22:27:40 +0200
+
+acpid (1.0.3-15) unstable; urgency=low
+
+  * Fixed powerbutton script which did a shutdown when a
+    KDE user was logged in. Now it skips the shutdown,
+    because kdm will do it for us.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri, 23 Apr 2004 18:06:16 +0200
+
+acpid (1.0.3-14) unstable; urgency=low
+
+  * Fixed postrm script to clean some lost config files. (Closes: #242273)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu,  8 Apr 2004 11:04:05 +0200
+
+acpid (1.0.3-13) unstable; urgency=low
+
+  * Removed support for configuring list of modules with debconf. I can't
+    spend hours in fullfilling all wishes currently. Don't think anyone really
+    needs this feature - and if: This is more an issue for a tool that detects
+    hardware than one for the daemon itself. Implicitly closes: #241367.
+  * Updated init script to skip loading of modules that are not present in
+    system, but are configured in defaults file.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu,  1 Apr 2004 06:56:27 +0200
+
+acpid (1.0.3-12) unstable; urgency=low
+
+  * Fixed possible problem in config script when installing for the
+    first time (Closes:#241012)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Tue, 30 Mar 2004 13:06:01 +0200
+
+acpid (1.0.3-11) unstable; urgency=low
+
+  * Included danish translations (Closes:#240044)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu, 25 Mar 2004 19:52:46 +0100
+
+acpid (1.0.3-10) unstable; urgency=low
+
+  * Avoided overwriting of manual changes in defaults file (Closes:#239635)
+  * Replaced init call by normal shutdown with more informative
+    message (Closes:#239583)
+  * Included upstream changelog (Closes:#235530)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Tue, 23 Mar 2004 21:33:31 +0100
+
+acpid (1.0.3-9) unstable; urgency=low
+
+  * Made acpid close all used filehandles (Closes:#239350)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon, 22 Mar 2004 14:56:57 +0100
+
+acpid (1.0.3-8) unstable; urgency=low
+
+  * Fixed clean target of debian/rules to call dh_clean (Closes:#239239)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon, 22 Mar 2004 11:14:36 +0100
+
+acpid (1.0.3-7) unstable; urgency=low
+
+  * Added dutch po-debconf translation (Closes:#237816)
+  * Added greek po-debconf translation (Closes:#237847)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 21 Mar 2004 11:40:48 +0100
+
+acpid (1.0.3-6) unstable; urgency=low
+
+  * Modified start script to have the 2.6 module loading
+    style (Closes:#236703)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri, 12 Mar 2004 16:34:42 +0100
+
+acpid (1.0.3-5) unstable; urgency=low
+
+  * Changed description to a coffee cooking variant (Closes:#237199)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Wed, 10 Mar 2004 20:51:52 +0100
+
+acpid (1.0.3-4) unstable; urgency=low
+
+  * Fixed typo in template, that made it in again. (Closes:#236005)
+  * Included French translations, thanks to Clement Stenac. (Closes:#236375)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu,  4 Mar 2004 07:55:24 +0100
+
+acpid (1.0.3-3) unstable; urgency=low
+
+  * Included Japanese translations, thanks to Hideki Yamane. (Closes:#235320)
+  * Included Brazilian Portuguese translations, thanks to
+    Andre Luis Lopes (Closes:#235462)
+  * Workaround for non working postinst configure installed. (Closes:#234270)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 29 Feb 2004 11:26:06 +0100
+
+acpid (1.0.3-2) unstable; urgency=low
+
+  * Added a sleep between stop and start in the init-scripts restart
+    condition. This should fix the logrotate problem. (Closes:#234283)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Wed, 25 Feb 2004 13:15:53 +0100
+
+acpid (1.0.3-1) unstable; urgency=high
+
+  * New upstream release 
+
+ -- Cajus Pollmeier <cajus@debian.org>  Wed, 25 Feb 2004 10:08:34 +0100
+
+acpid (1.0.2-12) unstable; urgency=low
+
+  * Added missing true condition in postinstall script (Closes: #234274)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon, 23 Feb 2004 10:08:19 +0100
+
+acpid (1.0.2-11) unstable; urgency=high
+
+  * Switched to invoke-rc.d in prerm script. (Closes: #234161)
+  * Removed a - for some users - confusing message from debconf
+    templates. (Closes: #234179)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 22 Feb 2004 10:29:11 +0100
+
+acpid (1.0.2-10) unstable; urgency=low
+
+  * Fix typo in events file - powerbtn/powerbtn.sh (Closes:#233248)
+  * Doing workaround in rules to remove setgid bits. Can't upload new
+    orig.tar.gz. (Closes: #233628)
+  * Changed the standard 'all' into a list of most common modules
+
+ -- Cajus Pollmeier <cajus@debian.org>  Tue, 17 Feb 2004 20:28:42 +0100
+
+acpid (1.0.2-9) unstable; urgency=high
+
+  * Yes, yes. I commented out this line, because I've acpi in
+    built into my kernel. Enabled it again. (Closes: #232400)
+  * Fixed some lintian related issues.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 15 Feb 2004 09:23:31 +0100
+
+acpid (1.0.2-8) unstable; urgency=low
+
+  * Finetuning in init script for automatic module loading (Closes: #232400)
+  * Added debconf script to help user, made 'load all modules' the
+    default.
+  * Unmasked signals so that processes started from acpid can receive
+    TERM signals. (Closes: #206525)
+  * Added changes from CVS. New upstream release is comming soon.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu, 12 Feb 2004 18:58:29 +0100
+
+acpid (1.0.2-7) unstable; urgency=low
+
+  * Renamed acpid socket. gnome-applet seems to have a compiled
+    in default for /var/run/acpid.socket. (Closes: #217932)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri, 31 Oct 2003 21:15:17 +0100
+
+acpid (1.0.2-6) unstable; urgency=low
+
+  * Fixed module loader in init script. Credits go to Tim Wright.
+
+ -- Cajus Pollmeier <cajus@debian.org>  Wed, 22 Oct 2003 20:48:17 +0200
+
+acpid (1.0.2-5) unstable; urgency=low
+
+  * Ok. Removing socket support was no good idea. Obviously there
+    are some programms that depend on it. Notice, that the socket
+    is on a non standard location currently. (Closes: #207926)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu,  9 Oct 2003 07:10:51 +0200
+
+acpid (1.0.2-4) unstable; urgency=low
+
+  * Removed socket support for Debian. I currently don't see any use
+    in it.
+  * Changed postrm to clean only config files (Closes: #202858)
+  * Added acpid to logrotate.d (Closes: #200705)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri,  5 Sep 2003 16:51:43 +0200
+
+acpid (1.0.2-3) unstable; urgency=low
+
+  * Make --purge remove /etc/acpi directory (Closes: #197981)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Thu, 19 Jun 2003 08:43:48 +0200
+
+acpid (1.0.2-2) unstable; urgency=low
+
+  * Fixed module loading for kernel 2.5. Modules now have .ko as extension
+    so that the former .o method wouldn't work (Closes: #193709)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 18 May 2003 12:06:04 +0200
+
+acpid (1.0.2-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Cajus Pollmeier <cajus@debian.org>  Wed, 14 May 2003 07:39:25 +0200
+
+acpid (1.0.1-8) unstable; urgency=low
+
+  * Fixed automatic module loading script regex (Closes: #192711)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sat, 10 May 2003 10:27:14 +0200
+
+acpid (1.0.1-7) unstable; urgency=low
+
+  * Changed poweroff script to be dcop aware (Closes: #187493)
+  * Made title line in control file to make it more meaningly (Closes: #181774)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Fri,  4 Apr 2003 19:56:34 +0200
+
+acpid (1.0.1-6) unstable; urgency=low
+
+  * load modules even when acpi.o is not compiled in kernel (Closes: #173173)
+  * updated standards-version
+
+ -- Cajus Pollmeier <cajus@debian.org>  Mon, 30 Dec 2002 13:58:26 +0100
+
+acpid (1.0.1-5) unstable; urgency=low
+
+  * added modules autoloading in startup script, see /etc/default/acpid (Closes: #173173)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Sun, 29 Dec 2002 19:51:32 +0100
+
+acpid (1.0.1-4) unstable; urgency=high
+
+  * removed double freed pointer in event.c (Closes: #153288)
+
+ -- Cajus Pollmeier <cajus@debian.org>  Tue, 20 Aug 2002 08:05:31 +0100
+
+acpid (1.0.1-3) unstable; urgency=high
+
+  * forgot do close ia64 bug (Closes: #141101)
+  * made run-parts stylish /etc/acpi/events (Closes: #141350)
+  * renamed samples to examples and added joeys examples (Closes: #141351)
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Sat,  6 Apr 2002 10:21:15 +0100
+
+acpid (1.0.1-2) unstable; urgency=high
+
+  * Added ia64 for build
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Fri,  5 Apr 2002 08:34:01 +0100
+
+acpid (1.0.1-1) unstable; urgency=high
+
+  * new upstream release
+  * Fixed event handling to fit the new specs - again
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Sat,  9 Mar 2002 12:10:51 +0100
+
+acpid (1.0.0-4) unstable; urgency=high
+
+  * Changed priority to optional (Closes: #135578)
+  * Fixed event handling to fit the new specs
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Sat,  9 Mar 2002 12:10:51 +0100
+
+acpid (1.0.0-3) unstable; urgency=high
+
+  * Removed incompatibility message
+  * Closed bugs that should have been fixed with 1.0.0-2 (Closes: #130934, #127451)
+  * Fixed event handling with kernels patched with acpi-devel code
+  * Added reload option to the initscript (Closes: #129425)
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Fri,  1 Mar 2002 15:13:06 +0100
+
+acpid (1.0.0-2) unstable; urgency=low
+
+  * Fixed logfile not beeing truncated
+  * Changed line width of short description to less than 60 characters
+  * Close bugs not related to this upstream release (Closes: #67465, #108796, #63956, #109559, #110698, #107047)
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Thu,  1 Nov 2001 13:30:16 +0100
+
+acpid (1.0.0-1) unstable; urgency=low
+
+  * New upstream release
+  * Fixed read_line to work with unpatched 2.4.x kernels.
+
+ -- Cajus Pollmeier <C.Pollmeier@gmx.net>  Mon, 10 Aug 2001 12:12:41 +0200
+
+acpid (0.2001051000-1) unstable; urgency=low
+
+  * New upstream release (Closes: #97277, #104266)
+  * New maintainer
+  * 'acpictl' is no longer in the acpid package. (Closes: #79498)
+  * 'acpid' doesn't need build-depends anymore (Closes: #105751)
+
+ -- Robert van der Meulen <rvdm@debian.org>  Mon, 25 Jun 2001 16:01:12 +0200
+
+acpid (0.2000071100-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Wed, 12 Jul 2000 20:57:07 -0400
+
+acpid (0.2000052200-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Tue, 23 May 2000 13:41:51 +0200
+
+acpid (0.2000042500-1) unstable; urgency=low
+
+  * New upstream release
+  * Fix a typo in the init-script
+  * upstream changed the buildsystem again, updated debian/rules accordingly
+  * Stop via executable, not pid-file (which doesn't exist)
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Mon,  1 May 2000 23:00:46 +0200
+
+acpid (0.20000317-2) unstable; urgency=low
+
+  * Create /usr/doc compatibility symlinks
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Fri,  7 Apr 2000 14:26:31 +0200
+
+acpid (0.20000317-1) experimental; urgency=low
+
+  * New snapshot
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Mon,  3 Apr 2000 00:50:17 +0200
+
+acpid (0.20000316-1) experimental; urgency=low
+
+  * Initial release
+
+ -- Wichert Akkerman <wakkerma@debian.org>  Thu, 16 Mar 2000 12:24:51 +0100
+
--- acpid-1.0.10.orig/debian/gbp.conf
+++ acpid-1.0.10/debian/gbp.conf
@@ -0,0 +1,6 @@
+[DEFAULT]
+upstream-branch = upstream
+debian-branch = master
+upstream-tag = upstream/%(version)s
+debian-tag = debian/%(version)s
+pristine-tar = True
--- acpid-1.0.10.orig/debian/powerbtn.sh
+++ acpid-1.0.10/debian/powerbtn.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# /etc/acpi/powerbtn.sh
+# Initiates a shutdown when the power putton has been
+# pressed.
+
+# getXuser gets the X user belonging to the display in $displaynum.
+# If you want the foreground X user, use getXconsole!
+getXuser() {
+        user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
+        if [ x"$user" = x"" ]; then
+                startx=`pgrep -n startx`
+                if [ x"$startx" != x"" ]; then
+                        user=`ps -o user --no-headers $startx`
+                fi
+        fi
+        if [ x"$user" != x"" ]; then
+                userhome=`getent passwd $user | cut -d: -f6`
+                export XAUTHORITY=$userhome/.Xauthority
+        else
+                export XAUTHORITY=""
+        fi
+        export XUSER=$user
+}
+
+# Skip if we just in the middle of resuming.
+test -f /var/lock/acpisleep && exit 0
+
+# If the current X console user is running a power management daemon that
+# handles suspend/resume requests, let them handle policy This is effectively
+# the same as 'acpi-support's '/usr/share/acpi-support/policy-funcs' file.
+
+getXconsole
+PMS="gnome-power-manager kpowersave xfce4-power-manager"
+PMS="$PMS guidance-power-manager.py dalston-power-applet"
+
+if pidof x $PMS > /dev/null ||
+	( test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon) ||
+	( test "$XUSER" != "" && test -x /usr/bin/qdbus && test -r /proc/$(pidof kded4)/environ && su - $XUSER -c "eval $(echo -n 'export '; cat /proc/$(pidof kded4)/environ |tr '\0' '\n'|grep DBUS_SESSION_BUS_ADDRESS); qdbus org.kde.kded" | grep -q powerdevil) ; then
+    exit
+fi
+
+# If all else failed, just initiate a plain shutdown.
+/sbin/shutdown -h now "Power button pressed"
--- acpid-1.0.10.orig/debian/control
+++ acpid-1.0.10/debian/control
@@ -0,0 +1,30 @@
+Source: acpid
+Section: admin
+Priority: optional
+Maintainer: Debian Acpi Team <pkg-acpi-devel@lists.alioth.debian.org>
+Uploaders: Anibal Monsalve Salazar <anibal@debian.org>,
+           Michael Meskes <meskes@debian.org>,
+           Loic Minier <lool@dooz.org>
+Standards-Version: 3.8.3
+Build-Depends: debhelper (>= 5), quilt (>= 0.40)
+Vcs-Git: git://git.debian.org/git/pkg-acpi/acpid.git
+Vcs-Browser: http://git.debian.org/?p=pkg-acpi/acpid.git
+Homepage: http://acpid.sourceforge.net/
+
+Package: acpid
+Architecture: i386 ia64 amd64 lpia
+Depends: ${shlibs:Depends},
+         ${misc:Depends},
+         lsb-base (>= 3.2-14),
+         module-init-tools (>= 3.1-rel-2ubuntu2)
+Recommends: acpi-support-base (>= 0.114-1)
+Description: Advanced Configuration and Power Interface event daemon
+ Modern computers support the Advanced Configuration and Power Interface (ACPI)
+ to allow intelligent power management on your system and to query battery and
+ configuration status.
+ .
+ ACPID is a completely flexible, totally extensible daemon for delivering
+ ACPI events. It listens on netlink interface (or on the deprecated file
+ /proc/acpi/event), and when an event occurs, executes programs to handle the
+ event. The programs it executes are configured through a set of configuration
+ files, which can be dropped into place by packages or by the admin.
--- acpid-1.0.10.orig/debian/powerbtn
+++ acpid-1.0.10/debian/powerbtn
@@ -0,0 +1,13 @@
+# /etc/acpi/events/powerbtn
+# This is called when the user presses the power button and calls
+# /etc/acpi/powerbtn.sh for further processing.
+
+# Optionally you can specify the placeholder %e. It will pass
+# through the whole kernel event message to the program you've
+# specified.
+
+# We need to react on "button power.*" and "button/power.*" because
+# of kernel changes.
+
+event=button[ /]power
+action=/etc/acpi/powerbtn.sh
--- acpid-1.0.10.orig/debian/acpid.docs
+++ acpid-1.0.10/debian/acpid.docs
@@ -0,0 +1 @@
+README
--- acpid-1.0.10.orig/debian/acpid.default
+++ acpid-1.0.10/debian/acpid.default
@@ -0,0 +1,11 @@
+# Options to pass to acpid
+#
+# OPTIONS are appended to the acpid command-line
+#OPTIONS=""
+
+# Linux kernel modules to load before starting acpid
+#
+# MODULES is a space seperated list of modules to load, or "all" to load all
+# acpi drivers, or commented out to load no module
+#MODULES="battery ac processor button fan thermal video"
+#MODULES="all"
--- acpid-1.0.10.orig/debian/README.debian
+++ acpid-1.0.10/debian/README.debian
@@ -0,0 +1,34 @@
+acpid for Debian
+================
+
+The acpid daemon can handle user defined events. Place event files under
+/etc/acpi/events.
+
+If an event occurs, acpid recurses through the event files in order to
+see if the regex defined after "event" matches. If they do, action is
+executed.
+
+An example with /etc/acpi/events/powerbtn to handle presses on the power
+button.
+
+new style:
+    event=button/power .*
+    action=/etc/acpi/powerbtn.sh
+
+old style:
+    event=button power.*
+    action=/etc/acpi/powerbtn.sh
+
+to handle both styles:
+    event=button[ /]power
+    action=/etc/acpi/powerbtn.sh
+
+Your script will get the complete event string (as reported by
+/proc/acpid/events), if you use %e as a parameter of your script.
+You may want to split this by calling set $*. $1 then holds the
+event group, $2 takes the event and $3 and $4 take the values as
+reported by the kernel.
+
+When using acpid with modules, you can use /etc/default/acpid in order
+to specify Linux kernel modules to be loaded at startup.
+
--- acpid-1.0.10.orig/debian/acpid.dirs
+++ acpid-1.0.10/debian/acpid.dirs
@@ -0,0 +1 @@
+/etc/acpi/events
--- acpid-1.0.10.orig/debian/compat
+++ acpid-1.0.10/debian/compat
@@ -0,0 +1 @@
+5
--- acpid-1.0.10.orig/debian/watch
+++ acpid-1.0.10/debian/watch
@@ -0,0 +1,2 @@
+version=3
+http://sf.net/acpid/acpid-(\d\.\d\.\d.*)\.tar\.gz
--- acpid-1.0.10.orig/debian/acpid.preinst
+++ acpid-1.0.10/debian/acpid.preinst
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+set -e
+
+#DEBHELPER#
+
+# Remove a no-longer used conffile
+rm_conffile() {
+    PKGNAME="$1"
+    CONFFILE="$2"
+    if [ -e "$CONFFILE" ]; then
+        md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
+        old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE '{s/ obsolete$//;s/.* //p}\"`"
+        if [ "$md5sum" != "$old_md5sum" ]; then
+            echo "Obsolete conffile $CONFFILE has been modified by you."
+            echo "Saving as $CONFFILE.dpkg-bak ..."
+            mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
+        else
+	    if [ "$CONFFILE" = "/etc/acpi/events/powerbtn" -a -e /etc/acpi/powerbtn.sh.dpkg-bak ]; then
+		# we need some special logic for /etc/acpi/events/powerbtn because it might
+		# be kept because it was changed itself or because /etc/acpi/powerbtn.sh was changed
+		echo "Obsolete conffile $CONFFILE saved as $CONFFILE.dpkg-bak ..."
+		sed -e 's#/etc/acpi/powerbtn.sh#/etc/acpi/powerbtn.sh.dpkg-bak#' < "$CONFFILE" > "$CONFFILE".dpkg-bak
+	    else
+		echo "Removing obsolete conffile $CONFFILE ..."
+	    fi
+	    rm -f "$CONFFILE"
+        fi
+    fi
+}
+
+case "$1" in
+  install|upgrade)
+    if dpkg --compare-versions "$2" lt 1.0.8-7; then
+	rm_conffile acpid /etc/logrotate.d/acpid
+	rm_conffile acpid /etc/acpi/powerbtn.sh
+	rm_conffile acpid /etc/acpi/events/powerbtn
+    fi
+  ;;
+esac
+
--- acpid-1.0.10.orig/debian/acpid.postinst
+++ acpid-1.0.10/debian/acpid.postinst
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+set -e
+
+# Remove old init.d links
+if dpkg --compare-versions "$2" lt-nl "1.0.10-3"; then
+	rm -f /etc/rc1.d/K??acpid
+fi
+
+if dpkg --compare-versions "$2" lt-nl "1.0.6-16"; then
+	rm -f /etc/rc[06].d/K??acpid
+fi
+
+if dpkg --compare-versions "$2" lt "1.0.6-6"; then
+	rm -f /etc/rc1.d/K20acpid /etc/rc[2-5].d/S20acpid
+fi
+
+# Fix very old permission problem
+if dpkg --compare-versions "$2" lt-nl "1.0.10-5~bpo50+1"; then
+	[ -f /var/log/acpid ] && chmod 640 /var/log/acpid*
+fi
+
+HAL_NEEDS_RESTARTING=no
+case "$1" in
+  configure|reconfigure)
+    # check whether the hal init script is present and hal seems running; we
+    # need to stop hal to grab /proc/acpi/event; when hal starts again, it will
+    # simply ignore this interface as long as acpid is installed; see
+    # Launchpad #63450
+    if [ -x /etc/init.d/hal ] && [ -f /var/run/hal/hald.pid ]; then
+      HAL_NEEDS_RESTARTING=yes
+      invoke-rc.d hal stop
+    fi
+    ;;
+esac
+
+#DEBHELPER#
+
+case "$1" in
+  configure|reconfigure)
+    if [ -x /etc/init.d/hal ] && [ "$HAL_NEEDS_RESTARTING" = "yes" ]; then
+      invoke-rc.d hal start
+    fi
+    ;;
+esac
--- acpid-1.0.10.orig/debian/acpid.manpages
+++ acpid-1.0.10/debian/acpid.manpages
@@ -0,0 +1,2 @@
+acpid.8
+acpi_listen.8
--- acpid-1.0.10.orig/debian/README.source
+++ acpid-1.0.10/debian/README.source
@@ -0,0 +1,58 @@
+This package uses quilt to manage all modifications to the upstream
+source.  Changes are stored in the source package as diffs in
+debian/patches and applied during the build.
+
+To configure quilt to use debian/patches instead of patches, you want
+either to export QUILT_PATCHES=debian/patches in your environment
+or use this snippet in your ~/.quiltrc:
+
+    for where in ./ ../ ../../ ../../../ ../../../../ ../../../../../; do
+        if [ -e ${where}debian/rules -a -d ${where}debian/patches ]; then
+                export QUILT_PATCHES=debian/patches
+                break
+        fi
+    done
+
+To get the fully patched source after unpacking the source package, cd to
+the root level of the source package and run:
+
+    quilt push -a
+
+The last patch listed in debian/patches/series will become the current
+patch.
+
+To add a new set of changes, first run quilt push -a, and then run:
+
+    quilt new <patch>
+
+where <patch> is a descriptive name for the patch, used as the filename in
+debian/patches.  Then, for every file that will be modified by this patch,
+run:
+
+    quilt add <file>
+
+before editing those files.  You must tell quilt with quilt add what files
+will be part of the patch before making changes or quilt will not work
+properly.  After editing the files, run:
+
+    quilt refresh
+
+to save the results as a patch.
+
+Alternately, if you already have an external patch and you just want to
+add it to the build system, run quilt push -a and then:
+
+    quilt import -P <patch> /path/to/patch
+    quilt push -a
+
+(add -p 0 to quilt import if needed). <patch> as above is the filename to
+use in debian/patches.  The last quilt push -a will apply the patch to
+make sure it works properly.
+
+To remove an existing patch from the list of patches that will be applied,
+run:
+
+    quilt delete <patch>
+
+You may need to run quilt pop -a to unapply patches first before running
+this command.
--- acpid-1.0.10.orig/debian/acpid.postrm
+++ acpid-1.0.10/debian/acpid.postrm
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" = purge ]; then
+	rm -f /var/backups/acpid-cruft.tar.gz
+
+	# We restart hal on install and upgrades because acpid needs
+	# /proc/acpi/event and hal might hold it (see postinst). On removal we
+	# should restart hal to allow it to grab the file again.
+	if [ -x /etc/init.d/hal ]; then
+		invoke-rc.d hal restart
+	fi
+fi
+
+#DEBHELPER#
--- acpid-1.0.10.orig/debian/acpid.install
+++ acpid-1.0.10/debian/acpid.install
@@ -0,0 +1,8 @@
+debian/powerbtn			usr/share/doc/acpid/examples/
+debian/powerbtn.sh  		usr/share/doc/acpid/examples/
+debian/examples/default		usr/share/doc/acpid/examples/
+debian/examples/default.sh	usr/share/doc/acpid/examples/
+debian/examples/ac		usr/share/doc/acpid/examples/
+debian/examples/ac.sh		usr/share/doc/acpid/examples/
+acpi_listen			usr/bin
+acpid				usr/sbin
--- acpid-1.0.10.orig/debian/patches/event.c.diff
+++ acpid-1.0.10/debian/patches/event.c.diff
@@ -0,0 +1,43 @@
+--- acpid-1.0.8.orig/event.c
++++ acpid-1.0.8/event.c
+@@ -23,6 +23,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/wait.h>
++#include <libgen.h>
+ #include <sys/poll.h>
+ #include <fcntl.h>
+ #include <unistd.h>
+@@ -92,6 +93,8 @@
+ 	struct dirent *dirent;
+ 	char *file = NULL;
+ 	int nrules = 0;
++	char *basen = NULL;
++	regex_t preg;
+ 
+ 	lock_rules();
+ 
+@@ -141,10 +144,19 @@
+ 			continue; /* skip non-regular files */
+ 		}
+ 
+-		r = parse_file(file);
+-		if (r) {
+-			enlist_rule(&cmd_list, r);
+-			nrules++;
++		/* check for run-parts style filename */
++		basen = basename(file);
++		if (regcomp(&preg, "^[a-zA-Z0-9_-]+$", RULE_REGEX_FLAGS) == 0){
++			if (regexec(&preg, basen, 0, NULL, 0) == 0){
++				r = parse_file(file);
++				if (r) {
++					enlist_rule(&cmd_list, r);
++					nrules++;
++				}
++			} else {
++				acpid_log(LOG_DEBUG, "ignoring conf file %s\n", file);
++			}
++
+ 		}
+ 		free(file);
+ 	}
--- acpid-1.0.10.orig/debian/patches/series
+++ acpid-1.0.10/debian/patches/series
@@ -0,0 +1,2 @@
+event.c.diff
+netlink6.diff
--- acpid-1.0.10.orig/debian/patches/netlink6.diff
+++ acpid-1.0.10/debian/patches/netlink6.diff
@@ -0,0 +1,3312 @@
+--- acpid.old/acpid.8	2009-11-17 14:36:21.000000000 +0100
++++ acpid/acpid.8	2009-11-17 14:44:42.000000000 +0100
+@@ -10,11 +10,13 @@
+ \fBacpid\fP is designed to notify user-space programs of ACPI events.
+ \fBacpid\fP should be started during the system boot, and will run as a
+ background process, by default.  It will open an events file
+-(\fI/proc/acpi/event\fP by default) and attempt to read whole lines.  When
+-a line is received (an \fIevent\fP), \fBacpid\fP will examine a list of rules,
+-and execute the rules that match the event.
+-\fBacpid\fP will ignore all incoming ACPI events if a lock file exists
+-(\fI/var/lock/acpid\fP by default).
++(\fI/proc/acpi/event\fP by default) and attempt to read whole lines which
++represent ACPI events.  If the events file does not exist, \fBacpid\fP will
++attempt to connect to the Linux kernel via the input layer and netlink.  When an
++ACPI event is received from one of these sources, \fBacpid\fP will examine a
++list of rules, and execute the rules that match the event. \fBacpid\fP will
++ignore all incoming ACPI events if a lock file exists (\fI/var/lock/acpid\fP by
++default).
+ .PP
+ \fIRules\fP are defined by simple configuration files.  \fBacpid\fP
+ will look in a configuration directory (\fI/etc/acpi/events\fP by default),
+@@ -73,6 +75,9 @@
+ This option changes the event file from which \fBacpid\fP reads events.
+ Default is \fI/proc/acpi/event\fP.
+ .TP
++.BI \-n "\fR, \fP" \--netlink
++This option forces \fBacpid\fP to use the Linux kernel input layer and netlink interface for ACPI events.
++.TP
+ .BI \-f "\fR, \fP" \--foreground
+ This option keeps \fBacpid\fP in the foreground by not forking at startup.
+ .TP
+@@ -126,6 +131,8 @@
+ .PD 0
+ .B /proc/acpi/event
+ .br
++.B /dev/input/event*
++.br
+ .B /etc/acpi/
+ .br
+ .B /var/run/acpid.socket
+--- acpid.old/acpid.c	2009-11-17 14:36:16.000000000 +0100
++++ acpid/acpid.c	2009-11-17 14:44:45.000000000 +0100
+@@ -20,23 +20,24 @@
+  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  */
+ 
+-#include <sys/types.h>
+-#include <sys/stat.h>
++#include <unistd.h>
+ #include <fcntl.h>
+ #include <signal.h>
+-#include <unistd.h>
++#include <string.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+-#include <string.h>
+ #include <errno.h>
+ #include <getopt.h>
+-#include <time.h>
+-#include <sys/poll.h>
+-#include <grp.h>
+-#include <syslog.h>
++#include <stdarg.h>
+ 
+ #include "acpid.h"
+-#include "ud_socket.h"
++#include "event.h"
++#include "connection_list.h"
++#include "proc.h"
++#include "sock.h"
++#include "input_layer.h"
++#include "inotify_handler.h"
++#include "netlink.h"
+ 
+ static int handle_cmdline(int *argc, char ***argv);
+ static void close_fds(void);
+@@ -44,9 +45,7 @@
+ static int open_log(void);
+ static int create_pidfile(void);
+ static void clean_exit(int sig);
+-static void clean_exit_with_status(int status);
+ static void reload_conf(int sig);
+-static char *read_line(int fd);
+ 
+ /* global debug level */
+ int acpid_debug;
+@@ -54,27 +53,17 @@
+ /* do we log event info? */
+ int logevents;
+ 
+-/* the number of non-root clients that are connected */
+-int non_root_clients;
+-
+-static const char *progname;
++const char *progname;
+ static const char *confdir = ACPID_CONFDIR;
+-static const char *eventfile = ACPID_EVENTFILE;
+-static const char *socketfile = ACPID_SOCKETFILE;
+ static const char *lockfile = ACPID_LOCKFILE;
+ static int nosocket;
+-static const char *socketgroup;
+-static mode_t socketmode = ACPID_SOCKETMODE;
+ static int foreground;
+ static const char *pidfile = ACPID_PIDFILE;
+-static int clientmax = ACPID_CLIENTMAX;
++static int netlink;
+ 
+ int
+ main(int argc, char **argv)
+ {
+-	int event_fd;
+-	int sock_fd = -1; /* init to avoid a compiler warning */
+-
+ 	/* learn who we really are */
+ 	progname = (const char *)strrchr(argv[0], '/');
+ 	progname = progname ? (progname + 1) : argv[0];
+@@ -85,14 +74,25 @@
+ 	/* close any extra file descriptors */
+ 	close_fds();
+ 
+-	/* actually open the event file */
+-	event_fd = open(eventfile, O_RDONLY);
+-	if (event_fd < 0) {
+-		fprintf(stderr, "%s: can't open %s: %s\n", progname, 
+-			eventfile, strerror(errno));
+-		exit(EXIT_FAILURE);
++	if (!netlink)
++	{
++		/* open the acpi event file in the proc fs */
++		/* if the open fails, try netlink */
++		if (open_proc())
++			netlink = 1;
++	}
++
++	if (netlink)
++	{
++		/* open the input layer */
++		open_input();
++
++		/* watch for new input layer devices */
++		open_inotify();
++
++		/* open netlink */
++		open_netlink();
+ 	}
+-	fcntl(event_fd, F_SETFD, FD_CLOEXEC);
+ 
+ /*
+  * if there is data, and the kernel is NOT broken, this eats 1 byte.  We
+@@ -129,34 +129,7 @@
+ 
+ 	/* open our socket */
+ 	if (!nosocket) {
+-		sock_fd = ud_create_socket(socketfile);
+-		if (sock_fd < 0) {
+-			fprintf(stderr, "%s: can't open socket %s: %s\n",
+-				progname, socketfile, strerror(errno));
+-			exit(EXIT_FAILURE);
+-		}
+-		fcntl(sock_fd, F_SETFD, FD_CLOEXEC);
+-		chmod(socketfile, socketmode);
+-		if (socketgroup) {
+-			struct group *gr;
+-			struct stat buf;
+-			gr = getgrnam(socketgroup);
+-			if (!gr) {
+-				fprintf(stderr, "%s: group %s does not exist\n",
+-					progname, socketgroup);
+-				exit(EXIT_FAILURE);
+-			}
+-			if (stat(socketfile, &buf) < 0) {
+-				fprintf(stderr, "%s: can't stat %s\n",
+-					progname, socketfile);
+-				exit(EXIT_FAILURE);
+-			}
+-			if (chown(socketfile, buf.st_uid, gr->gr_gid) < 0) {
+-				fprintf(stderr, "%s: chown(): %s\n",
+-					progname, strerror(errno));
+-				exit(EXIT_FAILURE);
+-			}
+-		}
++		open_sock();
+ 	}
+ 
+ 	/* if we're running in foreground, we don't daemonize */
+@@ -169,7 +142,8 @@
+ 	if (open_log() < 0) {
+ 		exit(EXIT_FAILURE);
+ 	}
+-	acpid_log(LOG_INFO, "starting up\n");
++	acpid_log(LOG_INFO, "starting up with %s\n",
++		netlink ? "netlink and the input layer" : "proc fs");
+ 
+ 	/* trap key signals */
+ 	signal(SIGHUP, reload_conf);
+@@ -188,128 +162,53 @@
+ 		exit(EXIT_FAILURE);
+ 	}
+ 
+-	/* main loop */
+ 	acpid_log(LOG_INFO, "waiting for events: event logging is %s\n",
+ 	    logevents ? "on" : "off");
+-	while (1) {
+-		struct pollfd ar[2];
+-		int r;
+-		int fds = 0;
+-
+-		/* poll for the socket and the event file */
+-		ar[0].fd = event_fd; ar[0].events = POLLIN; fds++;
+-		if (!nosocket) {
+-			ar[1].fd = sock_fd; ar[1].events = POLLIN; fds++;
+-		}
+-		r = poll(ar, fds, -1);
+ 
+-		if (r < 0 && errno == EINTR) {
++	/* main loop */
++	while (1)
++	{
++		fd_set readfds;
++		int nready;
++		int i;
++		struct connection *p;
++
++		/* it's going to get clobbered, so use a copy */
++		readfds = *get_fdset();
++
++		/* wait on data */
++		nready = select(get_highestfd() + 1, &readfds, NULL, NULL, NULL);
++
++		if (nready < 0  &&  errno == EINTR) {
+ 			continue;
+-		} else if (r < 0) {
+-			acpid_log(LOG_ERR, "poll(): %s\n", strerror(errno));
++		} else if (nready < 0) {
++			acpid_log(LOG_ERR, "select(): %s\n", strerror(errno));
+ 			continue;
+ 		}
+ 
+ 		/* house keeping */
+ 		acpid_close_dead_clients();
+ 
+-		/* was it an event? */
+-		if (ar[0].revents) {
+-			char *event;
+-			struct stat trash;
+-			int fexists;
+-
+-			/* check for existence of a lockfile */
+-			fexists = (stat(lockfile, &trash) == 0);
+-
+-			/* this shouldn't happen */
+-			if (!ar[0].revents & POLLIN) {
+-				acpid_log(LOG_DEBUG,
+-				    "odd, poll set flags 0x%x\n",
+-				    ar[0].revents);
+-				continue;
+-			}
+-
+-			/* read an event */
+-			event = read_line(event_fd);
++		/* for each connection */
++		for (i = 0; i <= get_number_of_connections(); ++i)
++		{
++			int fd;
+ 
+-			/* if we're locked, don't process the event */
+-			if (fexists) {
+-				if (logevents) {
+-					acpid_log(LOG_INFO,
+-					    "lockfile present, not processing "
+-					    "event \"%s\"\n", event);
+-				}
+-				continue;
+-			}
++			p = get_connection(i);
+ 
+-			/* handle the event */
+-			if (event) {
+-				if (logevents) {
+-					acpid_log(LOG_INFO,
+-					    "received event \"%s\"\n", event);
+-				}
+-				acpid_handle_event(event);
+-				if (logevents) {
+-					acpid_log(LOG_INFO,
+-					    "completed event \"%s\"\n", event);
+-				}
+-			} else if (errno == EPIPE) {
+-				acpid_log(LOG_WARNING,
+-				    "events file connection closed\n");
++			/* if this connection is invalid, bail */
++			if (!p)
+ 				break;
+-			} else {
+-				static int nerrs;
+-				if (++nerrs >= ACPID_MAX_ERRS) {
+-					acpid_log(LOG_ERR,
+-					    "too many errors reading "
+-					    "events file - aborting\n");
+-					break;
+-				}
+-			}
+-		}
+ 
+-		/* was it a new connection? */
+-		if (!nosocket && ar[1].revents) {
+-			int cli_fd;
+-			struct ucred creds;
+-			char buf[32];
+-			static int accept_errors;
+-
+-			/* this shouldn't happen */
+-			if (!ar[1].revents & POLLIN) {
+-				acpid_log(LOG_DEBUG,
+-				    "odd, poll set flags 0x%x\n",
+-				    ar[1].revents);
+-				continue;
+-			}
++			/* get the file descriptor */
++			fd = p->fd;
+ 
+-			/* accept and add to our lists */
+-			cli_fd = ud_accept(sock_fd, &creds);
+-			if (cli_fd < 0) {
+-				acpid_log(LOG_ERR, "can't accept client: %s\n",
+-				    strerror(errno));
+-				accept_errors++;
+-				if (accept_errors >= 5) {
+-					acpid_log(LOG_ERR, "giving up\n");
+-					clean_exit_with_status(EXIT_FAILURE);
+-				}
+-				continue;
+-			}
+-			accept_errors = 0;
+-			if (creds.uid != 0 && non_root_clients >= clientmax) {
+-				close(cli_fd);
+-				acpid_log(LOG_ERR,
+-				    "too many non-root clients\n");
+-				continue;
+-			}
+-			if (creds.uid != 0) {
+-				non_root_clients++;
++			/* if this file descriptor has data waiting */
++			if (FD_ISSET(fd, &readfds))
++			{
++				/* delegate to this connection's process function */
++				p->process(fd);
+ 			}
+-			fcntl(cli_fd, F_SETFD, FD_CLOEXEC);
+-			snprintf(buf, sizeof(buf)-1, "%d[%d:%d]",
+-				creds.pid, creds.uid, creds.gid);
+-			acpid_add_client(cli_fd, buf);
+ 		}
+ 	}
+ 
+@@ -337,6 +236,7 @@
+ 		{"nosocket", 1, 0, 'S'},
+ 		{"pidfile", 1, 0, 'p'},
+ 		{"lockfile", 1, 0, 'L'},
++		{"netlink", 0, 0, 'n'},
+ 		{"version", 0, 0, 'v'},
+ 		{"help", 0, 0, 'h'},
+ 		{NULL, 0, 0, 0},
+@@ -353,7 +253,8 @@
+ 		"Use the specified socket file.",	/* socketfile */
+ 		"Do not listen on a UNIX socket (overrides -s).",/* nosocket */
+ 		"Use the specified PID file.",		/* pidfile */
+-		"Use the specified lockfile to stop processing.", /* pidfile */
++		"Use the specified lockfile to stop processing.", /* lockfile */
++		"Force netlink/input layer mode. (overrides -e)", /* netlink */
+ 		"Print version information.",		/* version */
+ 		"Print this message.",			/* help */
+ 	};
+@@ -364,7 +265,7 @@
+ 	for (;;) {
+ 		int i;
+ 		i = getopt_long(*argc, *argv,
+-		    "c:C:de:flg:m:s:Sp:L:vh", opts, NULL);
++		    "c:C:de:flg:m:s:Sp:L:nvh", opts, NULL);
+ 		if (i == -1) {
+ 			break;
+ 		}
+@@ -406,6 +307,9 @@
+ 		case 'L':
+ 			lockfile = optarg;
+ 			break;
++		case 'n':
++			netlink = 1;
++			break;
+ 		case 'v':
+ 			printf(PACKAGE "-" VERSION "\n");
+ 			exit(EXIT_SUCCESS);
+@@ -547,7 +451,7 @@
+ 	return -1;
+ }
+ 
+-static void
++void
+ clean_exit_with_status(int status)
+ {
+ 	acpid_cleanup_rules(1);
+@@ -585,54 +489,11 @@
+ 	return 0;
+ }
+ 
+-/* 
+- * This depends on fixes in linux ACPI after 2.4.8
+- */
+-#define MAX_BUFLEN	1024
+-static char *
+-read_line(int fd)
+-{
+-	static char *buf;
+-	int buflen = 64;
+-	int i = 0;
+-	int r;
+-	int searching = 1;
+-
+-	while (searching) {
+-		buf = realloc(buf, buflen);
+-		if (!buf) {
+-			acpid_log(LOG_ERR, "malloc(%d): %s\n",
+-				buflen, strerror(errno));
+-			return NULL;
+-		}
+-		memset(buf+i, 0, buflen-i);
+-
+-		while (i < buflen) {
+-			r = read(fd, buf+i, 1);
+-			if (r < 0 && errno != EINTR) {
+-				/* we should do something with the data */
+-				acpid_log(LOG_ERR, "read(): %s\n",
+-					strerror(errno));
+-				return NULL;
+-			} else if (r == 0) {
+-				/* signal this in an almost standard way */
+-				errno = EPIPE;
+-				return NULL;
+-			} else if (r == 1) {
+-				/* scan for a newline */
+-				if (buf[i] == '\n') {
+-					searching = 0;
+-					buf[i] = '\0';
+-					break;
+-				}
+-				i++;
+-			}
+-		}
+-		if (buflen >= MAX_BUFLEN) {
+-			break;
+-		} 
+-		buflen *= 2;
+-	}
++int
++locked()
++{
++	struct stat trash;
+ 
+-	return buf;
++	/* check for existence of a lockfile */
++	return (stat(lockfile, &trash) == 0);
+ }
+--- acpid.old/acpid.h	2009-11-17 14:36:21.000000000 +0100
++++ acpid/acpid.h	2009-11-17 14:44:45.000000000 +0100
+@@ -23,11 +23,7 @@
+ #ifndef ACPID_H__
+ #define ACPID_H__
+ 
+-#include <unistd.h>
+ #include <syslog.h>
+-#include <stdarg.h>
+-#include <sys/types.h>
+-#include <sys/stat.h>
+ 
+ #define ACPI_PROCDIR 		"/proc/acpi"
+ #define ACPID_EVENTFILE		ACPI_PROCDIR "/event"
+@@ -39,6 +35,10 @@
+ #define ACPID_LOCKFILE		"/var/lock/acpid"
+ #define ACPID_MAX_ERRS		5
+ 
++/* ??? make these changeable by commandline option? */
++#define ACPID_INPUTLAYERDIR   "/dev/input"
++#define ACPID_INPUTLAYERFILES ACPID_INPUTLAYERDIR "/event*"
++
+ #define PACKAGE 		"acpid"
+ 
+ /*
+@@ -46,16 +46,12 @@
+  */
+ extern int acpid_debug;
+ extern int logevents;
+-extern int non_root_clients;
++extern const char *progname;
++
+ extern int acpid_log(int level, const char *fmt, ...);
+ 
+-/*
+- * event.c
+- */
+-extern int acpid_read_conf(const char *confdir);
+-extern int acpid_add_client(int client, const char *origin);
+-extern int acpid_cleanup_rules(int do_detach);
+-extern int acpid_handle_event(const char *event);
+-extern void acpid_close_dead_clients(void);
++extern int locked();
++
++extern void clean_exit_with_status(int status);
+ 
+ #endif /* ACPID_H__ */
+--- acpid.old/acpi_genetlink.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/acpi_genetlink.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,33 @@
++#ifndef __ACPI_GENETLINK_H__
++#define __ACPI_GENETLINK_H__ 1
++
++#include <linux/types.h>
++
++struct acpi_genl_event {
++        char device_class[20];
++        char bus_id[15];
++        __u32 type;
++        __u32 data;
++};
++
++/* attributes of acpi_genl_family */
++enum {
++        ACPI_GENL_ATTR_UNSPEC,
++        ACPI_GENL_ATTR_EVENT,   /* ACPI event info needed by user space */
++        __ACPI_GENL_ATTR_MAX,
++};
++#define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1)
++
++/* commands supported by the acpi_genl_family */
++enum {
++        ACPI_GENL_CMD_UNSPEC,
++        ACPI_GENL_CMD_EVENT,    /* kernel->user notifications for ACPI events */        __ACPI_GENL_CMD_MAX,
++};
++#define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
++#define GENL_MAX_FAM_OPS        256
++#define GENL_MAX_FAM_GRPS       256
++
++#define ACPI_EVENT_FAMILY_NAME		"acpi_event"
++#define ACPI_EVENT_MCAST_GROUP_NAME	"acpi_mc_group"
++
++#endif
+--- acpid.old/acpi_ids.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/acpi_ids.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,259 @@
++/*
++ *  acpi_ids.c - ACPI Netlink Group and Family IDs
++ *
++ *  Copyright (C) 2008 Ted Felix (www.tedfelix.com)
++ *  Portions from acpi_genl Copyright (C) Zhang Rui <rui.zhang@intel.com>
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#include <stdio.h>
++/* needed by netlink.h, should be in there */
++#include <arpa/inet.h>
++#include <linux/types.h>
++#include <string.h>
++
++#include "genetlink.h"
++#include "libnetlink.h"
++
++#include "acpid.h"
++
++#define GENL_MAX_FAM_GRPS       256
++#define ACPI_EVENT_FAMILY_NAME          "acpi_event"
++#define ACPI_EVENT_MCAST_GROUP_NAME     "acpi_mc_group"
++
++static int initialized = 0;
++static __u16 acpi_event_family_id = 0;
++static __u32 acpi_event_mcast_group_id = 0;
++
++/*
++ *  A CTRL_CMD_GETFAMILY message returns an attribute table that looks
++ *    like this:
++ *
++ *  CTRL_ATTR_FAMILY_ID         Use this to make sure we get the proper msgs
++ *  CTRL_ATTR_MCAST_GROUPS
++ *    CTRL_ATTR_MCAST_GRP_NAME
++ *    CTRL_ATTR_MCAST_GRP_ID    Need this for the group mask
++ *    ...
++ */
++
++static int
++get_ctrl_grp_id(struct rtattr *arg)
++{
++	struct rtattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1];
++	char *name;
++
++	if (arg == NULL)
++		return -1;
++
++	/* nested within the CTRL_ATTR_MCAST_GROUPS attribute are the  */
++	/* group name and ID  */
++	parse_rtattr_nested(tb, CTRL_ATTR_MCAST_GRP_MAX, arg);
++
++	/* if either of the entries needed cannot be found, bail */
++	if (!tb[CTRL_ATTR_MCAST_GRP_NAME] || !tb[CTRL_ATTR_MCAST_GRP_ID])
++		return -1;
++
++	/* get the name of this multicast group we've found */
++	name = RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_NAME]);
++
++	/* if it does not match the ACPI event multicast group name, bail */
++	if (strcmp(name, ACPI_EVENT_MCAST_GROUP_NAME))
++		return -1;
++
++	/* At this point, we've found what we were looking for.  We now  */
++	/* have the multicast group ID for ACPI events over generic netlink. */
++	acpi_event_mcast_group_id =
++		*((__u32 *)RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_ID]));
++
++	return 0;
++}
++
++/* n = the response to a CTRL_CMD_GETFAMILY message */
++static int
++genl_get_mcast_group_id(struct nlmsghdr *n)
++{
++	/*
++	 *  Attribute table.  Note the type name "rtattr" which means "route
++	 *  attribute".  This is a vestige of one of netlink's main uses:
++	 *  routing.
++	 */
++	struct rtattr *tb[CTRL_ATTR_MAX + 1];
++	/* place for the generic netlink header in the incoming message */
++	struct genlmsghdr ghdr;
++	/* length of the attribute and payload */
++	int len = n->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN);
++	/* Pointer to the attribute portion of the message */
++	struct rtattr *attrs;
++
++	if (len < 0) {
++		fprintf(stderr, "%s: netlink CTRL_CMD_GETFAMILY response, "
++			"wrong controller message len: %d\n", progname, len);
++		return -1;
++	}
++
++	if (n->nlmsg_type != GENL_ID_CTRL) {
++		fprintf(stderr, "%s: not a netlink controller message, "
++			"nlmsg_len=%d nlmsg_type=0x%x\n", 
++			progname, n->nlmsg_len, n->nlmsg_type);
++		return 0;
++	}
++
++	/* copy generic netlink header into structure */
++	memcpy(&ghdr, NLMSG_DATA(n), GENL_HDRLEN);
++
++	if (ghdr.cmd != CTRL_CMD_GETFAMILY &&
++	    ghdr.cmd != CTRL_CMD_DELFAMILY &&
++	    ghdr.cmd != CTRL_CMD_NEWFAMILY &&
++	    ghdr.cmd != CTRL_CMD_NEWMCAST_GRP &&
++	    ghdr.cmd != CTRL_CMD_DELMCAST_GRP) {
++		fprintf(stderr, "%s: unknown netlink controller command %d\n",
++			progname, ghdr.cmd);
++		return 0;
++	}
++
++	/* set attrs to point to the attribute */
++	attrs = (struct rtattr *)(NLMSG_DATA(n) + GENL_HDRLEN);
++	/* Read the table from the message into "tb".  This actually just  */
++	/* places pointers into the message into tb[].  */
++	parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len);
++
++	/* if a family ID attribute is present, get it */
++	if (tb[CTRL_ATTR_FAMILY_ID])
++	{
++		acpi_event_family_id =
++			*((__u32 *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]));
++	}
++
++	/* if a "multicast groups" attribute is present... */
++	if (tb[CTRL_ATTR_MCAST_GROUPS]) {
++		struct rtattr *tb2[GENL_MAX_FAM_GRPS + 1];
++		int i;
++
++		/* get the group table within this attribute  */
++		parse_rtattr_nested(tb2, GENL_MAX_FAM_GRPS,
++			tb[CTRL_ATTR_MCAST_GROUPS]);
++
++		/* for each group */
++		for (i = 0; i < GENL_MAX_FAM_GRPS; i++)
++			/* if this group is valid */
++			if (tb2[i])
++				/* Parse the ID.  If successful, we're done. */
++				if (!get_ctrl_grp_id(tb2[i]))
++					return 0;
++	}
++
++	return -1;
++}
++
++static int
++genl_get_ids(char *family_name)
++{
++	/* handle to the netlink connection */
++	struct rtnl_handle rth;
++	/* holds the request we are going to send and the reply */
++	struct {
++		struct nlmsghdr n;
++		char buf[4096];    /* ??? Is this big enough for all cases? */
++	} req;
++	/* pointer to the nlmsghdr in req */
++	struct nlmsghdr *nlh;
++	/* place for the generic netlink header before copied into req */
++	struct genlmsghdr ghdr;
++	/* return value */
++	int ret = -1;
++
++	/* clear out the request */
++	memset(&req, 0, sizeof(req));
++
++	/* set up nlh to point to the netlink header in req */
++	nlh = &req.n;
++	/* set up the netlink header */
++	nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
++	nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
++	nlh->nlmsg_type = GENL_ID_CTRL;
++
++	/* clear out the generic netlink message header */
++	memset(&ghdr, 0, sizeof(struct genlmsghdr));
++	/* set the command we want to run: "GETFAMILY" */
++	ghdr.cmd = CTRL_CMD_GETFAMILY;
++	/* copy it into req */
++	memcpy(NLMSG_DATA(&req.n), &ghdr, GENL_HDRLEN);
++
++	/* the message payload is the family name */
++	addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME,
++			  family_name, strlen(family_name) + 1);
++
++	/* open a generic netlink connection */
++	if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
++		fprintf(stderr, "%s: cannot open generic netlink socket\n", 
++			progname);
++		return -1;
++	}
++
++	/*
++	 *  Send CTRL_CMD_GETFAMILY message (in nlh) to the generic
++	 *  netlink controller.  Reply will be in nlh upon return.
++	 */
++	if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL) < 0) {
++		fprintf(stderr, "%s: error talking to the kernel via netlink\n",
++			progname);
++		goto ctrl_done;
++	}
++
++	/* process the response */
++	if (genl_get_mcast_group_id(nlh) < 0) {
++		fprintf(stderr, "%s: failed to get acpi_event netlink "
++			"multicast group\n", progname);
++		goto ctrl_done;
++	}
++
++	ret = 0;
++
++ctrl_done:
++	rtnl_close(&rth);
++	return ret;
++}
++
++/* initialize the ACPI IDs */
++static void
++acpi_ids_init()
++{
++	genl_get_ids(ACPI_EVENT_FAMILY_NAME);
++
++	initialized = 1;
++}
++
++/* returns the netlink family ID for ACPI event messages */
++__u16
++acpi_ids_getfamily()
++{
++	/* if the IDs haven't been initialized, initialize them */
++	if (initialized == 0)
++		acpi_ids_init();
++
++	return acpi_event_family_id;
++}
++
++/* returns the netlink multicast group ID for ACPI event messages */
++__u32
++acpi_ids_getgroup()
++{
++	/* if the IDs haven't been initialized, initialize them */
++	if (initialized == 0)
++		acpi_ids_init();
++
++	return acpi_event_mcast_group_id;
++}
+--- acpid.old/acpi_ids.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/acpi_ids.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,30 @@
++/*
++ *  acpi_ids.h - ACPI Netlink Group and Family IDs
++ *
++ *  Copyright (C) 2008 Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#ifndef ACPI_IDS_H__
++#define ACPI_IDS_H__
++
++/* returns the netlink family ID for ACPI event messages */
++extern __u16 acpi_ids_getfamily();
++
++/* returns the netlink multicast group ID for ACPI event messages */
++extern __u32 acpi_ids_getgroup();
++
++#endif /* ACPI_IDS_H__ */
+--- acpid.old/acpi_listen.c	2009-11-17 14:36:21.000000000 +0100
++++ acpid/acpi_listen.c	2009-11-17 14:44:42.000000000 +0100
+@@ -42,8 +42,8 @@
+ static int handle_cmdline(int *argc, char ***argv);
+ static char *read_line(int fd);
+ 
+-static const char *progname;
+-static const char *socketfile = ACPID_SOCKETFILE;
++const char *progname;
++const char *socketfile = ACPID_SOCKETFILE;
+ static int max_events;
+ 
+ static void
+--- acpid.old/Changelog	2009-11-17 14:36:21.000000000 +0100
++++ acpid/Changelog	2009-11-17 14:44:45.000000000 +0100
+@@ -1,4 +1,47 @@
+ %changelog
++* Thu Nov 13 2009  Ted Felix <http://www.tedfelix.com/>
++  - 1.0.10-netlink6 release
++  - Implemented discovery of new input layer devices using inotify(7).
++    (inotify_handler.h inotify_handler.c acpid.c input_layer.h input_layer.c)
++    (Ted Felix)
++  - Updated input layer event table to incorporate more events and
++    to support a format compatible with older event configuration
++    files.  (input_layer.c) (Harald Braumann and Ted Felix)
++  - Cleanup and move of input layer constants.  (acpid.h input_layer.c 
++    inotify_handler.c) (Ted Felix)
++  - kacpimon now opens all event sources and reports where each event 
++    comes from.  This makes it more useful for discovering events.
++    (kacpimon/kacpimon.c kacpimon/input_layer.c kacpimon/netlink.c)
++    (Ted Felix)
++  - Turned off strict aliasing optimizations as the netlink code is
++    filled with strict aliasing problems.  (Makefile) (Ted Felix)
++
++* Fri Nov 6 2009  Ted Felix <http://www.tedfelix.com/>
++  - 1.0.10-netlink5 release
++  - Fixed exit on device removal.  (input_layer.c connection_list.h
++    connection_list.c) (Mikhail Krivtsov)
++
++* Sun Jul 19 2009  Ted Felix <http://www.tedfelix.com/>
++  - 1.0.10-netlink4 release
++  - Added events to input_layer.c to cover more buttons on the Thinkpad X40
++    (input_layer.c) (Peter Stuge)
++  - Fixed Makefile "dist" target to work properly.  (Makefile) (Ted Felix)
++  - Added kacpimon to the codebase as a debugging tool.  (kacpimon directory,
++    Makefile) (Ted Felix)
++  - Removed erroneous comment in sock.c about the 256 connection limit.
++    (sock.c) (Ted Felix)
++  - Removed unnecessary #include from connection_list.c.  (connection_list.c)
++    (Ted Felix)
++
++* Mon May 04 2009  Ted Felix <http://www.tedfelix.com/>
++  - Fixed strict aliasing issue with gcc 4.4. (acpi_ids.c) (Michael Meskes
++    and Peter Alfredsen)
++  - 1.0.10-netlink3 release.
++
++* Sat May 02 2009  Ted Felix <http://www.tedfelix.com/>
++  - Merge of the following three 1.0.10 changes into 1.0.10-netlink2
++    (Michael Meskes and Ted Felix)
++
+ * Wed Apr 22 2009  Tim Hockin <thockin@hockin.org>
+   - Bump version to 1.0.10 for release.
+ 
+@@ -13,6 +56,11 @@
+ * Mon Feb 09 2009  Tim Hockin <thockin@hockin.org>
+   - Open /dev/null O_RDWR, rather than O_RDONLY. (acpid.c)
+ 
++* Thu Dec 11 2008  Ted Felix <http://www.tedfelix.com/>
++  - Version 1.0.8ted1
++  - Netlink and Input Layer support.  Many files have been changed and
++    several have been added.  (Ted Felix <http://www.tedfelix.com/>)
++
+ * Tue Oct 28 2008  Tim Hockin <thockin@hockin.org>
+   - Bump version to 1.0.8 for release.
+ 
+--- acpid.old/connection_list.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/connection_list.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,149 @@
++/*
++ *  connection_list.c - ACPI daemon connection list
++ *
++ *  Copyright (C) 2008, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  Tabs at 4
++ */
++
++#include <unistd.h>
++#include <stdio.h>
++
++#include "acpid.h"
++
++#include "connection_list.h"
++
++#define max(a, b)  (((a)>(b))?(a):(b))
++
++/*---------------------------------------------------------------*/
++/* private objects */
++
++#define MAX_CONNECTIONS 10
++
++static struct connection connection_list[MAX_CONNECTIONS];
++
++static int nconnections = 0;
++
++/* fd_set containing all the fd's that come in */
++static fd_set allfds;
++
++/* highest fd that is opened */
++/* (-2 + 1) causes select() to return immediately */
++static int highestfd = -2;
++
++/*---------------------------------------------------------------*/
++/* public functions */
++
++void
++add_connection(struct connection *p)
++{
++	if (nconnections < 0)
++		return;
++	if (nconnections >= MAX_CONNECTIONS) {
++		acpid_log(LOG_ERR, "Too many connections.\n");
++		/* ??? This routine should return -1 in this situation so that */
++		/*   callers can clean up any open fds and whatnot.  */
++		return;
++	}
++
++	if (nconnections == 0)
++		FD_ZERO(&allfds);
++	
++	/* add the connection to the connection list */
++	connection_list[nconnections] = *p;
++	++nconnections;
++	
++	/* add to the fd set */
++	FD_SET(p->fd, &allfds);
++	highestfd = max(highestfd, p->fd);
++}
++
++/*---------------------------------------------------------------*/
++
++void
++delete_connection(int fd)
++{
++	int i;
++
++	close(fd);
++
++	/* remove from the fd set */
++	FD_CLR(fd, &allfds);
++
++	for (i = 0; i < nconnections; ++i) {
++		/* if the file descriptors match, delete the connection */
++		if (connection_list[i].fd == fd) {
++			--nconnections;
++			connection_list[i] = connection_list[nconnections];
++			break;
++		}
++	}
++	
++	/* ??? might be nice to re-evaluate highestfd */
++}
++
++/*---------------------------------------------------------------*/
++
++struct connection *
++find_connection(int fd)
++{
++	int i;
++
++	/* for each connection */
++	for (i = 0; i < nconnections; ++i) {
++		/* if the file descriptors match, return the connection */
++		if (connection_list[i].fd == fd)
++			return &connection_list[i];
++	}
++
++	return NULL;
++}
++
++/*---------------------------------------------------------------*/
++
++int 
++get_number_of_connections()
++{
++	return nconnections;
++}
++
++/*---------------------------------------------------------------*/
++
++struct connection *
++get_connection(int i)
++{
++	if (i < 0  ||  i >= nconnections)
++		return NULL;
++
++	return &connection_list[i];
++}
++
++/*---------------------------------------------------------------*/
++
++const fd_set *
++get_fdset()
++{
++	return &allfds;
++}
++
++/*---------------------------------------------------------------*/
++
++int
++get_highestfd()
++{
++	return highestfd;
++}
+--- acpid.old/connection_list.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/connection_list.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,62 @@
++/*
++ *  connection_list.h - ACPI daemon connection list
++ *
++ *  Copyright (C) 2008, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  Tabs at 4
++ */
++
++#ifndef CONNECTION_LIST_H__
++#define CONNECTION_LIST_H__
++
++#include <sys/select.h>
++
++/*****************************************************************
++ *  Connection List Public Members
++ *****************************************************************/
++
++struct connection
++{
++	/* file descriptor */
++	int fd;
++
++	/* process incoming data on the connection */
++	void (* process)(int fd);
++};
++
++/* add a connection to the list */
++extern void add_connection(struct connection *p);
++
++/* delete a connection from the list */
++extern void delete_connection(int fd);
++
++/* find a connection in the list by file descriptor */
++extern struct connection *find_connection(int fd);
++
++/* get the number of connections in the list */
++extern int get_number_of_connections();
++
++/* get a specific connection by index from the list */
++extern struct connection *get_connection(int i);
++
++/* get an fd_set with all the fd's that have been added to the list */
++extern const fd_set *get_fdset();
++
++/* get the highest fd that was added to the list */
++extern int get_highestfd();
++
++#endif /* CONNECTION_LIST_H__ */
+--- acpid.old/event.c	2009-11-17 14:36:21.000000000 +0100
++++ acpid/event.c	2009-11-17 14:45:02.000000000 +0100
+@@ -1,5 +1,5 @@
+ /*
+- *  event.c - ACPI daemon
++ *  event.c - ACPI daemon event handler
+  *
+  *  Copyright (C) 2000 Andrew Henroid
+  *  Copyright (C) 2001 Sun Microsystems (thockin@sun.com)
+@@ -36,6 +36,7 @@
+ #include <signal.h>
+ 
+ #include "acpid.h"
++#include "sock.h"
+ #include "ud_socket.h"
+ 
+ /*
+--- acpid.old/event.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/event.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,32 @@
++/*
++ *  event.h - ACPI daemon event handler
++ *
++ *  Copyright (C) 1999-2000 Andrew Henroid
++ *  Copyright (C) 2001 Sun Microsystems
++ *  Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#ifndef EVENT_H__
++#define EVENT_H__
++
++extern int acpid_read_conf(const char *confdir);
++extern int acpid_add_client(int client, const char *origin);
++extern int acpid_cleanup_rules(int do_detach);
++extern int acpid_handle_event(const char *event);
++extern void acpid_close_dead_clients(void);
++
++#endif /* EVENT_H__ */
+--- acpid.old/genetlink.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/genetlink.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,81 @@
++#ifndef __LINUX_GENERIC_NETLINK_H
++#define __LINUX_GENERIC_NETLINK_H
++
++#include <linux/netlink.h>
++
++#define GENL_NAMSIZ	16	/* length of family name */
++
++#define GENL_MIN_ID	NLMSG_MIN_TYPE
++#define GENL_MAX_ID	1023
++
++struct genlmsghdr {
++	__u8	cmd;
++	__u8	version;
++	__u16	reserved;
++};
++
++#define GENL_HDRLEN	NLMSG_ALIGN(sizeof(struct genlmsghdr))
++
++#define GENL_ADMIN_PERM		0x01
++#define GENL_CMD_CAP_DO		0x02
++#define GENL_CMD_CAP_DUMP	0x04
++#define GENL_CMD_CAP_HASPOL	0x08
++
++/*
++ * List of reserved static generic netlink identifiers:
++ */
++#define GENL_ID_GENERATE	0
++#define GENL_ID_CTRL		NLMSG_MIN_TYPE
++
++/**************************************************************************
++ * Controller
++ **************************************************************************/
++
++enum {
++	CTRL_CMD_UNSPEC,
++	CTRL_CMD_NEWFAMILY,
++	CTRL_CMD_DELFAMILY,
++	CTRL_CMD_GETFAMILY,
++	CTRL_CMD_NEWOPS,
++	CTRL_CMD_DELOPS,
++	CTRL_CMD_GETOPS,
++	CTRL_CMD_NEWMCAST_GRP,
++	CTRL_CMD_DELMCAST_GRP,
++	CTRL_CMD_GETMCAST_GRP, /* unused */
++	__CTRL_CMD_MAX,
++};
++
++#define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
++
++enum {
++	CTRL_ATTR_UNSPEC,
++	CTRL_ATTR_FAMILY_ID,
++	CTRL_ATTR_FAMILY_NAME,
++	CTRL_ATTR_VERSION,
++	CTRL_ATTR_HDRSIZE,
++	CTRL_ATTR_MAXATTR,
++	CTRL_ATTR_OPS,
++	CTRL_ATTR_MCAST_GROUPS,
++	__CTRL_ATTR_MAX,
++};
++
++#define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
++
++enum {
++	CTRL_ATTR_OP_UNSPEC,
++	CTRL_ATTR_OP_ID,
++	CTRL_ATTR_OP_FLAGS,
++	__CTRL_ATTR_OP_MAX,
++};
++
++#define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
++
++enum {
++	CTRL_ATTR_MCAST_GRP_UNSPEC,
++	CTRL_ATTR_MCAST_GRP_NAME,
++	CTRL_ATTR_MCAST_GRP_ID,
++	__CTRL_ATTR_MCAST_GRP_MAX,
++};
++#define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1)
++
++#endif	/* __LINUX_GENERIC_NETLINK_H */
+--- acpid.old/inotify_handler.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/inotify_handler.c	2009-11-17 14:44:45.000000000 +0100
+@@ -0,0 +1,132 @@
++/*
++ *  inotify_handler.c - inotify Handler for New Devices
++ *
++ *  Watches /dev/input for new input layer device files.
++ *
++ *  Copyright (C) 2009, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++/* system */
++#include <sys/inotify.h>
++#include <sys/select.h>
++#include <sys/ioctl.h>
++#include <unistd.h>
++#include <stdio.h>
++#include <errno.h>
++#include <string.h>
++
++/* local */
++#include "acpid.h"
++#include "connection_list.h"
++#include "input_layer.h"
++
++/*-----------------------------------------------------------------*/
++/* called when an inotify event is received */
++void process_inotify(int fd)
++{
++	int bytes;
++	/* union to avoid strict-aliasing problems */
++	union {
++		char buffer[256];  /* a tad large */
++		struct inotify_event event;
++	} eventbuf;
++
++	bytes = read(fd, &eventbuf.buffer, sizeof(eventbuf.buffer));
++
++	if (acpid_debug)
++		fprintf(stderr, "%s: inotify read bytes: %d\n", progname, bytes);
++
++	/* eof is not expected */	
++	if (bytes == 0)
++	{
++		acpid_log(LOG_WARNING, "inotify fd eof encountered\n");
++		return;
++	}
++	else if (bytes < 0)
++	{
++		/* EINVAL means buffer wasn't big enough.  See inotify(7). */
++		acpid_log(LOG_ERR, "inotify read error: %s (%d)\n",
++			strerror(errno), errno);
++		acpid_log(LOG_ERR, "disconnecting from inotify\n");
++		delete_connection(fd);
++		return;
++	}
++
++	if (acpid_debug)
++		fprintf(stderr, "%s: inotify name len: %d\n", 
++			progname, eventbuf.event.len);
++
++	/* if a name is included */
++	if (eventbuf.event.len > 0)
++	{
++		const int dnsize = 256;
++		char devname[dnsize];
++
++		/* devname = ACPID_INPUTLAYERDIR + "/" + pevent -> name */
++		strcpy(devname, ACPID_INPUTLAYERDIR);
++		strcat(devname, "/");
++		strncat(devname, eventbuf.event.name, dnsize - strlen(devname) - 1);
++		
++		if (acpid_debug)
++			fprintf(stderr, "%s: inotify about to open: %s\n", 
++				progname, devname);
++
++		open_inputfile(devname);
++	}
++}
++
++/*-----------------------------------------------------------------*/
++/* Set up an inotify watch on /dev/input. */
++void open_inotify(void)
++{
++	int fd = -1;
++	int wd = -1;
++	struct connection c;
++
++	/* set up inotify */
++	fd = inotify_init();
++	
++	if (fd < 0) {
++		acpid_log(LOG_ERR, "inotify_init() failed: %s (%d)\n",
++			strerror(errno), errno);
++		return;
++	}
++	
++	if (acpid_debug)
++		fprintf(stderr, "%s: inotify fd: %d\n", progname, fd);
++
++	/* watch for new files being created in /dev/input */
++	wd = inotify_add_watch(fd, ACPID_INPUTLAYERDIR, IN_CREATE);
++
++	if (wd < 0) {
++		acpid_log(LOG_ERR, "inotify_add_watch() failed: %s (%d)\n",
++			strerror(errno), errno);
++		close(fd);			
++		return;
++	}
++
++	if (acpid_debug)
++		fprintf(stderr, "%s: inotify wd: %d\n", progname, wd);
++
++	/* add a connection to the list */
++	c.fd = fd;
++	c.process = process_inotify;
++	add_connection(&c);
++}
++
+--- acpid.old/inotify_handler.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/inotify_handler.h	2009-11-17 14:44:45.000000000 +0100
+@@ -0,0 +1,31 @@
++/*
++ *  inotify_handler.h - inotify Handler for New Devices
++ *
++ *  Watches /dev/input for new input layer device files.
++ *
++ *  Copyright (C) 2009, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++#ifndef INOTIFY_HANDLER_H__
++#define INOTIFY_HANDLER_H__
++
++/* Set up an inotify watch on /dev/input. */
++extern void open_inotify(void);
++
++#endif /* INOTIFY_HANDLER_H__ */
+--- acpid.old/input_layer.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/input_layer.c	2009-11-17 14:44:45.000000000 +0100
+@@ -0,0 +1,344 @@
++/*
++ *  input_layer - Kernel ACPI Event Input Layer Interface
++ *
++ *  Handles the details of getting kernel ACPI events from the input
++ *  layer (/dev/input/event*).
++ *
++ *  Inspired by (and in some cases blatantly lifted from) Vojtech Pavlik's
++ *  evtest.c.
++ *
++ *  Copyright (C) 2008-2009, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++/* system */
++#include <unistd.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <fcntl.h>
++#include <linux/input.h>
++#include <string.h>
++#include <errno.h>
++#include <malloc.h>
++#include <glob.h>
++
++/* local */
++#include "acpid.h"
++#include "connection_list.h"
++#include "event.h"
++
++#define DIM(a)  (sizeof(a) / sizeof(a[0]))
++
++struct evtab_entry {
++	struct input_event event;
++	const char *str;
++};
++
++/* Event Table: Events we are interested in and their strings.  Use 
++   evtest.c, acpi_genl, or kacpimon to find new events to add to this
++   table. */
++static struct evtab_entry evtab[] = {
++	{{{0,0}, EV_KEY, KEY_POWER, 1}, "button/power PBTN 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_SUSPEND, 1}, 
++ 		"button/suspend SUSP 00000080 00000000"},
++	{{{0,0}, EV_SW, SW_LID, 1}, "button/lid LID close"},
++	{{{0,0}, EV_SW, SW_LID, 0}, "button/lid LID open"},
++	/* blue access IBM button on Thinkpad T42p*/
++	{{{0,0}, EV_KEY, KEY_PROG1, 1}, "button/prog1 PROG1 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_VENDOR, 1}, "button/vendor VNDR 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F1, 1}, "button/fnf1 FNF1 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F2, 1}, "button/fnf2 FNF2 00000080 00000000"},
++	/* Fn-F2 produces KEY_BATTERY on Thinkpad T42p */
++	{{{0,0}, EV_KEY, KEY_BATTERY, 1}, 
++ 		"button/battery BAT 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_SCREENLOCK, 1}, 
++ 		"button/screenlock SCRNLCK 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_COFFEE, 1}, "button/coffee CFEE 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_SLEEP, 1}, "button/sleep SBTN 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_WLAN, 1}, "button/wlan WLAN 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F6, 1}, "button/fnf6 FNF6 00000080 00000000"},
++	/* procfs on Thinkpad 600X reports "video VID0 00000080 00000000" */
++	/* typical events file has "video.* 00000080" */
++	{{{0,0}, EV_KEY, KEY_SWITCHVIDEOMODE, 1}, 
++		"video/switchmode VMOD 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F9, 1}, "button/fnf9 FNF9 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F10, 1}, "button/fnf10 FF10 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_FN_F11, 1}, "button/fnf11 FF11 00000080 00000000"},
++	/* Fn-F9 produces KEY_F24 on Thinkpad T42p */
++	{{{0,0}, EV_KEY, KEY_F24, 1}, "button/f24 F24 00000080 00000000"},
++
++#if 0
++	/* These "EV_MSC, 4, x" events cause trouble.  They are triggered */
++	/* by unexpected keys on the keyboard.  */
++	/* The 4 is MSC_SCAN, so these are actually scan code events.  */
++
++	/* EV_MSC, MSC_SCAN, KEY_MINUS  This is triggered by the minus key. */
++	{{{0,0}, EV_MSC, 4, 12}, "button/fnbs FNBS 00000080 00000000"},
++
++	/* EV_MSC, MSC_SCAN, KEY_EQUAL  Triggered by the equals key. */
++	{{{0,0}, EV_MSC, 4, 13}, "button/fnins FNINS 00000080 00000000"},
++
++	/* EV_MSC, MSC_SCAN, KEY_BACKSPACE   Triggered by the backspace key. */
++	{{{0,0}, EV_MSC, 4, 14}, "button/fndel FNDEL 00000080 00000000"},
++
++	/* EV_MSC, MSC_SCAN, KEY_E   Triggered by the 'E' key. */
++	{{{0,0}, EV_MSC, 4, 18}, "button/fnpgdown FNPGDOWN 00000080 00000000"},
++#endif
++
++	{{{0,0}, EV_KEY, KEY_ZOOM, 1}, "button/zoom ZOOM 00000080 00000000"},
++	/* typical events file has "video.* 00000087" */
++	{{{0,0}, EV_KEY, KEY_BRIGHTNESSDOWN, 1}, 
++ 		"video/brightnessdown BRTDN 00000087 00000000"},
++ 	/* typical events file has "video.* 00000086" */
++	{{{0,0}, EV_KEY, KEY_BRIGHTNESSUP, 1}, 
++ 		"video/brightnessup BRTUP 00000086 00000000"},
++	{{{0,0}, EV_KEY, KEY_KBDILLUMTOGGLE, 1}, 
++ 		"button/kbdillumtoggle KBILLUM 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_VOLUMEDOWN, 1}, 
++ 		"button/volumedown VOLDN 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_VOLUMEUP, 1}, 
++ 		"button/volumeup VOLUP 00000080 00000000"},
++	{{{0,0}, EV_KEY, KEY_MUTE, 1}, 
++ 		"button/mute MUTE 00000080 00000000"},
++ 	/* additional events divined from the kernel's video.c */
++	{{{0,0}, EV_KEY, KEY_VIDEO_NEXT, 1}, 
++ 		"video/next NEXT 00000083 00000000"},
++	{{{0,0}, EV_KEY, KEY_VIDEO_PREV, 1}, 
++ 		"video/prev PREV 00000084 00000000"},
++	{{{0,0}, EV_KEY, KEY_BRIGHTNESS_CYCLE, 1}, 
++ 		"video/brightnesscycle BCYC 00000085 00000000"},
++	{{{0,0}, EV_KEY, KEY_BRIGHTNESS_ZERO, 1}, 
++ 		"video/brightnesszero BZRO 00000088 00000000"},
++	{{{0,0}, EV_KEY, KEY_DISPLAY_OFF, 1}, 
++ 		"video/displayoff DOFF 00000089 00000000"}
++};
++
++/*----------------------------------------------------------------------*/
++/* Given an input event, returns the string corresponding to that event.
++   If there is no corresponding string, NULL is returned.  */
++static const char *
++event_string(struct input_event event)
++{
++	unsigned i;
++	
++	/* for each entry in the event table */
++	for (i = 0; i < DIM(evtab); ++i)
++	{
++		/* if this is a matching event, return its string */
++		if (event.type == evtab[i].event.type  &&
++			event.code == evtab[i].event.code  &&
++			event.value == evtab[i].event.value) {
++			return evtab[i].str;
++		}
++	}
++	
++	return NULL;
++}
++
++/*-----------------------------------------------------------------*/
++/* returns non-zero if the event type/code is one we need */
++static int 
++need_event(int type, int code)
++{
++	unsigned i;
++
++	/* for each entry in the event table */
++	for (i = 0; i < DIM(evtab); ++i) {
++		/* if we found a matching event */
++		if (type == evtab[i].event.type  &&
++			code == evtab[i].event.code) {
++			return 1;
++		}
++	}
++
++	return 0;
++}
++
++/*-----------------------------------------------------------------*/
++/* called when an input layer event is received */
++void process_input(int fd)
++{
++	struct input_event event;
++	ssize_t nbytes;
++	const char *str;
++	static int nerrs;
++
++	nbytes = read(fd, &event, sizeof(event));
++
++	if (nbytes == 0) {
++		acpid_log(LOG_WARNING, "input layer connection closed\n");
++		exit(EXIT_FAILURE);
++	}
++	
++	if (nbytes < 0) {
++		/* if it's a signal, bail */
++		if (errno == EINTR)
++			return;
++		if (errno == ENODEV) {
++			acpid_log(LOG_WARNING, "input device has been disconnected\n");
++			delete_connection(fd);
++			return;
++		}
++		acpid_log(LOG_ERR, "input layer read error: %s (%d)\n",
++			strerror(errno), errno);
++		if (++nerrs >= ACPID_MAX_ERRS) {
++			acpid_log(LOG_ERR,
++				"too many errors reading "
++				"input layer - aborting\n");
++			exit(EXIT_FAILURE);
++		}
++		return;
++	}
++
++	/* ??? Is it possible for a partial message to come across? */
++	/*   If so, we've got more code to write... */
++	
++	if (nbytes != sizeof(event)) {
++		acpid_log(LOG_WARNING, "input layer unexpected length: "
++			"%d   expected: %d\n", nbytes, sizeof(event));
++		return;
++	}
++
++	/* convert the event into a string */
++	str = event_string(event);
++	/* if this is not an event we care about, bail */
++	if (str == NULL)
++		return;
++	
++	/* if we're locked, don't process the event */
++	if (locked()) {
++		if (logevents) {
++			acpid_log(LOG_INFO,
++				"lockfile present, not processing "
++				"input layer event \"%s\"\n", str);
++		}
++		return;
++	}
++
++	if (logevents)
++		acpid_log(LOG_INFO,
++			"received input layer event \"%s\"\n", str);
++	
++	/* send the event off to the handler */
++	acpid_handle_event(str);
++
++	if (logevents)
++		acpid_log(LOG_INFO,
++			"completed input layer event \"%s\"\n", str);
++}
++
++#define BITS_PER_LONG (sizeof(long) * 8)
++#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
++#define OFF(x)  ((x)%BITS_PER_LONG)
++#define LONG(x) ((x)/BITS_PER_LONG)
++#define test_bit(bit, array)	((array[LONG(bit)] >> OFF(bit)) & 1)
++
++/*--------------------------------------------------------------------*/
++/* returns non-zero if the file descriptor supports one of the events */
++/* supported by event_string().  */
++static int 
++has_event(int fd)
++{
++	int type, code;
++	unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
++
++	memset(bit, 0, sizeof(bit));
++	/* get the event type bitmap */
++	ioctl(fd, EVIOCGBIT(0, sizeof(bit[0])), bit[0]);
++
++	/* for each event type */
++	for (type = 0; type < EV_MAX; type++) {
++		/* if this event type is supported */
++		if (test_bit(type, bit[0])) {
++			/* skip sync */
++			if (type == EV_SYN) continue;
++			/* get the event code mask */
++			ioctl(fd, EVIOCGBIT(type, sizeof(bit[type])), bit[type]);
++			/* for each event code */
++			for (code = 0; code < KEY_MAX; code++) {
++				/* if this event code is supported */
++				if (test_bit(code, bit[type])) {
++					/* if we need this event */
++					if (need_event(type, code) != 0)
++						return 1;
++				}
++			}
++		}
++	}
++	return 0;
++}
++
++/*-----------------------------------------------------------------*
++ * open a single input layer file for input  */
++int open_inputfile(const char *filename)
++{
++	int fd;
++	struct connection c;
++
++	fd = open(filename, O_RDONLY | O_NONBLOCK);
++
++	if (fd >= 0) {
++		/* if this file doesn't have events we need, indicate failure */
++		if (!has_event(fd)) {
++			close(fd);
++			return -1;
++		}
++
++		if (acpid_debug)
++			fprintf(stderr, "%s: input layer %s "
++				"opened successfully\n", progname, filename);
++
++		/* add a connection to the list */
++		c.fd = fd;
++		c.process = process_input;
++		add_connection(&c);
++
++		return 0;  /* success */
++	}
++	
++	/* open unsuccessful */
++	return -1;
++}
++
++/*-----------------------------------------------------------------*
++ * open each of the appropriate /dev/input/event* files for input  */
++void open_input(void)
++{
++	char *filename = NULL;
++	glob_t globbuf;
++	unsigned i;
++	int success = 0;
++
++	/* get all the matching event filenames */
++	glob(ACPID_INPUTLAYERFILES, 0, NULL, &globbuf);
++
++	/* for each event file */
++	for (i = 0; i < globbuf.gl_pathc; ++i) {
++		filename = globbuf.gl_pathv[i];
++
++		/* open this input layer device file */
++		if (open_inputfile(filename) == 0)
++			success = 1;
++	}
++
++	if (!success)
++		fprintf(stderr, "%s: cannot open input layer\n", progname);
++
++	globfree(&globbuf);
++}
++
+--- acpid.old/input_layer.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/input_layer.h	2009-11-17 14:44:45.000000000 +0100
+@@ -0,0 +1,35 @@
++/*
++ *  input_layer.h - Kernel ACPI Event Input Layer Interface
++ *
++ *  Handles the details of getting kernel ACPI events from the input
++ *  layer (/dev/input/event*).
++ *
++ *  Copyright (C) 2008, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++#ifndef INPUT_LAYER_H__
++#define INPUT_LAYER_H__
++
++/* Open each of the appropriate /dev/input/event* files for input. */
++extern void open_input(void);
++
++/* Open a single input layer device file for input. */
++extern int open_inputfile(const char *filename);
++
++#endif /* INPUT_LAYER_H__ */
+--- acpid.old/libnetlink.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/libnetlink.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,593 @@
++/*
++ * libnetlink.c	RTnetlink service routines.
++ *
++ *		This program is free software; you can redistribute it and/or
++ *		modify it under the terms of the GNU General Public License
++ *		as published by the Free Software Foundation; either version
++ *		2 of the License, or (at your option) any later version.
++ *
++ * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
++ *
++ * Modified by Ted Felix (www.tedfelix.com) to fix warnings.
++ *
++ */
++
++#include <stdio.h>
++#include <stdlib.h>
++#include <unistd.h>
++#include <syslog.h>
++#include <fcntl.h>
++#include <net/if_arp.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <string.h>
++#include <errno.h>
++#include <time.h>
++#include <sys/uio.h>
++
++#include "libnetlink.h"
++
++void rtnl_close(struct rtnl_handle *rth)
++{
++	if (rth->fd >= 0) {
++		close(rth->fd);
++		rth->fd = -1;
++	}
++}
++
++int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
++		      int protocol)
++{
++	socklen_t addr_len;
++	int sndbuf = 32768;
++	int rcvbuf = 32768;
++
++	memset(rth, 0, sizeof(rth));
++
++	rth->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
++	if (rth->fd < 0) {
++		perror("Cannot open netlink socket");
++		return -1;
++	}
++
++	if (setsockopt(rth->fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
++		perror("SO_SNDBUF");
++		return -1;
++	}
++
++	if (setsockopt(rth->fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)) < 0) {
++		perror("SO_RCVBUF");
++		return -1;
++	}
++
++	memset(&rth->local, 0, sizeof(rth->local));
++	rth->local.nl_family = AF_NETLINK;
++	rth->local.nl_groups = subscriptions;
++
++	if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
++		perror("Cannot bind netlink socket");
++		return -1;
++	}
++	addr_len = sizeof(rth->local);
++	if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
++		perror("Cannot getsockname");
++		return -1;
++	}
++	if (addr_len != sizeof(rth->local)) {
++		fprintf(stderr, "Wrong address length %d\n", addr_len);
++		return -1;
++	}
++	if (rth->local.nl_family != AF_NETLINK) {
++		fprintf(stderr, "Wrong address family %d\n", rth->local.nl_family);
++		return -1;
++	}
++	rth->seq = time(NULL);
++	return 0;
++}
++
++int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
++{
++	return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
++}
++
++int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
++{
++	struct {
++		struct nlmsghdr nlh;
++		struct rtgenmsg g;
++	} req;
++	struct sockaddr_nl nladdr;
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++
++	memset(&req, 0, sizeof(req));
++	req.nlh.nlmsg_len = sizeof(req);
++	req.nlh.nlmsg_type = type;
++	req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
++	req.nlh.nlmsg_pid = 0;
++	req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
++	req.g.rtgen_family = family;
++
++	return sendto(rth->fd, (void*)&req, sizeof(req), 0,
++		      (struct sockaddr*)&nladdr, sizeof(nladdr));
++}
++
++int rtnl_send(struct rtnl_handle *rth, const char *buf, int len)
++{
++	struct sockaddr_nl nladdr;
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++
++	return sendto(rth->fd, buf, len, 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
++}
++
++int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
++{
++	struct nlmsghdr nlh;
++	struct sockaddr_nl nladdr;
++	struct iovec iov[2] = {
++		{ .iov_base = &nlh, .iov_len = sizeof(nlh) },
++		{ .iov_base = req, .iov_len = len }
++	};
++	struct msghdr msg = {
++		.msg_name = &nladdr,
++		.msg_namelen = 	sizeof(nladdr),
++		.msg_iov = iov,
++		.msg_iovlen = 2,
++	};
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++
++	nlh.nlmsg_len = NLMSG_LENGTH(len);
++	nlh.nlmsg_type = type;
++	nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
++	nlh.nlmsg_pid = 0;
++	nlh.nlmsg_seq = rth->dump = ++rth->seq;
++
++	return sendmsg(rth->fd, &msg, 0);
++}
++
++int rtnl_dump_filter(struct rtnl_handle *rth,
++		     rtnl_filter_t filter,
++		     void *arg1,
++		     rtnl_filter_t junk,
++		     void *arg2)
++{
++	struct sockaddr_nl nladdr;
++	struct iovec iov;
++	struct msghdr msg = {
++		.msg_name = &nladdr,
++		.msg_namelen = sizeof(nladdr),
++		.msg_iov = &iov,
++		.msg_iovlen = 1,
++	};
++	char buf[16384];
++
++	iov.iov_base = buf;
++	while (1) {
++		int status;
++		struct nlmsghdr *h;
++
++		iov.iov_len = sizeof(buf);
++		status = recvmsg(rth->fd, &msg, 0);
++
++		if (status < 0) {
++			if (errno == EINTR)
++				continue;
++			perror("OVERRUN");
++			continue;
++		}
++
++		if (status == 0) {
++			fprintf(stderr, "EOF on netlink\n");
++			return -1;
++		}
++
++		h = (struct nlmsghdr*)buf;
++		while (NLMSG_OK(h, (unsigned)status)) {
++			int err;
++
++			if (nladdr.nl_pid != 0 ||
++			    h->nlmsg_pid != rth->local.nl_pid ||
++			    h->nlmsg_seq != rth->dump) {
++				if (junk) {
++					err = junk(&nladdr, h, arg2);
++					if (err < 0)
++						return err;
++				}
++				goto skip_it;
++			}
++
++			if (h->nlmsg_type == NLMSG_DONE)
++				return 0;
++			if (h->nlmsg_type == NLMSG_ERROR) {
++				struct nlmsgerr *msgerr = (struct nlmsgerr*)NLMSG_DATA(h);
++				if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
++					fprintf(stderr, "ERROR truncated\n");
++				} else {
++					errno = -msgerr->error;
++					perror("RTNETLINK answers");
++				}
++				return -1;
++			}
++			err = filter(&nladdr, h, arg1);
++			if (err < 0)
++				return err;
++
++skip_it:
++			h = NLMSG_NEXT(h, status);
++		}
++		if (msg.msg_flags & MSG_TRUNC) {
++			fprintf(stderr, "Message truncated\n");
++			continue;
++		}
++		if (status) {
++			fprintf(stderr, "!!!Remnant of size %d\n", status);
++			exit(1);
++		}
++	}
++}
++
++int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
++	      unsigned groups, struct nlmsghdr *answer,
++	      rtnl_filter_t junk,
++	      void *jarg)
++{
++	int status;
++	unsigned seq;
++	struct nlmsghdr *h;
++	struct sockaddr_nl nladdr;
++	struct iovec iov = {
++		.iov_base = (void*) n,
++		.iov_len = n->nlmsg_len
++	};
++	struct msghdr msg = {
++		.msg_name = &nladdr,
++		.msg_namelen = sizeof(nladdr),
++		.msg_iov = &iov,
++		.msg_iovlen = 1,
++	};
++	char   buf[16384];
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++	nladdr.nl_pid = peer;
++	nladdr.nl_groups = groups;
++
++	n->nlmsg_seq = seq = ++rtnl->seq;
++
++	if (answer == NULL)
++		n->nlmsg_flags |= NLM_F_ACK;
++
++	status = sendmsg(rtnl->fd, &msg, 0);
++
++	if (status < 0) {
++		perror("Cannot talk to rtnetlink");
++		return -1;
++	}
++
++	memset(buf,0,sizeof(buf));
++
++	iov.iov_base = buf;
++
++	while (1) {
++		iov.iov_len = sizeof(buf);
++		status = recvmsg(rtnl->fd, &msg, 0);
++
++		if (status < 0) {
++			if (errno == EINTR)
++				continue;
++			perror("OVERRUN");
++			continue;
++		}
++		if (status == 0) {
++			fprintf(stderr, "EOF on netlink\n");
++			return -1;
++		}
++		if (msg.msg_namelen != sizeof(nladdr)) {
++			fprintf(stderr, "sender address length == %d\n", msg.msg_namelen);
++			exit(1);
++		}
++		for (h = (struct nlmsghdr*)buf; (unsigned)status >= sizeof(*h); ) {
++			int err;
++			int len = h->nlmsg_len;
++			int l = len - sizeof(*h);
++
++			if (l<0 || len>status) {
++				if (msg.msg_flags & MSG_TRUNC) {
++					fprintf(stderr, "Truncated message\n");
++					return -1;
++				}
++				fprintf(stderr, "!!!malformed message: len=%d\n", len);
++				exit(1);
++			}
++
++			if (nladdr.nl_pid != (unsigned)peer ||
++			    h->nlmsg_pid != rtnl->local.nl_pid ||
++			    h->nlmsg_seq != seq) {
++				if (junk) {
++					err = junk(&nladdr, h, jarg);
++					if (err < 0)
++						return err;
++				}
++				/* Don't forget to skip that message. */
++				status -= NLMSG_ALIGN(len);
++				h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
++				continue;
++			}
++
++			if (h->nlmsg_type == NLMSG_ERROR) {
++				struct nlmsgerr *msgerr = (struct nlmsgerr*)NLMSG_DATA(h);
++				if ((unsigned)l < sizeof(struct nlmsgerr)) {
++					fprintf(stderr, "ERROR truncated\n");
++				} else {
++					errno = -msgerr->error;
++					if (errno == 0) {
++						if (answer)
++							memcpy(answer, h, h->nlmsg_len);
++						return 0;
++					}
++					perror("RTNETLINK1 answers");
++				}
++				return -1;
++			}
++			if (answer) {
++				memcpy(answer, h, h->nlmsg_len);
++				return 0;
++			}
++
++			fprintf(stderr, "Unexpected reply!!!\n");
++
++			status -= NLMSG_ALIGN(len);
++			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
++		}
++		if (msg.msg_flags & MSG_TRUNC) {
++			fprintf(stderr, "Message truncated\n");
++			continue;
++		}
++		if (status) {
++			fprintf(stderr, "!!!Remnant of size %d\n", status);
++			exit(1);
++		}
++	}
++}
++
++int rtnl_listen(struct rtnl_handle *rtnl,
++		rtnl_filter_t handler,
++		void *jarg)
++{
++	int status;
++	struct nlmsghdr *h;
++	struct sockaddr_nl nladdr;
++	struct iovec iov;
++	struct msghdr msg = {
++		.msg_name = &nladdr,
++		.msg_namelen = sizeof(nladdr),
++		.msg_iov = &iov,
++		.msg_iovlen = 1,
++	};
++	char   buf[8192];
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++	nladdr.nl_pid = 0;
++	nladdr.nl_groups = 0;
++
++	iov.iov_base = buf;
++	while (1) {
++		iov.iov_len = sizeof(buf);
++		status = recvmsg(rtnl->fd, &msg, 0);
++
++		if (status < 0) {
++			if (errno == EINTR)
++				continue;
++			perror("OVERRUN");
++			continue;
++		}
++		if (status == 0) {
++			fprintf(stderr, "EOF on netlink\n");
++			return -1;
++		}
++		if (msg.msg_namelen != sizeof(nladdr)) {
++			fprintf(stderr, "Sender address length == %d\n", msg.msg_namelen);
++			exit(1);
++		}
++		for (h = (struct nlmsghdr*)buf; (unsigned)status >= sizeof(*h); ) {
++			int err;
++			int len = h->nlmsg_len;
++			int l = len - sizeof(*h);
++
++			if (l<0 || len>status) {
++				if (msg.msg_flags & MSG_TRUNC) {
++					fprintf(stderr, "Truncated message\n");
++					return -1;
++				}
++				fprintf(stderr, "!!!malformed message: len=%d\n", len);
++				exit(1);
++			}
++
++			err = handler(&nladdr, h, jarg);
++			if (err < 0)
++				return err;
++
++			status -= NLMSG_ALIGN(len);
++			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
++		}
++		if (msg.msg_flags & MSG_TRUNC) {
++			fprintf(stderr, "Message truncated\n");
++			continue;
++		}
++		if (status) {
++			fprintf(stderr, "!!!Remnant of size %d\n", status);
++			exit(1);
++		}
++	}
++}
++
++int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler,
++		   void *jarg)
++{
++	int status;
++	struct sockaddr_nl nladdr;
++	char   buf[8192];
++	struct nlmsghdr *h = (void*)buf;
++
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++	nladdr.nl_pid = 0;
++	nladdr.nl_groups = 0;
++
++	while (1) {
++		int err, len, type;
++		int l;
++
++		status = fread(&buf, 1, sizeof(*h), rtnl);
++
++		if (status < 0) {
++			if (errno == EINTR)
++				continue;
++			perror("rtnl_from_file: fread");
++			return -1;
++		}
++		if (status == 0)
++			return 0;
++
++		len = h->nlmsg_len;
++		type= h->nlmsg_type;
++		l = len - sizeof(*h);
++
++		if (l<0 || (unsigned)len>sizeof(buf)) {
++			fprintf(stderr, "!!!malformed message: len=%d @%lu\n",
++				len, ftell(rtnl));
++			return -1;
++		}
++
++		status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
++
++		if (status < 0) {
++			perror("rtnl_from_file: fread");
++			return -1;
++		}
++		if (status < l) {
++			fprintf(stderr, "rtnl-from_file: truncated message\n");
++			return -1;
++		}
++
++		err = handler(&nladdr, h, jarg);
++		if (err < 0)
++			return err;
++	}
++}
++
++int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
++{
++	int len = RTA_LENGTH(4);
++	struct rtattr *rta;
++	if ((int)NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
++		fprintf(stderr,"addattr32: Error! max allowed bound %d exceeded\n",maxlen);
++		return -1;
++	}
++	rta = NLMSG_TAIL(n);
++	rta->rta_type = type;
++	rta->rta_len = len;
++	memcpy(RTA_DATA(rta), &data, 4);
++	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
++	return 0;
++}
++
++int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
++	      int alen)
++{
++	int len = RTA_LENGTH(alen);
++	struct rtattr *rta;
++
++	if ((int)NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
++		fprintf(stderr, "addattr_l ERROR: message exceeded bound of %d\n",maxlen);
++		return -1;
++	}
++	rta = NLMSG_TAIL(n);
++	rta->rta_type = type;
++	rta->rta_len = len;
++	memcpy(RTA_DATA(rta), data, alen);
++	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
++	return 0;
++}
++
++int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
++{
++	if ((int)NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) {
++		fprintf(stderr, "addraw_l ERROR: message exceeded bound of %d\n",maxlen);
++		return -1;
++	}
++
++	memcpy(NLMSG_TAIL(n), data, len);
++	memset((void *) NLMSG_TAIL(n) + len, 0, NLMSG_ALIGN(len) - len);
++	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len);
++	return 0;
++}
++
++int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
++{
++	int len = RTA_LENGTH(4);
++	struct rtattr *subrta;
++
++	if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
++		fprintf(stderr,"rta_addattr32: Error! max allowed bound %d exceeded\n",maxlen);
++		return -1;
++	}
++	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
++	subrta->rta_type = type;
++	subrta->rta_len = len;
++	memcpy(RTA_DATA(subrta), &data, 4);
++	rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
++	return 0;
++}
++
++int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
++		  const void *data, int alen)
++{
++	struct rtattr *subrta;
++	int len = RTA_LENGTH(alen);
++
++	if (RTA_ALIGN(rta->rta_len) + RTA_ALIGN(len) > maxlen) {
++		fprintf(stderr,"rta_addattr_l: Error! max allowed bound %d exceeded\n",maxlen);
++		return -1;
++	}
++	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
++	subrta->rta_type = type;
++	subrta->rta_len = len;
++	memcpy(RTA_DATA(subrta), data, alen);
++	rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
++	return 0;
++}
++
++int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
++{
++	memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
++	while (RTA_OK(rta, len)) {
++		if (rta->rta_type <= max)
++			tb[rta->rta_type] = rta;
++		rta = RTA_NEXT(rta,len);
++	}
++	if (len)
++		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
++	return 0;
++}
++
++int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len)
++{
++	int i = 0;
++
++	memset(tb, 0, sizeof(struct rtattr *) * max);
++	while (RTA_OK(rta, len)) {
++		if (rta->rta_type <= max && i < max)
++			tb[i++] = rta;
++		rta = RTA_NEXT(rta,len);
++	}
++	if (len)
++		fprintf(stderr, "!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
++	return i;
++}
+--- acpid.old/libnetlink.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/libnetlink.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,91 @@
++#ifndef __LIBNETLINK_H__
++#define __LIBNETLINK_H__ 1
++
++#include <asm/types.h>
++// needed by netlink.h, should be in there
++#include <arpa/inet.h>
++#include <linux/netlink.h>
++#include <linux/rtnetlink.h>
++
++struct rtnl_handle
++{
++	int			fd;
++	struct sockaddr_nl	local;
++	struct sockaddr_nl	peer;
++	__u32			seq;
++	__u32			dump;
++};
++
++extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
++extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol);
++extern void rtnl_close(struct rtnl_handle *rth);
++extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
++extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
++
++typedef int (*rtnl_filter_t)(const struct sockaddr_nl *,
++			     struct nlmsghdr *n, void *);
++extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
++			    void *arg1,
++			    rtnl_filter_t junk,
++			    void *arg2);
++extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
++		     unsigned groups, struct nlmsghdr *answer,
++		     rtnl_filter_t junk,
++		     void *jarg);
++extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int);
++
++
++extern int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data);
++extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen);
++extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len);
++extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
++extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen);
++
++extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
++extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
++
++#define parse_rtattr_nested(tb, max, rta) \
++	(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
++
++extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler,
++		       void *jarg);
++extern int rtnl_from_file(FILE *, rtnl_filter_t handler,
++		       void *jarg);
++
++#define NLMSG_TAIL(nmsg) \
++	((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
++
++#ifndef IFA_RTA
++#define IFA_RTA(r) \
++	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
++#endif
++#ifndef IFA_PAYLOAD
++#define IFA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
++#endif
++
++#ifndef IFLA_RTA
++#define IFLA_RTA(r) \
++	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
++#endif
++#ifndef IFLA_PAYLOAD
++#define IFLA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
++#endif
++
++#ifndef NDA_RTA
++#define NDA_RTA(r) \
++	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
++#endif
++#ifndef NDA_PAYLOAD
++#define NDA_PAYLOAD(n)	NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
++#endif
++
++#ifndef NDTA_RTA
++#define NDTA_RTA(r) \
++	((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg))))
++#endif
++#ifndef NDTA_PAYLOAD
++#define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
++#endif
++
++#endif /* __LIBNETLINK_H__ */
++
+--- acpid.old/Makefile	2009-11-17 14:36:21.000000000 +0100
++++ acpid/Makefile	2009-11-17 14:44:45.000000000 +0100
+@@ -12,7 +12,8 @@
+ BIN_PROGS = acpi_listen
+ PROGS = $(SBIN_PROGS) $(BIN_PROGS)
+ 
+-acpid_SRCS = acpid.c event.c ud_socket.c
++acpid_SRCS = acpid.c acpi_ids.c connection_list.c event.c input_layer.c \
++    inotify_handler.c libnetlink.c netlink.c proc.c sock.c ud_socket.c
+ acpid_OBJS = $(acpid_SRCS:.c=.o)
+ 
+ acpi_listen_SRCS = acpi_listen.c ud_socket.c
+@@ -23,7 +24,8 @@
+ MAN8 = acpid.8 acpi_listen.8
+ MAN8GZ = $(MAN8:.8=.8.gz)
+ 
+-CFLAGS = -W -Wall -Werror -Wundef -Wshadow -D_GNU_SOURCE -O2 -g $(DEFS)
++CFLAGS = -W -Wall -Werror -Wundef -Wshadow -D_GNU_SOURCE -O2 \
++	-fno-strict-aliasing -g $(DEFS)
+ DEFS = -DVERSION="\"$(VERSION)\""
+ 
+ all: $(PROGS)
+--- acpid.old/netlink.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/netlink.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,239 @@
++/*
++ *  netlink.c - Kernel ACPI Event Netlink Interface
++ *
++ *  Handles the details of getting kernel ACPI events from netlink.
++ *
++ *  Inspired by (and in some cases blatantly lifted from) Zhang Rui's
++ *  acpi_genl and Alexey Kuznetsov's libnetlink.  Thanks also to Yi Yang
++ *  at intel.
++ *
++ *  Copyright (C) 2008, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++/* system */
++#include <unistd.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <errno.h>
++
++/* local */
++#include "acpid.h"
++#include "event.h"
++
++#include "libnetlink.h"
++#include "genetlink.h"
++#include "acpi_genetlink.h"
++
++#include "acpi_ids.h"
++#include "connection_list.h"
++
++static void
++format_netlink(struct nlmsghdr *msg)
++{
++	struct rtattr *tb[ACPI_GENL_ATTR_MAX + 1];
++	struct genlmsghdr *ghdr = NLMSG_DATA(msg);
++	int len;
++	struct rtattr *attrs;
++	
++	len = msg->nlmsg_len;
++	
++	/* if this message doesn't have the proper family ID, drop it */
++	if (msg->nlmsg_type != acpi_ids_getfamily()) {
++		if (logevents) {
++			acpid_log(LOG_INFO, "wrong netlink family ID.\n");
++		}
++		return;
++	}
++
++	len -= NLMSG_LENGTH(GENL_HDRLEN);
++
++	if (len < 0) {
++		acpid_log(LOG_WARNING,
++			"wrong netlink controller message len: %d\n", len);
++		return;
++	}
++
++	attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN);
++	/* parse the attributes in this message */
++	parse_rtattr(tb, ACPI_GENL_ATTR_MAX, attrs, len);
++
++	/* if there's an ACPI event attribute... */
++	if (tb[ACPI_GENL_ATTR_EVENT]) {
++		/* get the actual event struct */
++		struct acpi_genl_event *event =
++				RTA_DATA(tb[ACPI_GENL_ATTR_EVENT]);
++		char buf[64];
++
++		/* format it */
++		snprintf(buf, sizeof(buf), "%s %s %08x %08x",
++			event->device_class, event->bus_id, event->type, event->data);
++
++		/* if we're locked, don't process the event */
++		if (locked()) {
++			if (logevents) {
++				acpid_log(LOG_INFO,
++					"lockfile present, not processing "
++					"netlink event \"%s\"\n", buf);
++			}
++			return;
++		}
++
++		if (logevents)
++			acpid_log(LOG_INFO,
++				"received netlink event \"%s\"\n", buf);
++
++		/* send the event off to the handler */
++		acpid_handle_event(buf);
++
++		if (logevents)
++			acpid_log(LOG_INFO,
++				"completed netlink event \"%s\"\n", buf);
++	}
++}
++
++/* (based on rtnl_listen() in libnetlink.c) */
++void
++process_netlink(int fd)
++{
++	int status;
++	struct nlmsghdr *h;
++	/* the address for recvmsg() */
++	struct sockaddr_nl nladdr;
++	/* the io vector for recvmsg() */
++	struct iovec iov;
++	/* recvmsg() parameters */
++	struct msghdr msg = {
++		.msg_name = &nladdr,
++		.msg_namelen = sizeof(nladdr),
++		.msg_iov = &iov,
++		.msg_iovlen = 1,
++	};
++	/* buffer for the incoming data */
++	char buf[8192];
++	static int nerrs;
++
++	/* set up the netlink address */
++	memset(&nladdr, 0, sizeof(nladdr));
++	nladdr.nl_family = AF_NETLINK;
++	nladdr.nl_pid = 0;
++	nladdr.nl_groups = 0;
++
++	/* set up the I/O vector */
++	iov.iov_base = buf;
++	iov.iov_len = sizeof(buf);
++	
++	/* read the data into the buffer */
++	status = recvmsg(fd, &msg, 0);
++
++	/* if there was a problem, print a message and keep trying */
++	if (status < 0) {
++		/* if we were interrupted by a signal, bail */
++		if (errno == EINTR)
++			return;
++		
++		acpid_log(LOG_ERR, "netlink read error: %s (%d)\n",
++			strerror(errno), errno);
++		if (++nerrs >= ACPID_MAX_ERRS) {
++			acpid_log(LOG_ERR,
++				"too many errors reading via "
++				"netlink - aborting\n");
++			exit(EXIT_FAILURE);
++		}
++		return;
++	}
++	/* if an orderly shutdown has occurred, we're done */
++	if (status == 0) {
++		acpid_log(LOG_WARNING, "netlink connection closed\n");
++		exit(EXIT_FAILURE);
++	}
++	/* check to see if the address length has changed */
++	if (msg.msg_namelen != sizeof(nladdr)) {
++		acpid_log(LOG_WARNING, "netlink unexpected length: "
++			"%d   expected: %d\n", msg.msg_namelen, sizeof(nladdr));
++		return;
++	}
++	
++	/* for each message received */
++	for (h = (struct nlmsghdr*)buf; (unsigned)status >= sizeof(*h); ) {
++		int len = h->nlmsg_len;
++		int l = len - sizeof(*h);
++
++		if (l < 0  ||  len > status) {
++			if (msg.msg_flags & MSG_TRUNC) {
++				acpid_log(LOG_WARNING, "netlink msg truncated (1)\n");
++				return;
++			}
++			acpid_log(LOG_WARNING,
++				"malformed netlink msg, length %d\n", len);
++			return;
++		}
++
++		/* format the message */
++		format_netlink(h);
++
++		status -= NLMSG_ALIGN(len);
++		h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
++	}
++	if (msg.msg_flags & MSG_TRUNC) {
++		acpid_log(LOG_WARNING, "netlink msg truncated (2)\n");
++		return;
++	}
++	if (status) {
++		acpid_log(LOG_WARNING, "netlink remnant of size %d\n", status);
++		return;
++	}
++
++	return;
++}
++
++/* convert the netlink multicast group number into a bit map */
++/* (e.g. 4 => 16, 5 => 32) */
++static __u32
++nl_mgrp(__u32 group)
++{
++	if (group > 31) {
++		fprintf(stderr, "%s: unexpected group number %d\n",
++			progname, group);
++		return 0;
++	}
++	return group ? (1 << (group - 1)) : 0;
++}
++
++void open_netlink(void)
++{
++	struct rtnl_handle rth;
++	struct connection c;
++
++	/* open the appropriate netlink socket for input */
++	if (rtnl_open_byproto(
++		&rth, nl_mgrp(acpi_ids_getgroup()), NETLINK_GENERIC) < 0) {
++		fprintf(stderr, "%s: cannot open generic netlink socket\n",
++			progname);
++		return;
++	}
++
++	if (acpid_debug)
++		fprintf(stderr, "%s: netlink opened successfully\n", progname);
++
++	/* add a connection to the list */
++	c.fd = rth.fd;
++	c.process = process_netlink;
++	add_connection(&c);
++}
+--- acpid.old/netlink.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/netlink.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,31 @@
++/*
++ *  netlink.h - Kernel ACPI Event Netlink Interface
++ *
++ *  Handles the details of getting kernel ACPI events from netlink.
++ *
++ *  Copyright (C) 2008, Ted Felix (www.tedfelix.com)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ *
++ *  (tabs at 4)
++ */
++
++#ifndef NETLINK_H__
++#define NETLINK_H__
++
++/* open the netlink connection */
++extern void open_netlink(void);
++
++#endif /* NETLINK_H__ */
+--- acpid.old/proc.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/proc.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,207 @@
++/*
++ *  proc.c - ACPI daemon proc filesystem interface
++ *
++ *  Portions Copyright (C) 2000 Andrew Henroid
++ *  Portions Copyright (C) 2001 Sun Microsystems
++ *  Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#include <unistd.h>
++#include <fcntl.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <errno.h>
++
++#include "acpid.h"
++#include "event.h"
++#include "connection_list.h"
++
++const char *eventfile = ACPID_EVENTFILE;
++
++static char *read_line(int fd);
++
++static void
++process_proc(int fd)
++{
++	char *event;
++
++	/* read an event */
++	event = read_line(fd);
++
++	/* if we're locked, don't process the event */
++	if (locked()) {
++		if (logevents  &&  event != NULL) {
++			acpid_log(LOG_INFO,
++				"lockfile present, not processing "
++				"event \"%s\"\n", event);
++		}
++		return;
++	}
++
++	/* handle the event */
++	if (event) {
++		if (logevents) {
++			acpid_log(LOG_INFO,
++			          "procfs received event \"%s\"\n", event);
++		}
++		acpid_handle_event(event);
++		if (logevents) {
++			acpid_log(LOG_INFO,
++				"procfs completed event \"%s\"\n", event);
++		}
++	} else if (errno == EPIPE) {
++		acpid_log(LOG_WARNING,
++			"events file connection closed\n");
++		exit(EXIT_FAILURE);
++	} else {
++		static int nerrs;
++		if (++nerrs >= ACPID_MAX_ERRS) {
++			acpid_log(LOG_ERR,
++				"too many errors reading "
++				"events file - aborting\n");
++			exit(EXIT_FAILURE);
++		}
++	}
++}
++
++int
++open_proc()
++{
++	int fd;
++	struct connection c;
++	
++	fd = open(eventfile, O_RDONLY);
++	if (fd < 0) {
++	    if (acpid_debug)
++		fprintf(stderr, "%s: can't open %s: %s\n", progname, 
++			eventfile, strerror(errno));
++		return -1;
++	}
++	fcntl(fd, F_SETFD, FD_CLOEXEC);
++
++	if (acpid_debug)
++		fprintf(stderr, "%s: proc fs opened successfully\n", progname);
++
++	/* add a connection to the list */
++	c.fd = fd;
++	c.process = process_proc;
++	add_connection(&c);
++
++	return 0;
++}
++
++/*
++ * This depends on fixes in linux ACPI after 2.4.8
++ */
++#define BUFLEN 1024
++static char *
++read_line(int fd)
++{
++	static char buf[BUFLEN];
++	int i = 0;
++	int r;
++	int searching = 1;
++
++	while (searching) {
++		memset(buf+i, 0, BUFLEN-i);
++
++		/* only go to BUFLEN-1 so there will always be a 0 at the end */
++		while (i < BUFLEN-1) {
++			r = read(fd, buf+i, 1);
++			if (r < 0 && errno != EINTR) {
++				/* we should do something with the data */
++				acpid_log(LOG_ERR, "read(): %s\n",
++					strerror(errno));
++				return NULL;
++			} else if (r == 0) {
++				/* signal this in an almost standard way */
++				errno = EPIPE;
++				return NULL;
++			} else if (r == 1) {
++				/* scan for a newline */
++				if (buf[i] == '\n') {
++					searching = 0;
++					buf[i] = '\0';
++					break;
++				}
++				i++;
++			}
++		}
++		if (i >= BUFLEN - 1)
++			break;
++	}
++
++	return buf;
++}
++
++#if 0
++/* This version leaks memory.  The above version is simpler and leak-free. */
++/* Downside is that the above version always uses 1k of RAM. */
++/*
++ * This depends on fixes in linux ACPI after 2.4.8
++ */
++#define MAX_BUFLEN	1024
++static char *
++read_line(int fd)
++{
++	static char *buf;
++	int buflen = 64;
++	int i = 0;
++	int r;
++	int searching = 1;
++
++	while (searching) {
++		/* ??? This memory is leaked since it is never freed */
++		buf = realloc(buf, buflen);
++		if (!buf) {
++			acpid_log(LOG_ERR, "malloc(%d): %s\n",
++				buflen, strerror(errno));
++			return NULL;
++		}
++		memset(buf+i, 0, buflen-i);
++
++		while (i < buflen) {
++			r = read(fd, buf+i, 1);
++			if (r < 0 && errno != EINTR) {
++				/* we should do something with the data */
++				acpid_log(LOG_ERR, "read(): %s\n",
++					strerror(errno));
++				return NULL;
++			} else if (r == 0) {
++				/* signal this in an almost standard way */
++				errno = EPIPE;
++				return NULL;
++			} else if (r == 1) {
++				/* scan for a newline */
++				if (buf[i] == '\n') {
++					searching = 0;
++					buf[i] = '\0';
++					break;
++				}
++				i++;
++			}
++		}
++		if (buflen >= MAX_BUFLEN) {
++			break;
++		} 
++		buflen *= 2;
++	}
++
++	return buf;
++}
++#endif
+--- acpid.old/proc.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/proc.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,30 @@
++/*
++ *  proc.h - ACPI daemon proc filesystem interface
++ *
++ *  Portions Copyright (C) 2000 Andrew Henroid
++ *  Portions Copyright (C) 2001 Sun Microsystems
++ *  Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#ifndef PROC_H__
++#define PROC_H__
++
++extern const char *eventfile;
++
++extern int open_proc();
++
++#endif /* PROC_H__ */
+--- acpid.old/README-NETLINK	1970-01-01 01:00:00.000000000 +0100
++++ acpid/README-NETLINK	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,12 @@
++acpid for netlink
++
++This is Ted Felix's <http://www.tedfelix.com> branch of the acpid project 
++which includes support for netlink and the input layer.
++
++/proc/acpi/event is a deprecated kernel interface for ACPI events.  Newer
++kernels rely on netlink and the input layer to send ACPI-related events.
++This branch of acpid uses these new interfaces.
++
++Any comments or patches for this branch should be sent to Ted Felix:
++
++http://www.tedfelix.com
+--- acpid.old/sock.c	1970-01-01 01:00:00.000000000 +0100
++++ acpid/sock.c	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,119 @@
++/*
++ *  sock.c - ACPI daemon socket interface
++ *
++ *  Portions Copyright (C) 2000 Andrew Henroid
++ *  Portions Copyright (C) 2001 Sun Microsystems
++ *  Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#include <unistd.h>
++#include <fcntl.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <errno.h>
++#include <grp.h>
++
++#include "acpid.h"
++#include "event.h"
++#include "ud_socket.h"
++#include "connection_list.h"
++
++const char *socketfile = ACPID_SOCKETFILE;
++const char *socketgroup;
++mode_t socketmode = ACPID_SOCKETMODE;
++int clientmax = ACPID_CLIENTMAX;
++
++/* the number of non-root clients that are connected */
++int non_root_clients;
++
++static void
++process_sock(int fd)
++{
++	int cli_fd;
++	struct ucred creds;
++	char buf[32];
++	static int accept_errors;
++
++	/* accept and add to our lists */
++	cli_fd = ud_accept(fd, &creds);
++	if (cli_fd < 0) {
++		acpid_log(LOG_ERR, "can't accept client: %s\n",
++			  strerror(errno));
++		accept_errors++;
++		if (accept_errors >= 5) {
++			acpid_log(LOG_ERR, "giving up\n");
++			clean_exit_with_status(EXIT_FAILURE);
++		}
++		return;
++	}
++	accept_errors = 0;
++	/* This check against clientmax is from the non-netlink 1.0.10.  */
++	if (creds.uid != 0 && non_root_clients >= clientmax) {
++		close(cli_fd);
++		acpid_log(LOG_ERR,
++		    "too many non-root clients\n");
++		return;
++	}
++	if (creds.uid != 0) {
++		non_root_clients++;
++	}
++	fcntl(cli_fd, F_SETFD, FD_CLOEXEC);
++	snprintf(buf, sizeof(buf)-1, "%d[%d:%d]",
++		 creds.pid, creds.uid, creds.gid);
++	acpid_add_client(cli_fd, buf);
++}
++
++void
++open_sock()
++{
++	int fd;
++	struct connection c;
++
++	fd = ud_create_socket(socketfile);
++	if (fd < 0) {
++		fprintf(stderr, "%s: can't open socket %s: %s\n",
++			progname, socketfile, strerror(errno));
++		exit(EXIT_FAILURE);
++	}
++	fcntl(fd, F_SETFD, FD_CLOEXEC);
++	chmod(socketfile, socketmode);
++	if (socketgroup) {
++		struct group *gr;
++		struct stat buf;
++		gr = getgrnam(socketgroup);
++		if (!gr) {
++			fprintf(stderr, "%s: group %s does not exist\n",
++				progname, socketgroup);
++			exit(EXIT_FAILURE);
++		}
++		if (stat(socketfile, &buf) < 0) {
++			fprintf(stderr, "%s: can't stat %s\n",
++				progname, socketfile);
++			exit(EXIT_FAILURE);
++		}
++		if (chown(socketfile, buf.st_uid, gr->gr_gid) < 0) {
++			fprintf(stderr, "%s: chown(): %s\n",
++				progname, strerror(errno));
++			exit(EXIT_FAILURE);
++		}
++	}
++	
++	/* add a connection to the list */
++	c.fd = fd;
++	c.process = process_sock;
++	add_connection(&c);
++}
+--- acpid.old/sock.h	1970-01-01 01:00:00.000000000 +0100
++++ acpid/sock.h	2009-11-17 14:44:42.000000000 +0100
+@@ -0,0 +1,34 @@
++/*
++ *  sock.h - ACPI daemon socket interface
++ *
++ *  Portions Copyright (C) 2000 Andrew Henroid
++ *  Portions Copyright (C) 2001 Sun Microsystems
++ *  Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
++ *
++ *  This program is free software; you can redistribute it and/or modify
++ *  it under the terms of the GNU General Public License as published by
++ *  the Free Software Foundation; either version 2 of the License, or
++ *  (at your option) any later version.
++ *
++ *  This program is distributed in the hope that it will be useful,
++ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ *  GNU General Public License for more details.
++ *
++ *  You should have received a copy of the GNU General Public License
++ *  along with this program; if not, write to the Free Software
++ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
++ */
++
++#ifndef SOCK_H__
++#define SOCK_H__
++
++extern const char *socketfile;
++extern const char *socketgroup;
++extern mode_t socketmode;
++extern int clientmax;
++extern int non_root_clients;
++
++extern void open_sock();
++
++#endif /* SOCK_H__ */
+--- acpid.old/TESTPLAN	1970-01-01 01:00:00.000000000 +0100
++++ acpid/TESTPLAN	2009-11-17 14:44:45.000000000 +0100
+@@ -0,0 +1,82 @@
++acpid Test Plan
++
++Suggestions
++
++- Run all these tests with valgrind to detect memory leaks.
++- It's best to test without a window manager running (such as GNOME or KDE) as they tend to handle acpi events on their own and override acpid.  To bring down X on a system that is configured with a graphical login, there's usually an "init" script you can run.  As an example, with Debian/GNOME, log off of your X/GNOME session, switch to another tty (e.g. Alt-Ctrl-F1), login, and do this:
++  sudo /etc/init.d/gdm stop
++Now X is out of the way and you can test from the console.
++- You can kill acpid with "sudo killall acpid".
++- To make testing more convenient, you can run acpid from a shell as "acpid -ld" to get maximum logging.  Use Ctrl-C to stop acpid.
++
++Normal Paths
++
++* proc fs, all events
++Start acpid against /proc/acpi/event (if it exists).
++Test each of the following events:
++1. Power Button
++2. Laptop Lid Switch
++3. Sleep Button
++4. Laptop AC Adapter
++5. Laptop Battery
++
++* input layer/netlink, all events
++Start acpid against the input layer and netlink.
++Test each of the following events:
++1. Power Button (tests ACPI -> input layer)
++2. Laptop Lid Switch (tests ACPI -> input layer)
++3. Sleep Button (tests ACPI -> input layer)
++4. Laptop AC Adapter (tests ACPI -> netlink)
++5. Laptop Battery (tests ACPI -> netlink)
++6. Special Keyboard Key(s)
++
++* input layer/netlink fallback
++Start acpid with a bogus events file specified via the options.
++  acpid -e /proc/acpi/bogus
++Make sure a connection is made via the input layer and netlink.
++
++* lockfile procfs
++Start acpid against the proc fs
++Try some events and make sure they are coming through.
++Create the lockfile.
++Try some events and make sure they do not come through.
++Remove the lockfile.
++Try some events and make sure they are coming through.
++
++* lockfile netlink
++Start acpid against input layer and netlink.
++Try some events and make sure they are coming through.
++Create the lockfile.
++Try some events and make sure they do not come through.
++Remove the lockfile.
++Try some events and make sure they are coming through.
++
++* USB disconnect
++Start acpid (input layer and netlink) with a second USB keyboard attached.
++Try some events and make sure they are coming through.
++Disconnect the second USB keyboard.
++Make sure acpid is still running.
++Try some events and make sure they are coming through.
++
++* USB connect
++Start acpid against input layer and netlink.
++Try some events and make sure they are coming through.
++Connect a second USB keyboard.
++Check logging to see if acpid has found the new keyboard.
++Try some events from the second USB keyboard and make sure they are coming through.
++
++
++Debugging Paths
++
++* event logging
++Run acpid without the -l option and make sure no events are logged to syslog.
++Run acpid with the -l option and make sure events are logged to syslog.
++
++* debug mode
++Run acpid with the -d option and note that it runs in the foreground and provides debugging info to the console.
++acpid also supports up to 4 debug levels in the event handler.  Might want to try "-dddd" and see what happens.
++
++* foreground mode
++Run acpid with the -f option and note that it runs in the foreground.
++Run acpid without the -f option and note that it runs in the background.
++
--- acpid-1.0.10.orig/debian/examples/default.sh
+++ acpid-1.0.10/debian/examples/default.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Default acpi script that takes an entry for all actions
+
+set $*
+
+# Take care about the way events are reported
+ev_type=`echo "$1" | cut -d/ -f1`
+if [ "$ev_type" = "$1" ]; then
+	event="$2";
+else
+	event=`echo "$1" | cut -d/ -f2`
+fi
+
+
+case "$ev_type" in
+    button)
+        case "$event" in
+            power)
+                logger "acpid: received a shutdown request"
+                /sbin/init 0
+		break
+                ;;
+             *)
+                logger "acpid: action $2 is not defined"
+                ;;
+        esac
+    ;;
+
+    *)
+        logger "ACPI group $1 / action $2 is not defined"
+        ;;
+esac
--- acpid-1.0.10.orig/debian/examples/ac
+++ acpid-1.0.10/debian/examples/ac
@@ -0,0 +1,11 @@
+# /etc/acpid/events/ac
+# This detects changes to AC power status, and passes them to
+# /etc/acpi/ac.sh for further processing.
+
+# Optionally you can specify the placeholder %e. It will pass
+# through the whole kernel event message to the program you've
+# specified.
+
+event=ac_adapter
+action=/etc/acpi/ac.sh
+
--- acpid-1.0.10.orig/debian/examples/default
+++ acpid-1.0.10/debian/examples/default
@@ -0,0 +1,18 @@
+# This is the ACPID default configuration, it takes all
+# events and passes them to /etc/acpi/default.sh for further
+# processing.
+
+# event keeps a regular expression matching the event. To get
+# power events only, just use something like "event=button power.*"
+# to catch it.
+# action keeps the command to be executed after an event occurs
+# In case of the power event above, your entry may look this way:
+#event=button power.*
+#action=/sbin/init 0
+
+# Optionally you can specify the placeholder %e. It will pass
+# through the whole kernel event message to the program you've
+# specified.
+
+event=.*
+action=/etc/acpi/default.sh %e
--- acpid-1.0.10.orig/debian/examples/ac.sh
+++ acpid-1.0.10/debian/examples/ac.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# /etc/acpid/ac.sh
+# Detect loss of AC power and regaining of AC power, and take action
+# appropriatly.
+
+# On my laptop anyway, this script doesn't not get different parameters for
+# loss of power and regained power. So, I have to use a separate program to
+# tell what the adapter status is.
+
+# This uses the spicctrl program for probing the sonypi device.
+BACKLIGHT=$(spicctrl -B)
+
+if on_ac_power; then
+        # Now on AC power.
+
+        # Tell longrun to go crazy.
+        longrun -f performance
+        longrun -s 0 100
+
+        # Turn up the backlight unless it's up far enough.
+        if [ "$BACKLIGHT" -lt 108 ]; then
+                spicctrl -b 108
+        fi
+else
+        # Now off AC power.
+
+        # Tell longrun to be a miser.
+        longrun -f economy
+        longrun -s 0 50 # adjust to suite..
+
+        # Don't allow the screen to be too bright, but don't turn the
+        # backlight _up_ on removal, and don't turn it all the way down, as
+        # that is unusable on my laptop in most conditions. Adjust to
+        # taste.
+        if [ "$BACKLIGHT" -gt 68 ]; then
+                spicctrl -b 68
+        fi
+fi
+
