Files
sablink-distro/sys-power/acpid/files/acpid-1.0.6-updates.patch
T
lxnay 645a69be20 acpid: forking and adding some patches
git-svn-id: http://svn.sabayonlinux.org/overlay@2366 d7aec97c-591d-0410-af39-a8856400b30a
2008-06-13 15:26:05 +00:00

363 lines
12 KiB
Diff

diff -Nurp acpid-1.0.6.orig/acpid.8 acpid-1.0.6/acpid.8
--- acpid-1.0.6.orig/acpid.8 2007-05-25 06:35:31.000000000 +0200
+++ acpid-1.0.6/acpid.8 2008-06-13 16:20:36.000000000 +0200
@@ -16,7 +16,10 @@ and execute the rules that match the eve
.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
+and parse all files that fit to a runparts style naming convention. This means
+that files containing a dot and contain characters different from a-z and 0-9
+would be ignored. Debian implementation differs at this point from standard
+acpid. 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:
@@ -47,7 +50,7 @@ for messages about which it cares. \fBa
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
+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.
diff -Nurp acpid-1.0.6.orig/acpid.c acpid-1.0.6/acpid.c
--- acpid-1.0.6.orig/acpid.c 2007-05-25 06:19:23.000000000 +0200
+++ acpid-1.0.6/acpid.c 2008-06-13 16:20:36.000000000 +0200
@@ -53,6 +53,7 @@ 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 *lockfile = ACPI_LOCKFILE;
static int nosocket;
static const char *socketgroup;
static mode_t socketmode = ACPI_SOCKETMODE;
@@ -193,6 +194,11 @@ main(int argc, char **argv)
/* was it an event? */
if (ar[0].revents) {
char *event;
+ struct stat trash;
+ int fexists;
+
+ /* Check for the existence of a lockfile */
+ fexists = stat(lockfile, &trash);
/* this shouldn't happen */
if (!ar[0].revents & POLLIN) {
@@ -204,6 +210,15 @@ main(int argc, char **argv)
/* read and handle an event */
event = read_line(event_fd);
+
+ /* we're locked, don't process the event */
+ if (fexists == 0) {
+ acpid_log(LOG_INFO,
+ "Lock file present, not processing event\n");
+ continue;
+ }
+
+
if (event) {
acpid_log(LOG_INFO,
"received event \"%s\"\n", event);
@@ -274,6 +289,7 @@ handle_cmdline(int *argc, char ***argv)
{"nosocket", 1, 0, 'S'},
{"version", 0, 0, 'v'},
{"help", 0, 0, 'h'},
+ {"lockfile", 1, 0, 'L'},
{NULL, 0, 0, 0},
};
const char *opts_help[] = {
@@ -287,6 +303,7 @@ handle_cmdline(int *argc, char ***argv)
"Do not listen on a UNIX socket (overrides -s).",/* nosocket */
"Print version information.", /* version */
"Print this message.", /* help */
+ "Use the specified file to lock the daemon.", /* lockfile */
};
struct option *opt;
const char **hlp;
@@ -294,7 +311,7 @@ handle_cmdline(int *argc, char ***argv)
for (;;) {
int i;
- i = getopt_long(*argc, *argv, "c:de:fg:m:s:Svh", opts, NULL);
+ i = getopt_long(*argc, *argv, "c:de:fg:m:s:SvhL:", opts, NULL);
if (i == -1) {
break;
}
@@ -327,6 +344,9 @@ handle_cmdline(int *argc, char ***argv)
case 'v':
printf(PACKAGE "-" VERSION "\n");
exit(EXIT_SUCCESS);
+ case 'L':
+ lockfile = optarg;
+ break;
case 'h':
default:
fprintf(stderr, "Usage: %s [OPTIONS]\n", progname);
@@ -412,6 +432,11 @@ open_log(void)
}
openlog(PACKAGE, log_opts, LOG_DAEMON);
+ /* Debian: restrict logging to >= NOTICE; #447200 */
+ if (!acpid_debug) {
+ setlogmask(LOG_UPTO(LOG_NOTICE));
+ }
+
/* set up stdin, stdout, stderr to /dev/null */
if (dup2(nullfd, STDIN_FILENO) != STDIN_FILENO) {
fprintf(stderr, "%s: dup2: %s\n", progname, strerror(errno));
diff -Nurp acpid-1.0.6.orig/acpid.h acpid-1.0.6/acpid.h
--- acpid-1.0.6.orig/acpid.h 2007-05-24 08:33:33.000000000 +0200
+++ acpid-1.0.6/acpid.h 2008-06-13 16:20:36.000000000 +0200
@@ -35,6 +35,7 @@
#define ACPI_SOCKETFILE "/var/run/acpid.socket"
#define ACPI_SOCKETMODE 0666
#define ACPI_MAX_ERRS 5
+#define ACPI_LOCKFILE "/var/lock/acpid"
#define PACKAGE "acpid"
diff -Nurp acpid-1.0.6.orig/acpi_listen.8 acpid-1.0.6/acpi_listen.8
--- acpid-1.0.6.orig/acpi_listen.8 2007-01-17 08:57:51.000000000 +0100
+++ acpid-1.0.6/acpi_listen.8 2008-06-13 16:20:36.000000000 +0200
@@ -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 @@ acpi_listen \- ACPI event listener
\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 -Nurp acpid-1.0.6.orig/event.c acpid-1.0.6/event.c
--- acpid-1.0.6.orig/event.c 2007-05-25 06:26:09.000000000 +0200
+++ acpid-1.0.6/event.c 2008-06-13 16:20:36.000000000 +0200
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <libgen.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
@@ -80,20 +81,6 @@ static int safe_write(int fd, const char
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
*/
@@ -104,6 +91,8 @@ acpid_read_conf(const char *confdir)
struct dirent *dirent;
char *file = NULL;
int nrules = 0;
+ char *basen = NULL;
+ regex_t preg;
lock_rules();
@@ -119,6 +108,7 @@ acpid_read_conf(const char *confdir)
while ((dirent = readdir(dir))) {
int len;
struct rule *r;
+ struct stat stat_buf;
if (dirent->d_name[0] == '.')
continue; /* skip dotfiles */
@@ -139,15 +129,31 @@ acpid_read_conf(const char *confdir)
}
snprintf(file, len, "%s/%s", confdir, dirent->d_name);
- if (path_is_dir(file)) {
+ /* allow only regular files and symlinks to these */
+ if (stat(file, &stat_buf) != 0) {
+ acpid_log(LOG_ERR, "stat(%s): %s\n", file, strerror(errno));
+ unlock_rules();
+ return -1;
+ }
+ if (!S_ISREG(stat_buf.st_mode)) {
+ acpid_log(LOG_DEBUG, "skipping non-file %s\n", file);
free(file);
continue; /* skip subdirs */
}
- 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);
}
@@ -235,7 +241,7 @@ parse_file(const char *file)
}
/* read each line */
- while (!feof(fp)) {
+ while (!feof(fp) && !ferror(fp)) {
char *p = buf;
char key[64];
char val[512];
diff -Nurp acpid-1.0.6.orig/examples/ac acpid-1.0.6/examples/ac
--- acpid-1.0.6.orig/examples/ac 1970-01-01 01:00:00.000000000 +0100
+++ acpid-1.0.6/examples/ac 2008-06-13 16:20:36.000000000 +0200
@@ -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
+
diff -Nurp acpid-1.0.6.orig/examples/ac.sh acpid-1.0.6/examples/ac.sh
--- acpid-1.0.6.orig/examples/ac.sh 1970-01-01 01:00:00.000000000 +0100
+++ acpid-1.0.6/examples/ac.sh 2008-06-13 16:20:36.000000000 +0200
@@ -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
+
diff -Nurp acpid-1.0.6.orig/examples/default acpid-1.0.6/examples/default
--- acpid-1.0.6.orig/examples/default 1970-01-01 01:00:00.000000000 +0100
+++ acpid-1.0.6/examples/default 2008-06-13 16:20:36.000000000 +0200
@@ -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
diff -Nurp acpid-1.0.6.orig/examples/default.sh acpid-1.0.6/examples/default.sh
--- acpid-1.0.6.orig/examples/default.sh 1970-01-01 01:00:00.000000000 +0100
+++ acpid-1.0.6/examples/default.sh 2008-06-13 16:20:36.000000000 +0200
@@ -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
diff -Nurp acpid-1.0.6.orig/Makefile acpid-1.0.6/Makefile
--- acpid-1.0.6.orig/Makefile 2008-06-13 16:21:36.000000000 +0200
+++ acpid-1.0.6/Makefile 2008-06-13 16:20:56.000000000 +0200
@@ -21,7 +21,7 @@ acpi_listen_OBJS = $(acpi_listen_SRCS:.c
MAN8 = acpid.8 acpi_listen.8
MAN8GZ = $(MAN8:.8=.8.gz)
-CFLAGS += -Wall $(DEFS)
+CFLAGS += -Wall -D_GNU_SOURCE $(DEFS)
DEFS = -DVERSION="\"$(VERSION)\""
all: $(PROGS)