[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

acpid: new upstream version



Hi,

there is a new upstream version available that fixes some bugs in the source
code like unchecked errors. Here's a complete list:

- Define _GNU_SOURCE.
- Rename a variable to avoid shadowing a global.
- Fix typos in man pages.
- GCC 4.3.2 gives chdir() the _wur attribute (warn unused result). Check
    for errors.
- Check for ferror() in parse_file().
- Only read regular files in acpid_read_conf().
- Stop processing ACPI events when a lockfile exists. (already in our existing
  Debian package for 1.0.6)
- Build with -O2 flag
- Add -l (--logevents) option to enable logging of all events.  Due to a
    number of reports of log flooding (bad ACPI BIOS?) The new default is to
    NOT log events.
- Add pidfile support and a -p (--pidfile) option to change the pidfile.
    Default is /var/run/acpid.pid.
- Rename ACPI_* constants to ACPID_*.
- Remove a bad cast of malloc()'s return value. 
- Add proper make dependencies.
- Close client file descriptors on exec(). 
- Don't use a mode argument on open("/dev/null")
- Use GCC "__attribute__((format(printf)))" for acpid_log
- Fix a shadowed variable name 
- Fix a leaked fd on error
- Fix a signed/unsigned comparison
- Compile with more warnings

As you can see there only two "features", logevent and pidfile but quite some
fixes. So the question is shall we backport the bug fixes to 1.0.6 or do you
accept 1.0.8 for Lenny? The interdiff is attached, don't worry about the size,
most of it is documentation.

Michael

-- 
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!
diff -ruN acpid-1.0.6/acpid.8 acpid-1.0.8/acpid.8
--- acpid-1.0.6/acpid.8	2007-05-25 06:35:31.000000000 +0200
+++ acpid-1.0.8/acpid.8	2008-10-27 06:41:34.000000000 +0100
@@ -1,6 +1,6 @@
 .TH acpid 8 ""
 .\" Portions Copyright (c) 2001 Sun Microsystems
-.\" Portions Copyright (c) Tim Hockin (thockin@hockin.org.com)
+.\" Portions Copyright (c) Tim Hockin (thockin@hockin.org)
 .SH NAME
 acpid \- Advanced Configuration and Power Interface event daemon
 .SH SYNOPSIS
@@ -8,21 +8,24 @@
 
 .SH DESCRIPTION
 \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 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).
 .PP
 \fIRules\fP are defined by simple configuration files.  \fBacpid\fP
-will look in a configuration directory (\fI/etc/acpi/events\fP by default), 
-and parse all files that do not begin with a period ('.').  Each file must
-define two things: an \fIevent\fP and an \fIaction\fP.  Any blank lines, or
-lines where the first character is a pound sign ('#') are ignored.  Extraneous
-lines are flagged as warnings, but are not fatal.  Each line has three tokens:
-the key, a literal equal sign, and the value.  The key can be up to 63
-characters, and is case-insensitive (but whitespace matters).  The value can be
-up to 511 characters, and is case and whitespace sensitive.
+will look in a configuration directory (\fI/etc/acpi/events\fP by default),
+and parse all regular files that do not begin with a period ('.') or end
+with a tilde (~).  Each file must define two things: an \fIevent\fP and an
+\fIaction\fP.  Any blank lines, or lines where the first character is a
+pound sign ('#') are ignored.  Extraneous lines are flagged as warnings, but
+are not fatal.  Each line has three tokens: the key, a literal equal sign,
+and the value.  The key can be up to 63 characters, and is case-insensitive
+(but whitespace matters).  The value can be up to 511 characters, and is
+case and whitespace sensitive.
 .PP
 The event value is a regular expression (see regcomp(3)), against which events are matched.
 .PP
@@ -31,30 +34,30 @@
 include shell-special characters, and they will be preserved.  The only special
 characters in an action value are "%" escaped.  The string "%e" will be
 replaced by the literal text of the event for which the action was invoked.
-This string may contain spaces, so the commandline must take care to quote the "%e" if it wants a single token.  The string "%%" will be replaced by a 
-literal "%".  All other "%" escapes are reserved, and will cause a rule to 
+This string may contain spaces, so the commandline must take care to quote the "%e" if it wants a single token.  The string "%%" will be replaced by a
+literal "%".  All other "%" escapes are reserved, and will cause a rule to
 not load.
 .PP
 This feature allows multiple rules to be defined for the same event (though no
 ordering is guaranteed), as well as one rule to be defined for multiple events.
 To force \fBacpid\fP to reload the rule configuration, send it a SIGHUP.
 .PP
-In addition to rule files, \fBacpid\fP also accepts connections on a UNIX 
-domain socket (\fI/var/run/acpid.socket\fP by default).  Any application may 
-connect to this socket.  Once connected, \fBacpid\fP will send the text of 
+In addition to rule files, \fBacpid\fP also accepts connections on a UNIX
+domain socket (\fI/var/run/acpid.socket\fP by default).  Any application may
+connect to this socket.  Once connected, \fBacpid\fP will send the text of
 all ACPI events to the client.  The client has the responsibility of filtering
-for messages about which it cares.  \fBacpid\fP will not close the client 
+for messages about which it cares.  \fBacpid\fP will not close the client
 socket except in the case of a SIGHUP or \fBacpid\fP exiting.
 .PP
 .B acpid
-will log all of it's activities, as well as the stdout and stderr of any
-actions to syslog.
+will log all of its activities, as well as the stdout and stderr of any
+actions, to syslog.
 .PP
-All the default file and directories can be changed with commandline options.
+All the default files and directories can be changed with commandline options.
 .SH OPTIONS
 .TP 12
 .BI \-c "\fR, \fP" \--confdir " directory"
-This option changes the directory in which \fBacpid\fP looks for rule 
+This option changes the directory in which \fBacpid\fP looks for rule
 configuration files.  Default is \fI/etc/acpi/events\fP.
 .TP 12
 .BI \-d "\fR, \fP" \--debug
@@ -69,9 +72,15 @@
 .BI \-f "\fR, \fP" \--foreground
 This option keeps \fBacpid\fP in the foreground by not forking at startup.
 .TP
+.BI \-l "\fR, \fP" \--logevents
+This option tells \fBacpid\fP to log information about all events and actions.
+.TP
+.BI \-L "\fR, \fP" \--lockfile " filename"
+This option changes the lock file used to stop event processing.
+Default is \fI/var/lock/acpid\fP.
 .TP
 .BI \-g "\fR, \fP" \--socketgroup " groupname"
-This option changes the group ownership of the UNIX domain socket to which 
+This option changes the group ownership of the UNIX domain socket to which
 \fBacpid\fP publishes events.
 .TP
 .BI \-m "\fR, \fP" \--socketmode " mode"
@@ -83,9 +92,14 @@
 Default is \fI/var/run/acpid.socket\fP.
 .TP
 .BI \-S "\fR, \fP" \--nosocket " filename"
-This option tells \fBacpid\fP not to open a UNIX domain socket.  This 
+This option tells \fBacpid\fP not to open a UNIX domain socket.  This
 overrides the \fI-s\fP option, and negates all other socket options.
 .TP
+.BI \-p "\fR, \fP" \--pidfile " filename"
+This option tells \fBacpid\fP to use the specified file as its pidfile.  If
+the file exists, it will be removed and over-written.
+Default is \fI/var/run/acpid.pid\fP.
+.TP
 .BI \-v "\fR, \fP" \--version
 Print version information and exit.
 .TP
@@ -101,7 +115,7 @@
 action=/usr/local/sbin/power.sh "%e"
 .PP
 The script power.sh gets called and will see the complete event string
-as parameter $1. 
+as parameter $1.
 .SH DEPENDENCIES
 \fBacpid\fP should work on any linux kernel released since 2003.
 .SH FILES
@@ -112,6 +126,10 @@
 .br
 .B /var/run/acpid.socket
 .br
+.B /var/run/acpid.pid
+.br
+.B /var/lock/acpid
+.br
 .PD
 .SH BUGS
 There are no known bugs.  To file bug reports, see \fBAUTHORS\fP below.
diff -ruN acpid-1.0.6/acpid.c acpid-1.0.8/acpid.c
--- acpid-1.0.6/acpid.c	2007-05-25 06:19:23.000000000 +0200
+++ acpid-1.0.8/acpid.c	2008-10-27 07:07:25.000000000 +0100
@@ -42,6 +42,7 @@
 static void close_fds(void);
 static int daemonize(void);
 static int open_log(void);
+static int create_pidfile(void);
 static void clean_exit(int sig);
 static void reload_conf(int sig);
 static char *read_line(int fd);
@@ -49,14 +50,19 @@
 /* global debug level */
 int acpid_debug;
 
+/* do we log event info? */
+int logevents;
+
 static const char *progname;
-static const char *confdir = ACPI_CONFDIR;
-static const char *eventfile = ACPI_EVENTFILE;
-static const char *socketfile = ACPI_SOCKETFILE;
+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 = ACPI_SOCKETMODE;
+static mode_t socketmode = ACPID_SOCKETMODE;
 static int foreground;
+static const char *pidfile = ACPID_PIDFILE;
 
 int
 main(int argc, char **argv)
@@ -168,9 +174,18 @@
 	signal(SIGPIPE, SIG_IGN);
 
 	/* read in our configuration */
-	acpid_read_conf(confdir);
+	if (acpid_read_conf(confdir)) {
+		exit(EXIT_FAILURE);
+	}
+
+	/* create our pidfile */
+	if (create_pidfile() < 0) {
+		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;
@@ -193,7 +208,12 @@
 		/* 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,
@@ -202,21 +222,37 @@
 				continue;
 			}
 
-			/* read and handle an event */
+			/* read an event */
 			event = read_line(event_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;
+			}
+
+			/* handle the event */
 			if (event) {
-				acpid_log(LOG_INFO,
-				    "received event \"%s\"\n", event);
+				if (logevents) {
+					acpid_log(LOG_INFO,
+					    "received event \"%s\"\n", event);
+				}
 				acpid_handle_event(event);
-				acpid_log(LOG_INFO,
-				    "completed event \"%s\"\n", 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");
 				break;
 			} else {
 				static int nerrs;
-				if (++nerrs >= ACPI_MAX_ERRS) {
+				if (++nerrs >= ACPID_MAX_ERRS) {
 					acpid_log(LOG_ERR,
 					    "too many errors reading "
 					    "events file - aborting\n");
@@ -246,6 +282,7 @@
 				    strerror(errno));
 				continue;
 			}
+			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);
@@ -268,10 +305,13 @@
 		{"debug", 0, 0, 'd'},
 		{"eventfile", 1, 0, 'e'},
 		{"foreground", 0, 0, 'f'},
+		{"logevents", 0, 0, 'l'},
 		{"socketgroup", 1, 0, 'g'},
 		{"socketmode", 1, 0, 'm'},
 		{"socketfile", 1, 0, 's'},
 		{"nosocket", 1, 0, 'S'},
+		{"pidfile", 1, 0, 'p'},
+		{"lockfile", 1, 0, 'L'},
 		{"version", 0, 0, 'v'},
 		{"help", 0, 0, 'h'},
 		{NULL, 0, 0, 0},
@@ -281,10 +321,13 @@
 		"Increase debugging level (implies -f).",/* debug */
 		"Use the specified file for events.",	/* eventfile */
 		"Run in the foreground.",		/* foreground */
+		"Log all event activity.",		/* logevents */
 		"Set the group on the socket file.",	/* socketgroup */
 		"Set the permissions on the socket file.",/* socketmode */
 		"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 */
 		"Print version information.",		/* version */
 		"Print this message.",			/* help */
 	};
@@ -294,7 +337,8 @@
 
 	for (;;) {
 		int i;
-		i = getopt_long(*argc, *argv, "c:de:fg:m:s:Svh", opts, NULL);
+		i = getopt_long(*argc, *argv,
+		    "c:de:flg:m:s:Sp:L:vh", opts, NULL);
 		if (i == -1) {
 			break;
 		}
@@ -312,6 +356,9 @@
 		case 'f':
 			foreground = 1;
 			break;
+		case 'l':
+			logevents = 1;
+			break;
 		case 'g':
 			socketgroup = optarg;
 			break;
@@ -324,6 +371,12 @@
 		case 'S':
 			nosocket = 1;
 			break;
+		case 'p':
+			pidfile = optarg;
+			break;
+		case 'L':
+			lockfile = optarg;
+			break;
 		case 'v':
 			printf(PACKAGE "-" VERSION "\n");
 			exit(EXIT_SUCCESS);
@@ -387,7 +440,11 @@
 	umask(0);
 
 	/* get outta the way */
-	chdir("/");
+	if (chdir("/") < 0) {
+		fprintf(stderr, "%s: chdir(\"/\"): %s\n", progname,
+		        strerror(errno));
+		return -1;
+	}
 
 	return 0;
 }
@@ -399,7 +456,7 @@
 	int log_opts;
 
 	/* open /dev/null */
-	nullfd = open("/dev/null", O_RDONLY, 0640);
+	nullfd = open("/dev/null", O_RDONLY);
 	if (nullfd < 0) {
 		fprintf(stderr, "%s: can't open %s: %s\n", progname, 
 			"/dev/null", strerror(errno));
@@ -431,23 +488,57 @@
 	return 0;
 }
 
+static int
+create_pidfile(void)
+{
+	int fd;
+
+	/* JIC */
+	unlink(pidfile);
+
+	/* open the pidfile */
+	fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644);
+	if (fd >= 0) {
+		FILE *f;
+
+		/* write our pid to it */
+		f = fdopen(fd, "w");
+		if (f != NULL) {
+			fprintf(f, "%d\n", getpid());
+			fclose(f);
+			/* leave the fd open */
+			return 0;
+		}
+		close(fd);
+	}
+
+	/* something went wrong */
+	acpid_log(LOG_ERR, "can't create pidfile %s: %s\n",
+		    pidfile, strerror(errno));
+	return -1;
+}
+
 static void
-clean_exit(int sig)
+clean_exit(int sig __attribute__((unused)))
 {
 	acpid_cleanup_rules(1);
 	acpid_log(LOG_NOTICE, "exiting\n");
+	unlink(pidfile);
 	exit(EXIT_SUCCESS);
 }
 
 static void
-reload_conf(int sig)
+reload_conf(int sig __attribute__((unused)))
 {
 	acpid_log(LOG_NOTICE, "reloading configuration\n");
 	acpid_cleanup_rules(0);
 	acpid_read_conf(confdir);
 }
 
-int 
+int
+#ifdef __GNUC__
+__attribute__((format(printf, 2, 3)))
+#endif
 acpid_log(int level, const char *fmt, ...)
 {
 	va_list args;
diff -ruN acpid-1.0.6/acpid.h acpid-1.0.8/acpid.h
--- acpid-1.0.6/acpid.h	2007-05-24 08:33:33.000000000 +0200
+++ acpid-1.0.8/acpid.h	2008-10-27 06:52:07.000000000 +0100
@@ -30,11 +30,13 @@
 #include <sys/stat.h>
 
 #define ACPI_PROCDIR 		"/proc/acpi"
-#define ACPI_EVENTFILE		ACPI_PROCDIR "/event"
-#define ACPI_CONFDIR		"/etc/acpi/events"
-#define ACPI_SOCKETFILE		"/var/run/acpid.socket"
-#define ACPI_SOCKETMODE		0666
-#define ACPI_MAX_ERRS		5
+#define ACPID_EVENTFILE		ACPI_PROCDIR "/event"
+#define ACPID_CONFDIR		"/etc/acpi/events"
+#define ACPID_SOCKETFILE	"/var/run/acpid.socket"
+#define ACPID_SOCKETMODE	0666
+#define ACPID_PIDFILE		"/var/run/acpid.pid"
+#define ACPID_LOCKFILE		"/var/lock/acpid"
+#define ACPID_MAX_ERRS		5
 
 #define PACKAGE 		"acpid"
 
@@ -42,6 +44,7 @@
  * acpid.c
  */
 extern int acpid_debug;
+extern int logevents;
 extern int acpid_log(int level, const char *fmt, ...);
 
 /*
diff -ruN acpid-1.0.6/acpi_listen.8 acpid-1.0.8/acpi_listen.8
--- acpid-1.0.6/acpi_listen.8	2007-01-17 08:57:51.000000000 +0100
+++ acpid-1.0.8/acpi_listen.8	2008-10-27 05:57:28.000000000 +0100
@@ -1,4 +1,4 @@
-.TH acpi_listen 17 "Nov 2003"
+.TH acpi_listen 8 "Nov 2003"
 .\" Portions Copyright (c) 2003 Sun Microsystems
 .\" Copyright (c) 2004 Tim Hockin (thockin@hockin.org)
 .\" Some parts (C) 2003 - Gismo / Luca Capello <luca.pca.it> http://luca.pca.it
@@ -8,7 +8,7 @@
 \fBacpi_listen\fP [\fIoptions\fP]
 
 .SH DESCRIPTION
-\fBacpid\fP is the sysem-wide ACPI event catcher.  \fBacpi_listen\fP is a
+\fBacpid\fP is the system-wide ACPI event catcher.  \fBacpi_listen\fP is a
 simple shell-friendly tool which connects to acpid and listens for events.
 When an event occurs, acpi_listen will print it on stdout.
 
diff -ruN acpid-1.0.6/acpi_listen.c acpid-1.0.8/acpi_listen.c
--- acpid-1.0.6/acpi_listen.c	2007-01-17 08:57:51.000000000 +0100
+++ acpid-1.0.8/acpi_listen.c	2007-11-25 06:30:03.000000000 +0100
@@ -43,11 +43,11 @@
 static char *read_line(int fd);
 
 static const char *progname;
-static const char *socketfile = ACPI_SOCKETFILE;
+static const char *socketfile = ACPID_SOCKETFILE;
 static int max_events;
 
 static void
-time_expired(int signum)
+time_expired(int signum __attribute__((unused)))
 {
 	exit(EXIT_SUCCESS);
 }
@@ -94,7 +94,7 @@
 			break;
 		} else {
 			static int nerrs;
-			if (++nerrs >= ACPI_MAX_ERRS) {
+			if (++nerrs >= ACPID_MAX_ERRS) {
 				fprintf(stderr, "too many errors - aborting\n");
 				ret = 1;
 				break;
diff -ruN acpid-1.0.6/Changelog acpid-1.0.8/Changelog
--- acpid-1.0.6/Changelog	2007-06-30 21:17:22.000000000 +0200
+++ acpid-1.0.8/Changelog	2008-10-29 04:52:04.000000000 +0100
@@ -1,4 +1,47 @@
 %changelog
+* Tue Oct 28 2008  Tim Hockin <thockin@hockin.org>
+  - Bump version to 1.0.8 for release.
+
+* Sun Oct 26 2008  Tim Hockin <thockin@hockin.org>
+  - Define _GNU_SOURCE. (Makefile) (Ted Felix <http://www.tedfelix.com/>)
+  - Rename a variable to avoid shadowing a global. (event.c) (Ted Felix
+    <http://www.tedfelix.com/>)
+  - Fix typos in man pages. (acpid.8, acpi_listen.8) (Ted Felix
+    <http://www.tedfelix.com/>)
+  - GCC 4.3.2 gives chdir() the _wur attribute (warn unused result). Check
+    for errors. (acpid.c) (Ted Felix <http://www.tedfelix.com/>)
+  - Check for ferror() in parse_file(). (event.c) (Ted Felix
+    <http://www.tedfelix.com/>)
+  - Only read regular files in acpid_read_conf(). (event.c) (Ted Felix
+    <http://www.tedfelix.com/>)
+  - Stop processing ACPI events when a lockfile exists (from Debian).
+    (acpid.8, acpid.c, acpid.h) (Ted Felix <http://www.tedfelix.com/>)
+
+* Sat Nov 24 2007  Tim Hockin <thockin@hockin.org>
+  - Build with -O2 flag (Makefile).
+  - Add -l (--logevents) option to enable logging of all events.  Due to a
+    number of reports of log flooding (bad ACPI BIOS?) The new default is to
+    NOT log events. (acpid.c acpid.h event.h acpid.8)
+  - Add pidfile support and a -p (--pidfile) option to change the pidfile.
+    Default is /var/run/acpid.pid. (acpid.c acpid.8) (Javier Pello
+    <jpello@users.sourceforge.net>)
+  - Rename ACPI_* constants to ACPID_*. (acpid.c acpi_listen.c)
+  - Remove a bad cast of malloc()'s return value. (event.c)
+  - Add proper make dependencies. (Makefile)
+  - Close client file descriptors on exec(). (acpid.c) (Zdenek Prikryl
+    <zprikryl@redhat.com>)
+
+* Mon Sep 24 2007  Tim Hockin <thockin@hockin.org>
+  - Don't use a mode argument on open("/dev/null") (acpid.c) (Steve Grubb
+    <sgrubb@redhat.com>)
+  - Use GCC "__attribute__((format(printf)))" for acpid_log (acpid.c) (Steve
+    Grubb <sgrubb@redhat.com>)
+  - Fix a shadowed variable name (event.c) (Steve Grubb <sgrubb@redhat.com>)
+  - Fix a leaked fd on error (event.c) (Steve Grubb <sgrubb@redhat.com>)
+  - Fix a signed/unsigned comparison (event.c) (Steve Grubb
+    <sgrubb@redhat.com>)
+  - Compile with more warnings (Makefile) (Steve Grubb <sgrubb@redhat.com>)
+
 * Sat June 30 2007  Tim Hockin <thockin@hockin.org>
   - Bump version to 1.0.6 for release.
 
diff -ruN acpid-1.0.6/event.c acpid-1.0.8/event.c
--- acpid-1.0.6/event.c	2007-05-25 06:26:09.000000000 +0200
+++ acpid-1.0.8/event.c	2008-10-27 06:25:55.000000000 +0100
@@ -80,20 +80,6 @@
 static char *parse_cmd(const char *cmd, const char *event);
 static int check_escapes(const char *str);
 
-/* helper */
-static int
-path_is_dir(const char *path)
-{
-	struct stat s;
-
-	if (stat(path, &s)) {
-		acpid_log(LOG_ERR, "stat(\"%s\"): %s\n",
-		    path, strerror(errno));
-		return 0;
-	}
-	return S_ISDIR(s.st_mode);
-}
-
 /*
  * read in all the configuration files
  */
@@ -119,6 +105,7 @@
 	while ((dirent = readdir(dir))) {
 		int len;
 		struct rule *r;
+		struct stat stat_buf;
 
 		if (dirent->d_name[0] == '.')
 			continue; /* skip dotfiles */
@@ -131,7 +118,7 @@
 
 		len += strlen(confdir) + 2;
 
-		file = (char *)malloc(len);
+		file = malloc(len);
 		if (!file) {
 			acpid_log(LOG_ERR, "malloc(): %s\n", strerror(errno));
 			unlock_rules();
@@ -139,9 +126,17 @@
 		}
 		snprintf(file, len, "%s/%s", confdir, dirent->d_name);
 
-		if (path_is_dir(file)) {
+		/* allow only regular files and symlinks to files */
+		if (stat(file, &stat_buf) != 0) {
+			acpid_log(LOG_ERR, "stat(%s): %s\n", file,
+				strerror(errno));
+			free(file);
+			continue; /* keep trying the rest of the files */
+		}
+		if (!S_ISREG(stat_buf.st_mode)) {
+			acpid_log(LOG_DEBUG, "skipping non-file %s\n", file);
 			free(file);
-			continue; /* skip subdirs */
+			continue; /* skip non-regular files */
 		}
 
 		r = parse_file(file);
@@ -235,7 +230,7 @@
 	}
 
 	/* read each line */
-	while (!feof(fp)) {
+	while (!feof(fp) && !ferror(fp)) {
 		char *p = buf;
 		char key[64];
 		char val[512];
@@ -282,9 +277,9 @@
 			}
 			rv = regcomp(r->event, val, RULE_REGEX_FLAGS);
 			if (rv) {
-				char buf[128];
-				regerror(rv, r->event, buf, sizeof(buf));
-				acpid_log(LOG_ERR, "regcomp(): %s\n", buf);
+				char rbuf[128];
+				regerror(rv, r->event, rbuf, sizeof(rbuf));
+				acpid_log(LOG_ERR, "regcomp(): %s\n", rbuf);
 				free_rule(r);
 				fclose(fp);
 				return NULL;
@@ -318,6 +313,7 @@
 			    file);
 		}
 		free_rule(r);
+		fclose(fp);
 		return NULL;
 	}
 	fclose(fp);
@@ -476,7 +472,7 @@
 			struct rule *pnext = p->next;
 			if (!regexec(p->event, event, 0, NULL, 0)) {
 				/* a match! */
-				if (acpid_debug) {
+				if (acpid_debug && logevents) {
 					acpid_log(LOG_DEBUG,
 					    "rule from %s matched\n",
 					    p->origin);
@@ -492,7 +488,7 @@
 					    p->type);
 				}
 			} else {
-				if (acpid_debug >= 3) {
+				if (acpid_debug >= 3 && logevents) {
 					acpid_log(LOG_DEBUG,
 					    "rule from %s did not match\n",
 					    p->origin);
@@ -504,7 +500,7 @@
 
 	unlock_rules();
 
-	if (acpid_debug) {
+	if (acpid_debug && logevents) {
 		acpid_log(LOG_DEBUG, "%d total rule%s matched\n",
 			nrules, (nrules == 1)?"":"s");
 	}
@@ -516,15 +512,15 @@
 static sigset_t *
 signals_handled(void)
 {
-	static sigset_t sigset;
+	static sigset_t set;
 
-	sigemptyset(&sigset);
-	sigaddset(&sigset, SIGHUP);
-	sigaddset(&sigset, SIGTERM);
-	sigaddset(&sigset, SIGQUIT);
-	sigaddset(&sigset, SIGINT);
+	sigemptyset(&set);
+	sigaddset(&set, SIGHUP);
+	sigaddset(&set, SIGTERM);
+	sigaddset(&set, SIGQUIT);
+	sigaddset(&set, SIGINT);
 
-	return &sigset;
+	return &set;
 }
 
 static void
@@ -564,7 +560,10 @@
 	case 0: /* child */
 		/* parse the commandline, doing any substitutions needed */
 		action = parse_cmd(rule->action.cmd, event);
-		acpid_log(LOG_INFO, "executing action \"%s\"\n", action);
+		if (logevents) {
+			acpid_log(LOG_INFO,
+			    "executing action \"%s\"\n", action);
+		}
 
 		/* reset signals */
 		signal(SIGHUP, SIG_DFL);
@@ -574,8 +573,9 @@
 		signal(SIGPIPE, SIG_DFL);
 		sigprocmask(SIG_UNBLOCK, signals_handled(), NULL);
 
-		if (acpid_debug)
+		if (acpid_debug && logevents) {
 			fprintf(stdout, "BEGIN HANDLER MESSAGES\n");
+		}
 		execl("/bin/sh", "/bin/sh", "-c", action, NULL);
 		/* should not get here */
 		acpid_log(LOG_ERR, "execl(): %s\n", strerror(errno));
@@ -584,17 +584,21 @@
 
 	/* parent */
 	waitpid(pid, &status, 0);
-	if (acpid_debug)
+	if (acpid_debug && logevents) {
 		fprintf(stdout, "END HANDLER MESSAGES\n");
-	if (WIFEXITED(status)) {
-		acpid_log(LOG_INFO, "action exited with status %d\n",
-		    WEXITSTATUS(status));
-	} else if (WIFSIGNALED(status)) {
-		acpid_log(LOG_INFO, "action exited on signal %d\n",
-		    WTERMSIG(status));
-	} else {
-		acpid_log(LOG_INFO, "action exited with status %d\n",
-		    status);
+	}
+
+	if (logevents) {
+		if (WIFEXITED(status)) {
+			acpid_log(LOG_INFO, "action exited with status %d\n",
+			    WEXITSTATUS(status));
+		} else if (WIFSIGNALED(status)) {
+			acpid_log(LOG_INFO, "action exited on signal %d\n",
+			    WTERMSIG(status));
+		} else {
+			acpid_log(LOG_INFO, "action exited with status %d\n",
+			    status);
+		}
 	}
 
 	return 0;
@@ -606,12 +610,15 @@
 	int r;
 	int client = rule->action.fd;
 
-	acpid_log(LOG_INFO, "notifying client %s\n", rule->origin);
+	if (logevents) {
+		acpid_log(LOG_INFO, "notifying client %s\n", rule->origin);
+	}
 
 	r = safe_write(client, event, strlen(event));
 	if (r < 0 && errno == EPIPE) {
 		/* closed */
-		acpid_log(LOG_NOTICE, "client has disconnected\n");
+		acpid_log(LOG_NOTICE,
+		    "client %s has disconnected\n", rule->origin);
 		delist_rule(&client_list, rule);
 		close(rule->action.fd);
 		free_rule(rule);
@@ -660,7 +667,7 @@
 parse_cmd(const char *cmd, const char *event)
 {
 	static char buf[4096];
-	int i;
+	size_t i;
 	const char *p;
 
 	p = cmd;
@@ -672,7 +679,7 @@
 			p++;
 			if (*p == 'e') {
 				/* handle an event expansion */
-				int size = sizeof(buf) - i;
+				size_t size = sizeof(buf) - i;
 				size = snprintf(buf+i, size, "%s", event);
 				i += size;
 				p++;
diff -ruN acpid-1.0.6/Makefile acpid-1.0.8/Makefile
--- acpid-1.0.6/Makefile	2007-06-30 21:15:45.000000000 +0200
+++ acpid-1.0.8/Makefile	2008-10-29 04:48:52.000000000 +0100
@@ -1,7 +1,7 @@
 # Makefile for ACPI daemon
 
 # update these numbers for new releases
-VERSION = 1.0.6
+VERSION = 1.0.8
 
 INSTPREFIX =
 BINDIR = $(INSTPREFIX)/usr/bin
@@ -18,10 +18,12 @@
 acpi_listen_SRCS = acpi_listen.c ud_socket.c
 acpi_listen_OBJS = $(acpi_listen_SRCS:.c=.o)
 
+all_SRCS = $(acpid_SRCS) $(acpi_listen_SRCS)
+
 MAN8 = acpid.8 acpi_listen.8
 MAN8GZ = $(MAN8:.8=.8.gz)
 
-CFLAGS = -Wall -Werror -g $(DEFS)
+CFLAGS = -W -Wall -Werror -Wundef -Wshadow -D_GNU_SOURCE -O2 -g $(DEFS)
 DEFS = -DVERSION="\"$(VERSION)\""
 
 all: $(PROGS)
@@ -52,5 +54,32 @@
 	rm -rf $(DISTTMP)/acpid-$(VERSION)
 
 clean:
-	$(RM) $(PROGS) $(MAN8GZ) *.o
+	$(RM) $(PROGS) $(MAN8GZ) *.o .depend
 
+dep depend:
+	@$(RM) .depend
+	@$(MAKE) .depend
+
+.depend: $(all_SRCS)
+	@for f in $^; do \
+		OBJ=$$(echo $$f | sed 's/\.cp*$$/.o/'); \
+		$(CPP) $(PP_INCLUDES) -MM $$f -MT $$OBJ; \
+	done > $@
+
+# NOTE: 'sinclude' is "silent-include".  This suppresses a warning if
+# .depend does not exist.  Since Makefile includes this file, and this
+# file includes .depend, .depend is itself "a makefile" and Makefile is
+# dependent on it.  Any makefile for which there is a rule (as above for
+# .depend) will be evaluated before anything else.  If the rule executes
+# and the makefile is updated, make will reload the original Makefile and
+# start over.
+#
+# This means that the .depend rule will always be checked first.  If
+# .depend gets rebuilt, then the dependencies we have already sincluded
+# must have been stale.  Make starts over, the old dependencies are
+# tossed, and the new dependencies are sincluded.
+#
+# So why use 'sinclude' instead of 'include'?  We want to ALWAYS make
+# Makefile depend on .depend, even if .depend doesn't exist yet.  But we
+# don't want that pesky warning.
+sinclude .depend
diff -ruN acpid-1.0.6/README acpid-1.0.8/README
--- acpid-1.0.6/README	2007-01-17 08:57:51.000000000 +0100
+++ acpid-1.0.8/README	2008-10-29 04:14:49.000000000 +0100
@@ -3,8 +3,6 @@
 *                                                         *
 *  Daemon for Advanced Configuration and Power Interface  *
 *  Tim Hockin                                             *
-*      <sunthockin@users.sourceforge.net> or              *
-*      <thockin@users.sourceforge.net> or                 *
 *      <thockin@hockin.org>                               *
 *                                                         *
 ***********************************************************

Reply to: