I have made the following changes intended for : CE:Adaptation:x86-generic / acpid
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.pub.meego.com//request/show/4053 Thank You, Marko Saukko [This message was auto-generated] --- Request # 4053: Messages from BOSS: State: review at 2012-01-12T08:48:13 by bossbot Reviews: accepted by bossbot : Prechecks succeeded. new for CE-maintainers : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:sage:branches:CE:Adaptation:x86-generic / acpid -> CE:Adaptation:x86-generic / acpid changes files: -------------- --- acpid.changes +++ acpid.changes @@ -0,0 +1,7 @@ +* Thu Jan 12 2012 Marko Saukko <[email protected]> - 2.0.14 +- Update to version 2.0.14 +- Removed ConsoleKit based session check from acpid.power.sh. + Now it check just if power management binary is running. Added also + /sbin/mce in the list. +- Added .yaml for spectacle. + old: ---- acpid-2.0.10.tar.gz new: ---- acpid-2.0.14.tar.gz acpid.yaml spec files: ----------- --- acpid.spec +++ acpid.spec @@ -1,36 +1,43 @@ -#specfile originally created for Fedora, modified for Moblin Linux -Summary: ACPI Event Daemon +# +# Do NOT Edit the Auto-generated Part! +# Generated by: spectacle version 0.23 +# +# >> macros +# << macros + Name: acpid -Version: 2.0.10 +Summary: ACPI Event Daemon +Version: 2.0.14 Release: 1 -License: GPLv2+ and BSD Group: System/Daemons -Source: http://tedfelix.com/linux/acpid-%{version}.tar.gz -Source2: acpid.video.conf -Source3: acpid.power.conf -Source4: acpid.power.sh -Source5: acpid.lid.conf -Source6: acpid.lid.sh -Source7: acpid.battery.sh -Source8: acpid.battery.conf -Source9: acpid.ac.conf -Source13: acpid-start-script -Source14: acpid.start.sh -Source15: acpid.service -Source16: acpid -Patch1: acpid-2.0.9-makefile.patch -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -Requires(post): systemd -Requires(preun): systemd -Requires(postun): systemd - +License: GPLv2+ and BSD ExclusiveArch: ia64 x86_64 %{ix86} URL: http://tedfelix.com/linux/acpid-netlink.html +Source0: http://tedfelix.com/linux/acpid-%{version}.tar.gz +Source1: acpid.video.conf +Source2: acpid.power.conf +Source3: acpid.power.sh +Source4: acpid.lid.conf +Source5: acpid.lid.sh +Source6: acpid.battery.sh +Source7: acpid.battery.conf +Source8: acpid.ac.conf +Source9: acpid-start-script +Source10: acpid.start.sh +Source11: acpid.service +Source12: acpid +Source100: acpid.yaml +Patch0: acpid-2.0.9-makefile.patch +Requires: systemd +Requires(preun): systemd +Requires(post): systemd +Requires(postun): systemd %description acpid is a daemon that dispatches ACPI events to user-space programs. + %package extra-docs Summary: sample docs and sample scripts for apcid Group: Documentation @@ -41,18 +48,29 @@ %prep -%setup -q -%patch1 -p1 -b .makefile +%setup -q -n %{name}-%{version} + +# acpid-2.0.9-makefile.patch +%patch0 -p1 +# >> setup +# << setup %build -make %{?_smp_mflags} +# >> build pre +# << build pre + +make %{?jobs:-j%jobs} +# >> build post +# << build post %install -rm -rf $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT -make install DESTDIR=$RPM_BUILD_ROOT +rm -rf %{buildroot} +# >> install pre +# << install pre +%make_install +# >> install post mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions mkdir -p $RPM_BUILD_ROOT%{_datadir}/acpi @@ -63,37 +81,41 @@ mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/pm/sleep.d mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/lib/acpi-support mkdir -p $RPM_BUILD_ROOT/%{_lib}/systemd/system -install -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/videoconf -install -m 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/powerconf -install -m 755 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/power.sh -install -m 644 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/lidconf -install -m 755 %{SOURCE6} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/lid.sh -install -m 755 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/battery.sh -install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/batteryconf -install -m 644 %{SOURCE9} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/acconf -install -m 755 %{SOURCE13} $RPM_BUILD_ROOT%{_sbindir}/acpid-start-script -install -m 755 %{SOURCE14} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/start.sh -install -D -m 644 %{SOURCE15} $RPM_BUILD_ROOT/%{_lib}/systemd/system/acpid.service -install -D -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/acpid +install -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/videoconf +install -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/powerconf +install -m 755 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/power.sh +install -m 644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/lidconf +install -m 755 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/lid.sh +install -m 755 %{SOURCE6} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/battery.sh +install -m 644 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/batteryconf +install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/events/acconf +install -m 755 %{SOURCE9} $RPM_BUILD_ROOT%{_sbindir}/acpid-start-script +install -m 755 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/acpi/actions/start.sh +install -D -m 644 %{SOURCE11} $RPM_BUILD_ROOT/%{_lib}/systemd/system/acpid.service +install -D -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/acpid mkdir -p %{buildroot}/%{_lib}/systemd/system/multi-user.target.wants ln -s ../acpid.service %{buildroot}/%{_lib}/systemd/system/multi-user.target.wants/acpid.service +# << install post -%post -systemctl daemon-reload -systemctl restart acpid.service %preun systemctl stop acpid.service +%post +systemctl daemon-reload +systemctl reload-or-try-restart acpid.service + %postun systemctl daemon-reload -%clean -rm -rf $RPM_BUILD_ROOT + + + %files -%defattr(-,root,root) +%defattr(-,root,root,-) +# >> files %doc COPYING README Changelog TODO %dir %{_sysconfdir}/acpi %dir %{_sysconfdir}/acpi/events @@ -113,15 +135,17 @@ %config(noreplace) %attr(0644,root,root) %{_sysconfdir}/acpi/events/acconf %config(noreplace) %attr(0755,root,root) %{_sysconfdir}/acpi/actions/start.sh %config(noreplace) %attr(0755,root,root) %{_sysconfdir}/sysconfig/acpid - %{_bindir}/acpi_listen %{_sbindir}/acpid %{_sbindir}/acpid-start-script %{_mandir}/man8/acpid.8.gz %{_mandir}/man8/acpi_listen.8.gz +# << files + %files extra-docs -%defattr(-,root,root) +%defattr(-,root,root,-) +# >> files extra-docs %doc %{_defaultdocdir}/acpid/COPYING %doc %{_defaultdocdir}/acpid/Changelog %doc %{_defaultdocdir}/acpid/README @@ -141,3 +165,5 @@ %doc %{_defaultdocdir}/acpid/samples/powerbtn/powerbtn.sh %doc %{_defaultdocdir}/acpid/samples/powerbtn/powerbtn.sh.old %doc %{_defaultdocdir}/acpid/COPYING +# << files extra-docs + other changes: -------------- ++++++ acpid-2.0.10.tar.gz -> acpid-2.0.14.tar.gz --- Changelog +++ Changelog @@ -1,3 +1,52 @@ +* Thu Dec 15 2011 Ted Felix <http://www.tedfelix.com> + - 2.0.14 release + - Fixed brace style. (inotify_handler.c acpid.c) (Ted Felix) + - Added support for a "K" suffix on event strings to indicate that they + may have originated from a keyboard input layer device. This can be + used to differentiate between a power switch on the keyboard, and a power + switch on the computer's case. + + (connection_list.h inotify_handler.c input_layer.c netlink.c proc.c + sock.c) (Ted Felix) + + - Added a pathname to connection along with a find_connection_name(). + Modifications to process_inotify() to log IN_DELETE events. Additional + debugging output. + + These changes were experimentation related to dealing with a ThinkPad + suspend problem. They should have no effect on acpid's behavior. They are + mainly noticeable as a change in the logging. + + The Problem: When resuming from suspend, the lid switch and power button's + /dev/input event files do not trigger an IN_CREATE, so acpid doesn't + reconnect to them. Restarting acpid fixes this. + + Tried using IN_DELETE instead of ENODEV to detect the drivers going away. + Worked fine for disconnecting/reconnecting a USB keyboard, but not for the + ThinkPad suspend problem. I've given up on fixing this as it appears to be + a kernel or driver issue. + + (connection_list.c connection_list.h inotify_handler.c input_layer.c + netlink.c proc.c sock.c) (Ted Felix) + +* Tue Nov 15 2011 Ted Felix <http://www.tedfelix.com> + - 2.0.13 release + - Fix for socket name buffer overflow. (ud_socket.c) (Ted Felix) + - Moved acpid_log() out of acpid.h/.c and into log.h/.c to make it easier + for all parts of acpid to use. (Makefile acpid.h acpid.c connection_list.c + event.c inotify_handler.c input_layer.c log.h log.c netlink.c proc.c + sock.c ud_socket.c) (Ted Felix) + - Cleaned up #includes and comment style. (libnetlink.c libnetlink.h) + (Ted Felix) + +* Mon Aug 15 2011 Ted Felix <http://www.tedfelix.com> + - 2.0.12 release + - Changed exit() to _exit() if execl() fails. (event.c) (Ted Felix) + +* Sat Jul 30 2011 Ted Felix <http://www.tedfelix.com> + - 2.0.11 release + - Set umask to 0077 for scripts run by acpid. (event.c) (Ted Felix) + * Tue May 17 2011 Ted Felix <http://www.tedfelix.com> - 2.0.10 release - Fixed compiler warnings in kacpimon. (kacpimon/libnetlink.c) --- Makefile +++ Makefile @@ -1,7 +1,7 @@ # Makefile for ACPI daemon # update these numbers for new releases -VERSION = 2.0.10 +VERSION = 2.0.14 OPT = -O2 @@ -18,10 +18,10 @@ PROGS = $(SBIN_PROGS) $(BIN_PROGS) 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 + inotify_handler.c libnetlink.c log.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 +acpi_listen_SRCS = acpi_listen.c log.c ud_socket.c acpi_listen_OBJS = $(acpi_listen_SRCS:.c=.o) all_SRCS = $(acpid_SRCS) $(acpi_listen_SRCS) --- TESTPLAN +++ TESTPLAN @@ -6,7 +6,7 @@ - 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 It's different if you are using upstart: - sudo initctl gdm stop + sudo initctl stop gdm And systemd requires a different incantation: [anyone care to enlighten me?] Now X is out of the way and you can test from the console. --- acpid.c +++ acpid.c @@ -30,9 +30,9 @@ #include <stdlib.h> #include <errno.h> #include <getopt.h> -#include <stdarg.h> #include "acpid.h" +#include "log.h" #include "event.h" #include "connection_list.h" #include "proc.h" @@ -80,16 +80,14 @@ /* open the log */ open_log(); - if (!netlink) - { + if (!netlink) { /* open the acpi event file in the proc fs */ /* if the open fails, try netlink */ if (open_proc()) netlink = 1; } - if (netlink) - { + if (netlink) { /* open the input layer */ open_input(); @@ -141,8 +139,7 @@ logevents ? "on" : "off"); /* main loop */ - while (1) - { + while (1) { fd_set readfds; int nready; int i; @@ -165,8 +162,7 @@ acpid_close_dead_clients(); /* for each connection */ - for (i = 0; i <= get_number_of_connections(); ++i) - { + for (i = 0; i <= get_number_of_connections(); ++i) { int fd; p = get_connection(i); @@ -179,8 +175,7 @@ fd = p->fd; /* if this file descriptor has data waiting */ - if (FD_ISSET(fd, &readfds)) - { + if (FD_ISSET(fd, &readfds)) { /* delegate to this connection's process function */ p->process(fd); } @@ -254,6 +249,7 @@ case 'd': foreground = 1; acpid_debug++; + log_debug_to_stderr = 1; break; case 'e': eventfile = optarg; @@ -299,8 +295,7 @@ } for (opt = opts, hlp = opts_help; opt->name; - opt++, hlp++) - { + opt++, hlp++) { fprintf(stderr, " -%c, --%s", opt->val, opt->name); size = strlen(opt->name); @@ -469,33 +464,6 @@ } int -#ifdef __GNUC__ -__attribute__((format(printf, 2, 3))) -#endif -acpid_log(int level, const char *fmt, ...) -{ - va_list args; - - if (level == LOG_DEBUG) { - /* if "-d" has been specified */ - if (acpid_debug) { - /* send debug output to stderr */ - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - - fprintf(stderr, "\n"); - } - } else { - va_start(args, fmt); - vsyslog(level, fmt, args); - va_end(args); - } - - return 0; -} - -int locked() { struct stat trash; --- acpid.h +++ acpid.h @@ -23,8 +23,6 @@ #ifndef ACPID_H__ #define ACPID_H__ -#include <syslog.h> - #define ACPI_PROCDIR "/proc/acpi" #define ACPID_EVENTFILE ACPI_PROCDIR "/event" #define ACPID_CONFDIR "/etc/acpi/events" @@ -48,8 +46,6 @@ extern int logevents; extern const char *progname; -extern int acpid_log(int level, const char *fmt, ...); - extern int locked(); extern void clean_exit_with_status(int status); --- connection_list.c +++ connection_list.c @@ -22,8 +22,11 @@ #include <unistd.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "acpid.h" +#include "log.h" #include "connection_list.h" @@ -87,8 +90,11 @@ for (i = 0; i < nconnections; ++i) { /* if the file descriptors match, delete the connection */ if (connection_list[i].fd == fd) { + free(connection_list[i].pathname); + --nconnections; connection_list[i] = connection_list[nconnections]; + break; } } @@ -116,6 +122,27 @@ return &connection_list[i]; } + return NULL; +} + +/*---------------------------------------------------------------*/ + +struct connection * +find_connection_name(char *pathname) +{ + int i; + + /* for each connection */ + for (i = 0; i < nconnections; ++i) { + /* skip null pathnames */ + if (connection_list[i].pathname == NULL) + continue; + + /* if the pathname matches, return the connection */ + if (strcmp(connection_list[i].pathname, pathname) == 0) + return &connection_list[i]; + } + return NULL; } --- connection_list.h +++ connection_list.h @@ -35,7 +35,16 @@ int fd; /* process incoming data on the connection */ + /* ??? suggest passing a pointer to this connection struct */ void (* process)(int fd); + + /* Optional. Used by find_connection_name() to find the connection for a + specific file. Set to NULL if not specified. Memory will be freed + with free() when connection is deleted. */ + char *pathname; + + /* 0 indicates this is probably not a keyboard device */ + int kybd; }; /* add a connection to the list */ @@ -45,8 +54,15 @@ extern void delete_connection(int fd); /* find a connection in the list by file descriptor */ +/* ??? This routine is unnecessary. When we call the connection's process + * routine, we should pass a pointer to the connection. That will have + * the usual fd along with everything else. */ extern struct connection *find_connection(int fd); +/* find a connection in the list by pathname */ +/* ??? unused last I checked */ +extern struct connection *find_connection_name(char *pathname); + /* get the number of connections in the list */ extern int get_number_of_connections(); --- event.c +++ event.c @@ -36,6 +36,7 @@ #include <signal.h> #include "acpid.h" +#include "log.h" #include "sock.h" #include "ud_socket.h" @@ -641,10 +642,11 @@ if (acpid_debug && logevents) { fprintf(stdout, "BEGIN HANDLER MESSAGES\n"); } + umask(0077); execl("/bin/sh", "/bin/sh", "-c", action, NULL); /* should not get here */ acpid_log(LOG_ERR, "execl(): %s", strerror(errno)); - exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } /* parent */ --- inotify_handler.c +++ inotify_handler.c @@ -33,6 +33,7 @@ /* local */ #include "acpid.h" +#include "log.h" #include "connection_list.h" #include "input_layer.h" @@ -52,13 +53,11 @@ acpid_log(LOG_DEBUG, "inotify read bytes: %d", bytes); /* eof is not expected */ - if (bytes == 0) - { + if (bytes == 0) { acpid_log(LOG_WARNING, "inotify fd eof encountered"); return; } - else if (bytes < 0) - { + else if (bytes < 0) { /* EINVAL means buffer wasn't big enough. See inotify(7). */ acpid_log(LOG_ERR, "inotify read error: %s (%d)", strerror(errno), errno); @@ -69,21 +68,43 @@ acpid_log(LOG_DEBUG, "inotify name len: %d", eventbuf.event.len); - /* if a name is included */ - if (eventbuf.event.len > 0) - { - const int dnsize = 256; - char devname[dnsize]; + const int dnsize = 256; + char devname[dnsize]; + /* if a name is included */ + if (eventbuf.event.len > 0) { /* devname = ACPID_INPUTLAYERDIR + "/" + pevent -> name */ strcpy(devname, ACPID_INPUTLAYERDIR); strcat(devname, "/"); strncat(devname, eventbuf.event.name, dnsize - strlen(devname) - 1); + } + /* if this is a create */ + if (eventbuf.event.mask & IN_CREATE) { acpid_log(LOG_DEBUG, "inotify about to open: %s", devname); open_inputfile(devname); } + + /* if this is a delete */ + if (eventbuf.event.mask & IN_DELETE) { + /* struct connection *c; */ + + acpid_log(LOG_DEBUG, "inotify received a delete for: %s", devname); + +#if 0 +/* Switching back to the original ENODEV detection scheme. See + process_input() in input_layer.c. */ +/* keeping this for future reference */ + /* search for the event file in the connection list */ + /* ??? Or should we just have a delete_connection_name()? */ + c = find_connection_name(devname); + + /* close that connection if found */ + if (c) + delete_connection(c->fd); +#endif + } } /*-----------------------------------------------------------------*/ @@ -105,8 +126,8 @@ acpid_log(LOG_DEBUG, "inotify fd: %d", fd); - /* watch for new files being created in /dev/input */ - wd = inotify_add_watch(fd, ACPID_INPUTLAYERDIR, IN_CREATE); + /* watch for files being created or deleted in /dev/input */ + wd = inotify_add_watch(fd, ACPID_INPUTLAYERDIR, IN_CREATE | IN_DELETE); if (wd < 0) { acpid_log(LOG_ERR, "inotify_add_watch() failed: %s (%d)", @@ -120,6 +141,8 @@ /* add a connection to the list */ c.fd = fd; c.process = process_inotify; + c.pathname = NULL; + c.kybd = 0; add_connection(&c); } --- input_layer.c +++ input_layer.c @@ -39,6 +39,7 @@ /* local */ #include "acpid.h" +#include "log.h" #include "connection_list.h" #include "event.h" @@ -187,6 +188,8 @@ ssize_t nbytes; const char *str; static int nerrs; + struct connection *c; + char str2[100]; nbytes = read(fd, &event, sizeof(event)); @@ -200,7 +203,8 @@ if (errno == EINTR) return; if (errno == ENODEV) { - acpid_log(LOG_WARNING, "input device has been disconnected"); + acpid_log(LOG_WARNING, "input device has been disconnected, fd %d", + fd); delete_connection(fd); return; } @@ -224,11 +228,27 @@ return; } + c = find_connection(fd); + + /* if we're getting scancodes, we probably have a keyboard */ + if (event.type == EV_MSC && event.code == MSC_SCAN) { + if (c) + c->kybd = 1; /* appears to be a keyboard device */ + } + /* 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 suspect this is a keyboard, and we have enough space, tack a + * "K" on to the end of the event string. */ + if (c && c->kybd && strnlen(str, sizeof(str2)) <= sizeof(str2) - 3) { + strcpy(str2, str); + strcat(str2, " K"); + str = str2; + } /* if we're locked, don't process the event */ if (locked()) { @@ -307,18 +327,30 @@ fcntl(fd, F_SETFD, FD_CLOEXEC); if (fd >= 0) { + char evname[256]; + /* if this file doesn't have events we need, indicate failure */ if (!has_event(fd)) { close(fd); return -1; } - acpid_log(LOG_DEBUG, "input layer %s " - "opened successfully", filename); + /* get this event file's name for debugging */ + strcpy(evname, "Unknown"); + ioctl(fd, EVIOCGNAME(sizeof(evname)), evname); + + acpid_log(LOG_DEBUG, "input layer %s (%s) " + "opened successfully, fd %d", filename, evname, fd); /* add a connection to the list */ c.fd = fd; c.process = process_input; + /* delete_connection() will free */ + c.pathname = malloc(strlen(filename) + 1); + if (c.pathname) + strcpy(c.pathname, filename); + /* assume not a keyboard until we see a scancode */ + c.kybd = 0; add_connection(&c); return 0; /* success */ --- libnetlink.c +++ libnetlink.c @@ -15,7 +15,6 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <syslog.h> #include <fcntl.h> #include <net/if_arp.h> #include <sys/socket.h> --- libnetlink.h +++ libnetlink.h @@ -2,7 +2,7 @@ #define __LIBNETLINK_H__ 1 #include <asm/types.h> -// needed by netlink.h, should be in there +/* needed by netlink.h, should be in there */ #include <arpa/inet.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> --- log.c +++ log.c @@ -0,0 +1,56 @@ +/* + * log.c - ACPI daemon logging + * + * Portions Copyright (C) 2000 Andrew Henroid + * Portions Copyright (C) 2001 Sun Microsystems + * Portions Copyright (C) 2004 Tim Hockin ([email protected]) + * + * 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> +#include <syslog.h> +#include <stdarg.h> + +#include "log.h" + +int log_debug_to_stderr = 0; + +int +#ifdef __GNUC__ +__attribute__((format(printf, 2, 3))) +#endif +acpid_log(int level, const char *fmt, ...) +{ + va_list args; + + if (level == LOG_DEBUG) { + /* if "-d" has been specified */ + if (log_debug_to_stderr) { + /* send debug output to stderr */ + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + + fprintf(stderr, "\n"); + } + } else { + va_start(args, fmt); + vsyslog(level, fmt, args); + va_end(args); + } + + return 0; +} --- log.h +++ log.h @@ -0,0 +1,37 @@ +/* + * log.h - ACPI daemon logging + * + * Copyright (C) 1999-2000 Andrew Henroid + * Copyright (C) 2001 Sun Microsystems + * Portions Copyright (C) 2004 Tim Hockin ([email protected]) + * + * 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 LOG_H__ +#define LOG_H__ + +/* for LOG_ERR, LOG_DEBUG, LOG_INFO, etc... */ +#include <syslog.h> + +/* + * Set to 1 to send LOG_DEBUG logging to stderr, zero to ignore LOG_DEBUG + * logging. Default is zero. + */ +extern int log_debug_to_stderr; + +extern int acpid_log(int level, const char *fmt, ...); + +#endif /* LOG_H__ */ --- netlink.c +++ netlink.c @@ -35,6 +35,7 @@ /* local */ #include "acpid.h" +#include "log.h" #include "event.h" #include "libnetlink.h" @@ -232,6 +233,8 @@ /* add a connection to the list */ c.fd = rth.fd; c.process = process_netlink; + c.pathname = NULL; + c.kybd = 0; add_connection(&c); } --- proc.c +++ proc.c @@ -28,6 +28,7 @@ #include <errno.h> #include "acpid.h" +#include "log.h" #include "event.h" #include "connection_list.h" @@ -107,6 +108,8 @@ /* add a connection to the list */ c.fd = fd; c.process = process_proc; + c.pathname = NULL; + c.kybd = 0; add_connection(&c); return 0; --- sock.c +++ sock.c @@ -30,6 +30,7 @@ #include <grp.h> #include "acpid.h" +#include "log.h" #include "event.h" #include "ud_socket.h" #include "connection_list.h" @@ -174,5 +175,7 @@ /* add a connection to the list */ c.fd = fd; c.process = process_sock; + c.pathname = NULL; + c.kybd = 0; add_connection(&c); } --- ud_socket.c +++ ud_socket.c @@ -15,6 +15,7 @@ #include <fcntl.h> #include "acpid.h" +#include "log.h" #include "ud_socket.h" int @@ -24,7 +25,16 @@ int r; struct sockaddr_un uds_addr; - /* JIC */ + if (strnlen(name, sizeof(uds_addr.sun_path)) > + sizeof(uds_addr.sun_path) - 1) { + acpid_log(LOG_ERR, "ud_create_socket(): " + "socket filename longer than %u characters: %s", + sizeof(uds_addr.sun_path) - 1, name); + errno = EINVAL; + return -1; + } + + /* JIC */ unlink(name); fd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -35,7 +45,7 @@ /* setup address struct */ memset(&uds_addr, 0, sizeof(uds_addr)); uds_addr.sun_family = AF_UNIX; - strcpy(uds_addr.sun_path, name); + strncpy(uds_addr.sun_path, name, sizeof(uds_addr.sun_path) - 1); /* bind it to the socket */ r = bind(fd, (struct sockaddr *)&uds_addr, sizeof(uds_addr)); @@ -85,6 +95,14 @@ int r; struct sockaddr_un addr; + if (strnlen(name, sizeof(addr.sun_path)) > sizeof(addr.sun_path) - 1) { + acpid_log(LOG_ERR, "ud_connect(): " + "socket filename longer than %u characters: %s", + sizeof(addr.sun_path) - 1, name); + errno = EINVAL; + return -1; + } + fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { return fd; @@ -93,6 +111,8 @@ memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; sprintf(addr.sun_path, "%s", name); + /* safer: */ + /*strncpy(addr.sun_path, name, sizeof(addr.sun_path) - 1);*/ r = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); if (r < 0) { ++++++ acpid.power.sh --- acpid.power.sh +++ acpid.power.sh @@ -2,26 +2,10 @@ PATH=/sbin:/bin:/usr/bin -# Get the ID of the first active X11 session: -uid_session=$( -ck-list-sessions | \ -awk ' -/^Session[0-9]+:$/ { uid = active = x11 = "" ; next } -{ gsub(/'\''/, "", $3) } -$1 == "unix-user" { uid = $3 } -$1 == "active" { active = $3 } -$1 == "x11-display" { x11 = $3 } -active == "TRUE" && x11 != "" { - print uid - exit -}') - # Check that there is a power manager, otherwise shut down. -[ "$uid_session" ] && ps axo uid,cmd | \ awk ' - $1 == '$uid_session' && - ($2 == "gnome-power-manager" || $2 == "kpowersave" || $2 == "xfce4-power-manager" || $2 ~ /meego-power-icon/ ) \ + ($2 == "gnome-power-manager" || $2 == "/sbin/mce" || $2 == "kpowersave" || $2 == "xfce4-power-manager" || $2 ~ /meego-power-icon/ ) \ { found = 1; exit } END { exit !found } ' || ++++++ acpid.yaml (new) --- acpid.yaml +++ acpid.yaml @@ -0,0 +1,34 @@ +Name: acpid +Summary: ACPI Event Daemon +Version: 2.0.14 +Release: 1 +Group: System/Daemons +License: GPLv2+ and BSD +URL: http://tedfelix.com/linux/acpid-netlink.html +Sources: + - http://tedfelix.com/linux/acpid-%{version}.tar.gz + - acpid.video.conf + - acpid.power.conf + - acpid.power.sh + - acpid.lid.conf + - acpid.lid.sh + - acpid.battery.sh + - acpid.battery.conf + - acpid.ac.conf + - acpid-start-script + - acpid.start.sh + - acpid.service + - acpid +Patches: + - acpid-2.0.9-makefile.patch +Description: acpid is a daemon that dispatches ACPI events to user-space programs. + +Configure: none +Builder: make +ExclusiveArch: ia64 x86_64 %{ix86} +SubPackages: + - Name: extra-docs + Summary: sample docs and sample scripts for apcid + Group: Documentation + Description: Extra sample docs and scripts for acpid. +
