lircd: start lircd via systemd, rework lircd_helper and udev rules, this should fix #2991, this should fix #2968

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2014-03-09 22:27:09 +01:00
parent 5ce57469d8
commit a5e60d609e
5 changed files with 83 additions and 136 deletions

View File

@ -1,60 +0,0 @@
################################################################################
# An example udev rules file for lircd.
################################################################################
# lircd_helper only does something for "add" and "remove" actions.
ACTION!="add|remove", GOTO="end"
KERNEL=="hiddev[0-9]*", SUBSYSTEM=="usb", SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="ttyACM[0-9]*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="lirc[0-9]*", SUBSYSTEM=="lirc", SUBSYSTEMS=="i2c", GOTO="begin"
KERNEL=="lirc[0-9]*", SUBSYSTEM=="lirc", SUBSYSTEMS=="usb", GOTO="begin"
KERNEL=="lirc[0-9]*", SUBSYSTEM=="lirc", SUBSYSTEMS=="platform", GOTO="begin"
KERNEL=="lirc[0-9]*", SUBSYSTEM=="lirc", SUBSYSTEMS=="pnp", GOTO="begin"
GOTO="end"
LABEL="begin"
#-------------------------------------------------------------------------------
# Ask lircd_helper to lirc devices.
#-------------------------------------------------------------------------------
SUBSYSTEM=="lirc", \
ENV{lircd_driver}="default", \
ENV{lircd_conf}="/etc/lirc/lircd.conf"
### Microsoft Xbox DVD dongle
SUBSYSTEM=="lirc", DRIVERS=="lirc_xbox", \
ENV{lircd_driver}="default", \
ENV{lircd_conf}="/etc/lirc/lircd.conf.xbox"
### RPi GPIO IR Receiver
SUBSYSTEM=="lirc", DRIVERS=="lirc_rpi", \
ENV{lircd_driver}="default", \
ENV{lircd_conf}="/etc/lirc/lircd.conf.rpi"
#-------------------------------------------------------------------------------
# Ask lircd_helper to handle USB devices that do not show up as lirc devices
# and are supported by lircd. Remote controls that are USB HID devices that show
# up as event devices are not included as as they are handled by eventlircd.
#-------------------------------------------------------------------------------
SUBSYSTEMS=="usb", GOTO="begin-usb"
GOTO="end-usb"
LABEL="begin-usb"
ENV{ID_USB_INTERFACES}=="", IMPORT{builtin}="usb_id"
ENV{ID_VENDOR_ID}=="04d8", ENV{ID_MODEL_ID}=="fd08", \
ENV{lircd_driver}="usb_irtoy", \
ENV{lircd_conf}="/storage/.config/lircd.conf"
ENV{ID_VENDOR_ID}=="0fe9", ENV{ID_MODEL_ID}=="9010", \
ENV{lircd_driver}="dvico", \
ENV{lircd_conf}="/etc/lirc/lircd.conf"
# Enable wake-on-usb for the USB remotes.
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", RUN+="wakeup_enable"
LABEL="end-usb"
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", RUN+="lircd_helper"
LABEL="end"

View File

@ -58,7 +58,9 @@ post_makeinstall_target() {
cp $PKG_DIR/config/lircd.conf.xbox $INSTALL/etc/lirc cp $PKG_DIR/config/lircd.conf.xbox $INSTALL/etc/lirc
cp $PKG_DIR/config/lircd.conf.rpi $INSTALL/etc/lirc cp $PKG_DIR/config/lircd.conf.rpi $INSTALL/etc/lirc
mkdir -p $INSTALL/usr/lib/openelec
cp $PKG_DIR/scripts/lircd_helper $INSTALL/usr/lib/openelec
mkdir -p $INSTALL/usr/lib/udev mkdir -p $INSTALL/usr/lib/udev
cp $PKG_DIR/scripts/lircd_helper $INSTALL/usr/lib/udev
cp $PKG_DIR/scripts/lircd_wakeup_enable $INSTALL/usr/lib/udev cp $PKG_DIR/scripts/lircd_wakeup_enable $INSTALL/usr/lib/udev
} }

View File

@ -1,74 +1,66 @@
#!/bin/sh #!/bin/sh
################################################################################ ################################################################################
# lircd_helper # This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
# #
# This script can be used by udev to start or stop lircd when a remote control # OpenELEC is free software: you can redistribute it and/or modify
# device is added or removed. # 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.
# #
# lircd_helper configures lircd to output using a uinput event device so that # OpenELEC is distributed in the hope that it will be useful,
# eventlircd can aggregate the outputs into a single lircd socket. # 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.
# #
# lircd_helper configures lircd to use an lircd socket name that is derived # You should have received a copy of the GNU General Public License
# from the device name. In addition, lircd_helper creates symbolic links to this # along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
# lircd socket that are derived from the device symbolic links. You can use this
# socket and the symbolic link to this socket when using commands such as
# irsend.
#
# lircd_helper understands two lircd_helper specific device properites set
# using ENV{} and passed as environment variables:
# lircd_driver:
# Used to tell lircd_helper the name of the lircd driver.
# lircd_conf:
# Used to tell lircd_helper the path to the lircd.conf file to use.
################################################################################ ################################################################################
case "${ACTION}" in ACTION=$(echo "$1")
add) DEVICE=$(echo "$2" | cut -f1 -d:)
if test "x${lircd_driver}" = "x" ; then DRIVER=$(echo "$2" | cut -f2 -d:)
exit 1; CONFIG=$(echo "$2" | cut -f3 -d:)
fi
if test "x${lircd_conf}" = "x" ; then case "$ACTION" in
exit 1; add)
fi if [ "x$DRIVER" = "x" ]; then
if test ! -e '/run/lirc' ; then exit 1;
mkdir -p '/run/lirc' fi
fi if [ "x$CONFIG" = "x" ]; then
devname_instance=`echo ${DEVNAME} | sed -e 's/\/\+/~/g' -e 's/^~dev~//'` exit 1;
if test ! -e "/run/lirc/lircd-${devname_instance}.pid" ; then fi
daemon='/usr/sbin/lircd'
daemon="${daemon} --driver=${lircd_driver}" mkdir -p '/run/lirc'
daemon="${daemon} --device=${DEVNAME}"
daemon="${daemon} --uinput" if [ ! -e "/run/lirc/lircd-$DEVICE.pid" ]; then
daemon="${daemon} --output=/run/lirc/lircd-${devname_instance}"
daemon="${daemon} --pidfile=/run/lirc/lircd-${devname_instance}.pid" LIRCD="/usr/sbin/lircd"
if test -e "/storage/.config/lircd.conf" ; then LIRCD_CONFIG="--uinput --driver=$DRIVER --device=/dev/$DEVICE"
daemon="${daemon} /storage/.config/lircd.conf" LIRCD_CONFIG="$LIRCD_CONFIG --output=/run/lirc/lircd-$DEVICE"
elif test -e "${lircd_conf}" ; then LIRCD_CONFIG="$LIRCD_CONFIG --pidfile=/run/lirc/lircd-$DEVICE.pid"
daemon="${daemon} ${lircd_conf}"
else if [ -e "/storage/.config/$CONFIG" ]; then
exit 1 LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/$CONFIG"
fi elif [ -e "/storage/.config/lircd.conf" ]; then
${daemon} LIRCD_CONFIG="$LIRCD_CONFIG /storage/.config/lircd.conf"
for devlink in ${DEVLINKS} ; do elif [ -e "/etc/lirc/$CONFIG" ]; then
devlink_instance=`echo ${devlink} | /bin/sed -e 's/\/\+/~/g' -e 's/^~dev~//'` LIRCD_CONFIG="$LIRCD_CONFIG /etc/lirc/$CONFIG"
rm -f "/run/lirc/lircd-${devlink_instance}" else
ln -s "lircd-${devname_instance}" "/run/lirc/lircd-${devlink_instance}" exit 1
done fi
fi
;; exec $LIRCD $LIRCD_CONFIG
remove) fi
instance=`echo $DEVNAME | sed -e 's/\/\+/~/g' -e 's/^~dev~//'` ;;
if test -e "/run/lirc/lircd-${instance}.pid" ; then remove)
pid=`cat /run/lirc/lircd-${instance}.pid` if [ -e "/run/lirc/lircd-$DEVICE.pid" ]; then
if test ! "x${pid}" = "x" ; then PID=`cat /run/lirc/lircd-$DEVICE.pid`
kill ${pid} if [ ! "x$PID" = "x" ]; then
fi kill $PID
for devlink in ${DEVLINKS} ; do fi
devlink_instance=`echo ${devlink} | sed -e 's/\/\+/~/g' -e 's/^~dev~//'` fi
rm -f "/run/lirc/lircd-${devlink_instance}" ;;
done
fi
;;
esac esac
exit 0 exit 0

View File

@ -0,0 +1,12 @@
[Unit]
Description=Lirc with %I
[Service]
Type=oneshot
ExecStart=/usr/lib/openelec/lircd_helper add %I
ExecStop=/usr/lib/openelec/lircd_helper remove %I
TimeoutStopSec=1
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -17,19 +17,20 @@ LABEL="begin"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Ask lircd_helper to lirc devices. # Ask lircd_helper to lirc devices.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SUBSYSTEM=="lirc", \
ENV{lircd_driver}="default", \ #SUBSYSTEM=="lirc", \
ENV{lircd_conf}="/etc/lirc/lircd.conf" # ENV{lircd_driver}="default", \
# ENV{lircd_conf}="lircd.conf"
### Microsoft Xbox DVD dongle ### Microsoft Xbox DVD dongle
SUBSYSTEM=="lirc", DRIVERS=="lirc_xbox", \ SUBSYSTEM=="lirc", DRIVERS=="lirc_xbox", \
ENV{lircd_driver}="default", \ ENV{lircd_driver}="default", \
ENV{lircd_conf}="/etc/lirc/lircd.conf.xbox" ENV{lircd_conf}="lircd.conf.xbox"
### RPi GPIO IR Receiver ### RPi GPIO IR Receiver
SUBSYSTEM=="lirc", DRIVERS=="lirc_rpi", \ SUBSYSTEM=="lirc", DRIVERS=="lirc_rpi", \
ENV{lircd_driver}="default", \ ENV{lircd_driver}="default", \
ENV{lircd_conf}="/etc/lirc/lircd.conf.rpi" ENV{lircd_conf}="lircd.conf.rpi"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Ask lircd_helper to handle USB devices that do not show up as lirc devices # Ask lircd_helper to handle USB devices that do not show up as lirc devices
@ -38,23 +39,23 @@ SUBSYSTEM=="lirc", DRIVERS=="lirc_rpi", \
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
SUBSYSTEMS=="usb", GOTO="begin-usb" SUBSYSTEMS=="usb", GOTO="begin-usb"
GOTO="end-usb" GOTO="end-usb"
LABEL="begin-usb" LABEL="begin-usb"
ENV{ID_USB_INTERFACES}=="", IMPORT{builtin}="usb_id" ENV{ID_USB_INTERFACES}=="", IMPORT{builtin}="usb_id"
ENV{ID_VENDOR_ID}=="04d8", ENV{ID_MODEL_ID}=="fd08", \ ENV{ID_VENDOR_ID}=="04d8", ENV{ID_MODEL_ID}=="fd08", \
ENV{lircd_driver}="usb_irtoy", \ ENV{lircd_driver}="usb_irtoy", \
ENV{lircd_conf}="/storage/.config/lircd.conf" ENV{lircd_conf}="lircd.conf"
ENV{ID_VENDOR_ID}=="0fe9", ENV{ID_MODEL_ID}=="9010", \ ENV{ID_VENDOR_ID}=="0fe9", ENV{ID_MODEL_ID}=="9010", \
ENV{lircd_driver}="dvico", \ ENV{lircd_driver}="dvico", \
ENV{lircd_conf}="/etc/lirc/lircd.conf" ENV{lircd_conf}="lircd.conf"
# Enable wake-on-usb for the USB remotes.
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", RUN+="lircd_wakeup_enable"
LABEL="end-usb" LABEL="end-usb"
ENV{lircd_driver}=="?*", ENV{lircd_conf}=="?*", RUN+="lircd_helper" ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service", RUN+="lircd_wakeup_enable"
# ACTION=="add", RUN+="/usr/bin/systemctl start lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service", RUN+="lircd_wakeup_enable"
ACTION=="remove", RUN+="/usr/bin/systemctl stop lircd@$name:$env{lircd_driver}:$env{lircd_conf}.service"
LABEL="end" LABEL="end"