wok rev 12208

acpid: fix broken events handling
author Dominique Corbex <domcox@slitaz.org>
date Fri Mar 30 14:25:23 2012 +0200 (2012-03-30)
parents 9ffc10ecf210
children fa389f5b7eb9
files acpid/receipt acpid/stuff/acpi/acpi_handler.sh acpid/stuff/acpi/button.sh acpid/stuff/acpi/events/ac.conf acpid/stuff/acpi/events/ac_adapter acpid/stuff/acpi/events/battery.conf acpid/stuff/acpi/events/button.conf acpid/stuff/acpi/events/buttons acpid/stuff/acpi/power-supply.sh acpid/stuff/acpi_fakekey.c
line diff
     1.1 --- a/acpid/receipt	Fri Mar 30 00:41:00 2012 +0200
     1.2 +++ b/acpid/receipt	Fri Mar 30 14:25:23 2012 +0200
     1.3 @@ -1,35 +1,21 @@
     1.4  # SliTaz package receipt.
     1.5  
     1.6  PACKAGE="acpid"
     1.7 -VERSION="2.0.12"
     1.8 +VERSION="2.0.14"
     1.9  CATEGORY="system-tools"
    1.10 -SHORT_DESC="The ACPI event daemon"
    1.11 -MAINTAINER="domcox@users.sourceforge.net"
    1.12 +SHORT_DESC="The ACPI event daemon with netlink"
    1.13 +MAINTAINER="domcox@slitaz.org"
    1.14  TARBALL="$PACKAGE-$VERSION.tar.gz"
    1.15  WEB_SITE="http://tedfelix.com/linux/acpid-netlink.html"
    1.16  WGET_URL="http://www.tedfelix.com/linux/$TARBALL"
    1.17  KEY_FILE="key-constants"
    1.18  TAGS="power-management"
    1.19 +SUGGESTED="pm-utils"
    1.20  
    1.21  # Rules to configure and make the package.
    1.22  compile_rules()
    1.23  {
    1.24 -	# Build acpi_fakekey utility
    1.25 -	cp -a $stuff/acpi_fakekey.c .
    1.26 -	gcc -g -Wall -o acpi_fakekey acpi_fakekey.c
    1.27 -	# Generate key constants file
    1.28 -	INPUT_H="/usr/include/linux/input.h"
    1.29 -	echo -n '# Generated from $INPUT dated ' > $KEY_FILE
    1.30 -	date -r $INPUT_H >> $KEY_FILE
    1.31 -   	echo "KEY_RESERVED=0" >> $KEY_FILE
    1.32 -	awk '/define KEY_/{if($3 <= 255 && $3 > 0) print $2"="$3}' $INPUT_H | sort -nt'=' -k2 >> $KEY_FILE
    1.33 -	echo "KEY_LOCK=\$KEY_COFFEE" >> $KEY_FILE
    1.34 -	echo "KEY_LIGHT=\$KEY_F19" >> $KEY_FILE
    1.35 -	echo "KEY_VIDEOOUT=\$KEY_F20" >> $KEY_FILE
    1.36 -	echo "KEY_ROTATESCREEN=\$KEY_F21" >> $KEY_FILE
    1.37 -	echo "KEY_VIDEOMODECYCLE=\$KEY_F22" >> $KEY_FILE
    1.38 -	echo "KEY_PRESENTATION=\KEY_F23" >> $KEY_FILE
    1.39 -	# Build acpid
    1.40 +	# Build
    1.41  	cd $src
    1.42  	make clean && make
    1.43  	make DESTDIR=$DESTDIR install
    1.44 @@ -47,28 +33,26 @@
    1.45  	mkdir -p $fs/etc
    1.46  	cp -a $stuff/init.d $fs/etc/
    1.47  	cp -a $stuff/acpi $fs/etc/
    1.48 -	# acpi_fakekey
    1.49 -	cp -a $src/acpi_fakekey $fs/usr/bin
    1.50 -	cp -a $src/$KEY_FILE $fs/etc/acpi/
    1.51 +	chmod go-rwx $fs/etc/acpi/*.sh
    1.52 +	chmod go-rwx $fs/etc/acpi/events/*
    1.53  }
    1.54  
    1.55 -# Pre and post remove commands for Tazpkg                                                                              
    1.56 +# Pre and post remove commands for Tazpkg
    1.57 +post_install()
    1.58 +{
    1.59 +	local root
    1.60 +	root=$1
    1.61 +	if [ -z "$root" ]; then
    1.62 +		/etc/init.d/acpid start || continue
    1.63 +	fi
    1.64 +	if ! grep -q ^ACPID_OPTIONS $root/etc/daemons.conf; then
    1.65 +		echo '# ACPI daemon options.' >> $root/etc/daemons.conf
    1.66 +		echo 'ACPID_OPTIONS=""' >> $root/etc/daemons.conf
    1.67 +		echo '' >> $root/etc/daemons.conf
    1.68 +	fi
    1.69 +}	
    1.70  
    1.71  pre_remove()
    1.72  {
    1.73  	/etc/init.d/acpid stop
    1.74  }
    1.75 -
    1.76 -post_remove()
    1.77 -{
    1.78 -	if [ `ls /etc/acpi/events | wc -l` -eq 0 ]; then
    1.79 -		echo -n "Removing /etc/acpi/events"
    1.80 -		rm -rf /etc/acpi/events
    1.81 -		status
    1.82 -	fi
    1.83 -	if [ `ls /etc/acpi | wc -l` -eq 0 ]; then
    1.84 -		echo -n "Removing /etc/acpi"
    1.85 -		rm -rf /etc/acpi
    1.86 -		status
    1.87 -	fi
    1.88 -}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/acpid/stuff/acpi/acpi_handler.sh	Fri Mar 30 14:25:23 2012 +0200
     2.3 @@ -0,0 +1,31 @@
     2.4 +#!/bin/sh
     2.5 +# A script for handling ACPI events.
     2.6 +# See events/*.conf for a configuration file that can be used to
     2.7 +# run this script.
     2.8 +
     2.9 +if [ $# != 1 ]; then
    2.10 +	exit 1
    2.11 +fi
    2.12 +set $*
    2.13 +
    2.14 +case "$1" in
    2.15 +	button/lid)
    2.16 +		[ -e /usr/sbin/pm-suspend ] && /usr/sbin/pm-suspend \
    2.17 +		|| logger "acpid: pm-suspend not found, skipping.." ;;
    2.18 +	ac_adapter)
    2.19 +		case "$2" in
    2.20 +		 AC*|AD*)
    2.21 +			case "$4" in
    2.22 +				00000000) # disconnected
    2.23 +					[ -e /usr/sbin/pm-powersave ] \
    2.24 +					&& /usr/sbin/pm-powersave battery \
    2.25 +					|| logger "acpid: pm-powersave not found, skipping.." ;;
    2.26 +				00000001) # connected
    2.27 +					[ -e /usr/sbin/pm-powersave ] \
    2.28 +					&& /usr/sbin/pm-powersave ac \
    2.29 +					|| logger "acpid: pm-powersave not found, skipping.." ;;
    2.30 +            esac ;;
    2.31 +		esac ;;
    2.32 +	*) 
    2.33 +		logger "acpid: action $1 $2 is not defined" ;;
    2.34 +esac
     3.1 --- a/acpid/stuff/acpi/button.sh	Fri Mar 30 00:41:00 2012 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,39 +0,0 @@
     3.4 -#!/bin/sh
     3.5 -# button.sh - Managing button events for SliTaz
     3.6 -# 
     3.7 -
     3.8 -source /etc/acpi/key-constants
     3.9 -
    3.10 -# logger "button.sh: event=$1"
    3.11 -
    3.12 -# take care about the way events are reported
    3.13 -
    3.14 -EVENT_TYPE=`echo $1 | cut -d/ -f1`
    3.15 -if [ $EVENT_TYPE = $1 ]; then
    3.16 -	EVENT=$2
    3.17 -else
    3.18 -	EVENT=`echo "$1" | cut -d/ -f2`
    3.19 -fi
    3.20 -
    3.21 -case $EVENT in
    3.22 -	power)
    3.23 -		logger "Event: button/power - sending KEY_EXIT($KEY_EXIT)"
    3.24 -		/usr/bin/acpi_fakekey $KEY_EXIT
    3.25 -	;;
    3.26 -	lid)
    3.27 -		if [ -e /usr/bin/suspend ] ; then
    3.28 -			logger "Event: button/lid - suspending"
    3.29 -			/usr/bin/suspend
    3.30 -		else
    3.31 -			logger "Event: button/lid - /usr/bin/suspend not found, skipping.."
    3.32 -		fi
    3.33 -	;;
    3.34 -	sleep)
    3.35 -		if [ -e /usr/bin/hibernate ] ; then
    3.36 -			logger "Event: button/sleep - hibernating"
    3.37 -			/usr/bin/hibernate
    3.38 -		else
    3.39 -			logger "Event: button/sleep - /usr/bin/hibernate not found, skipping.."
    3.40 -		fi
    3.41 -	;;
    3.42 -esac
     4.1 --- a/acpid/stuff/acpi/events/ac.conf	Fri Mar 30 00:41:00 2012 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,6 +0,0 @@
     4.4 -# /etc/acpi/event/ac.conf
     4.5 -# ac power events
     4.6 -
     4.7 -event=ac_adapter
     4.8 -action=/etc/acpi/power-supply.sh
     4.9 -
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/acpid/stuff/acpi/events/ac_adapter	Fri Mar 30 14:25:23 2012 +0200
     5.3 @@ -0,0 +1,5 @@
     5.4 +# /etc/acpi/event/ac.conf
     5.5 +# ac power events
     5.6 +event=ac_adapter .*
     5.7 +action=/etc/acpi/acpi_handler.sh "%e"
     5.8 +
     6.1 --- a/acpid/stuff/acpi/events/battery.conf	Fri Mar 30 00:41:00 2012 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,6 +0,0 @@
     6.4 -# /etc/acpi/event/battery.conf
     6.5 -# Battery events
     6.6 -
     6.7 -event=battery
     6.8 -action=/etc/acpi/power-supply.sh
     6.9 -
     7.1 --- a/acpid/stuff/acpi/events/button.conf	Fri Mar 30 00:41:00 2012 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,6 +0,0 @@
     7.4 -# /etc/acpi/event/button
     7.5 -# lid, sleep or power button events
     7.6 -
     7.7 -event=button
     7.8 -action=/etc/acpi/button.sh %e
     7.9 -
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/acpid/stuff/acpi/events/buttons	Fri Mar 30 14:25:23 2012 +0200
     8.3 @@ -0,0 +1,5 @@
     8.4 +# /etc/acpi/event/button
     8.5 +# lid, sleep or power button events
     8.6 +event=button.*
     8.7 +action=/etc/acpi/acpi_handler.sh "%e"
     8.8 +
     9.1 --- a/acpid/stuff/acpi/power-supply.sh	Fri Mar 30 00:41:00 2012 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,235 +0,0 @@
     9.4 -#!/bin/sh
     9.5 -# /etc/acpi/power-supply.sh - Managing power events for SliTaz
     9.6 -# For Tips & Tricks see http://www.lesswatts.org
     9.7 -
     9.8 -# This script turns off power savings mode on ac or when the 
     9.9 -# battery almost runs out in a attempt to limit data loss in
    9.10 -# a case of power failure.
    9.11 -
    9.12 -ENABLED=1
    9.13 -DISABLED=0
    9.14 -
    9.15 -# AC status (from /sys/class/power_supply/online)
    9.16 -ON_LINE=1
    9.17 -OFF_LINE=0
    9.18 -
    9.19 -# Battery status 
    9.20 -LOW_BAT=0
    9.21 -HIGH_BAT=1
    9.22 -
    9.23 -# Determining the power state.
    9.24 -
    9.25 -ac_status()
    9.26 -{
    9.27 -	POWER_SUPPLY_MAINS=$DISABLED
    9.28 -	AC_STATUS=$OFF_LINE
    9.29 -	for POWER_SUPPLY in /sys/class/power_supply/* ; do
    9.30 -		if [ -f $POWER_SUPPLY/type ] ; then
    9.31 -			if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ] ;then
    9.32 -				echo -n "Determining power state from $POWER_SUPPLY: "
    9.33 -				POWER_SUPPLY_MAINS=$ENABLED
    9.34 -				if [ "$(cat $POWER_SUPPLY/online)" = 1 ] ; then
    9.35 -					AC_STATUS=$ON_LINE
    9.36 -					echo "on-line"
    9.37 -				else
    9.38 -					echo "off-line"
    9.39 -				fi
    9.40 -			fi
    9.41 -		fi
    9.42 -	done
    9.43 -	if [ $POWER_SUPPLY_MAINS -eq $DISABLED ] ; then
    9.44 -		$AC_STATUS=$ON_LINE
    9.45 -	fi
    9.46 -}
    9.47 -
    9.48 -# Determining the battery state.
    9.49 -
    9.50 -battery_status()
    9.51 -{
    9.52 -	BATTERY_STATUS=$LOW_BAT
    9.53 -	for BATT in /sys/class/power_supply/* ; do
    9.54 -		BATT_TYPE=$(cat $BATT/type)
    9.55 -		echo "$BATT is of type $BATT_TYPE."
    9.56 -		if [ "$BATT_TYPE" = "Battery" ] ; then
    9.57 -			echo "  Checking levels for $BATT."
    9.58 -			# Only do if the battery is present
    9.59 -	        if [ $(cat $BATT/present) -eq 1 ] ; then
    9.60 -
    9.61 -				# Get the remaining capacity.
    9.62 -				if [ -f $BATT/charge_now ] ; then
    9.63 -					REMAINING=$(cat $BATT/charge_now)
    9.64 -				elif [ -f $BATT/energy_now ] ; then
    9.65 -					REMAINING=$(cat $BATT/energy_now)
    9.66 -				else
    9.67 -					REMAINING=0
    9.68 -				fi
    9.69 -				if [ -z "$REMAINING" -o "$REMAINING" -eq 0 ] ; then
    9.70 -					echo "  Battery does not report remaining charge. Perhaps it is not present?"
    9.71 -				else
    9.72 -					echo "  Remaining charge: $REMAINING"
    9.73 -
    9.74 -					# Get the alarm level
    9.75 -					ALARM_LEVEL=$(cat $BATT/alarm)
    9.76 -					if [ "$ALARM_LEVEL" -eq 0 ] ; then
    9.77 -
    9.78 -						# Get the full capacity.
    9.79 -
    9.80 -						if [ -f $BATT/charge_full_design ] ; then
    9.81 -							CAPACITY=$(cat $BATT/charge_full_design)
    9.82 -						elif [ -f $BATT/energy_full_design ] ; then
    9.83 -							CAPACITY=$(cat $BATT/energy_full_design)
    9.84 -						else
    9.85 -							CAPACITY=0
    9.86 -						fi
    9.87 -						if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0 ] ; then
    9.88 -							echo "  Battery does not report design full charge, using non-design full charge."
    9.89 -
    9.90 -							if [ -f $BATT/charge_full ] ; then
    9.91 -								CAPACITY=$(cat $BATT/charge_full)
    9.92 -							elif [ -f $BATT/energy_full_design ] ; then
    9.93 -								CAPACITY=$(cat $BATT/energy_full)
    9.94 -							else
    9.95 -								CAPACITY=0
    9.96 -							fi
    9.97 -							if [ -z "$CAPACITY" -o "$CAPACITY" -eq 0] ; then
    9.98 -								echo "  Battery does not report non-design full charge."
    9.99 -							fi
   9.100 -						fi
   9.101 -						echo "  Full capacity: $CAPACITY"
   9.102 -						ALARM_LEVEL=$((CAPACITY*5/100))
   9.103 -					fi
   9.104 -					echo "  Alarm level: $ALARM_LEVEL"
   9.105 -					if [ "$ALARM_LEVEL" -ne 0 ] ; then
   9.106 -						if [ "$REMAINING" -ge "$ALARM_LEVEL" ] ; then
   9.107 -							# this battery does count as having enough charge.
   9.108 -							BATTERY_STATUS=$HIGH_BAT
   9.109 -							echo "  Battery status: high"
   9.110 -						else
   9.111 -							echo "  Battery status: low"
   9.112 -						fi
   9.113 -					fi
   9.114 -				fi
   9.115 -			else
   9.116 -				echo "Battery is not present."
   9.117 -			fi
   9.118 -		fi
   9.119 -	done
   9.120 -}
   9.121 -
   9.122 -online_mode()
   9.123 -{
   9.124 -	# Disable laptop mode
   9.125 -	# When laptop mode is enabled, the kernel will try to be smart
   9.126 -	# about when to do IO, to give the disk and the SATA links as
   9.127 -	# much time as possible in a low power state.
   9.128 -
   9.129 -	if [ -e /proc/sys/vm/laptop_mode ] ; then
   9.130 -		echo "Disabling laptop mode"
   9.131 -		echo 0 > /proc/sys/vm/laptop_mode
   9.132 -	fi
   9.133 -
   9.134 -	# AC97 audio power saving mode
   9.135 -	# The AC97 onboard audio chips support power saving, where the
   9.136 -	# analog parts (codec) are powered down when no program is using
   9.137 -	# the audio device.
   9.138 -
   9.139 -	if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then
   9.140 -		echo "Disabling AC97 audio power saving mode"
   9.141 -		echo 0 > /sys/module/snd_ac97_codec/parameters/power_save
   9.142 -	fi
   9.143 -
   9.144 -	# The VM writeback time
   9.145 -	# The VM subsystem caching allows the kernel to group consecutive
   9.146 -	# writes into one big write, and to generally optimize the disk IO
   9.147 -	# to be the most efficient. 
   9.148 -
   9.149 -	if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then
   9.150 -		echo "Writeback time reset to 500ms"
   9.151 -		echo 500 > /proc/sys/vm/dirty_writeback_centisecs
   9.152 -	fi
   9.153 -}
   9.154 -
   9.155 -offline_mode()
   9.156 -{
   9.157 -	# Enable laptop mode
   9.158 -	# When laptop mode is enabled, the kernel will try to be smart
   9.159 -	# about when to do IO, to give the disk and the SATA links as
   9.160 -	# much time as possible in a low power state. 
   9.161 -
   9.162 -	if [ ! -e /proc/sys/vm/laptop_mode ] ; then
   9.163 -		echo "Kernel does not have support for laptop mode." 
   9.164 -	else
   9.165 -		echo "Enabling laptop mode"
   9.166 -		echo 5 > /proc/sys/vm/laptop_mode
   9.167 -	fi
   9.168 -
   9.169 -	# AC97 audio power saving mode
   9.170 -	# The AC97 onboard audio chips support power saving, where the
   9.171 -	# analog parts (codec) are powered down when no program is using
   9.172 -	# the audio device.
   9.173 -
   9.174 -	if [ -e /sys/module/snd_ac97_codec/parameters/power_save ] ; then
   9.175 -		echo "Enabling AC97 audio power saving mode"
   9.176 -		echo 1 > /sys/module/snd_ac97_codec/parameters/power_save
   9.177 -		echo 1 > /dev/dsp
   9.178 -	fi
   9.179 -
   9.180 -	# The VM writeback time
   9.181 -	# The VM subsystem caching allows the kernel to group consecutive
   9.182 -	# writes into one big write, and to generally optimize the disk IO
   9.183 -	# to be the most efficient.
   9.184 -
   9.185 -	if [ -e /proc/sys/vm/dirty_writeback_centisecs ] ; then
   9.186 -		echo "Writeback time set to 1500ms"
   9.187 -		echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
   9.188 -	fi
   9.189 -}
   9.190 -
   9.191 -power_status()
   9.192 -{
   9.193 -	if [ $(cat /proc/sys/vm/dirty_writeback_centisecs) -gt 1000 ]; then
   9.194 -		POWER_SAVINGS=$ENABLED
   9.195 -		echo "power-savings-mode enabled"
   9.196 -	else
   9.197 -		POWER_SAVINGS=$DISABLED
   9.198 -		echo "power-savings-mode disabled"
   9.199 -	fi
   9.200 -}
   9.201 -
   9.202 -custom_scripts()
   9.203 -{
   9.204 -	# Custom scripts in /etc/acpi/ac.d
   9.205 -
   9.206 -	if [ -d /etc/acpi/ac.d ]; then
   9.207 -		for SCRIPT in /etc/acpi/ac.d/*.sh; do
   9.208 -			. $SCRIPT $AC_STATUS $BATTERY_STATUS $0
   9.209 -		done
   9.210 -	fi
   9.211 -
   9.212 -	# Custom scripts in /etc/acpi/battery.d
   9.213 -
   9.214 -	if [ -d /etc/acpi/battery.d ]; then
   9.215 -		for SCRIPT in /etc/acpi/battery.d/*.sh; do
   9.216 -			. $SCRIPT $AC_STATUS $BATTERY_STATUS $0
   9.217 -		done
   9.218 -	fi
   9.219 -}
   9.220 -
   9.221 -ac_status
   9.222 -battery_status
   9.223 -power_status
   9.224 -case "$AC_STATUS+$BATTERY_STATUS" in
   9.225 -	"$OFF_LINE+$HIGH_BAT")
   9.226 -		if [ $POWER_SAVINGS = $DISABLED ]; then 
   9.227 -			logger "Start power savings mode"
   9.228 -			offline_mode
   9.229 -		fi
   9.230 -	;;
   9.231 -	*)
   9.232 -		if [ $POWER_SAVINGS = $ENABLED ]; then
   9.233 -			logger "Stop power savings mode"
   9.234 -			online_mode
   9.235 -		fi
   9.236 -	;;
   9.237 -esac
   9.238 -custom_scripts
   9.239 \ No newline at end of file
    10.1 --- a/acpid/stuff/acpi_fakekey.c	Fri Mar 30 00:41:00 2012 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,64 +0,0 @@
    10.4 -#include <unistd.h>
    10.5 -#include <fcntl.h>
    10.6 -#include <string.h>
    10.7 -#include <stdlib.h>
    10.8 -#include <stdio.h>
    10.9 -#include <linux/input.h>
   10.10 -
   10.11 -#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))
   10.12 -
   10.13 -int find_keyboard() {
   10.14 -	int i, j;
   10.15 -        int fd;
   10.16 -        char filename[32];
   10.17 -        char key_bitmask[(KEY_MAX + 7) / 8];
   10.18 -
   10.19 -        for (i=0; i<32; i++) {
   10.20 -                snprintf(filename,sizeof(filename), "/dev/input/event%d", i);
   10.21 -
   10.22 -                fd = open(filename, O_RDWR);
   10.23 -                ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
   10.24 -
   10.25 -		for (j = 0; j < BTN_MISC; j++) {
   10.26 -			if (TestBit(j, key_bitmask))
   10.27 -				break;
   10.28 -		}
   10.29 -
   10.30 -                if (j < BTN_MISC) {
   10.31 -                        return fd;
   10.32 -                }
   10.33 -		close (fd);
   10.34 -        }
   10.35 -        return 0;
   10.36 -}
   10.37 -
   10.38 -int main(int argc, char** argv) {
   10.39 -	int fd;
   10.40 -	int key;
   10.41 -	struct input_event event;
   10.42 -
   10.43 -	if (argc == 2) {
   10.44 -		key = atoi(argv[1]);
   10.45 -	} else {
   10.46 -		return 1;
   10.47 -	}
   10.48 -
   10.49 -	fd = find_keyboard();
   10.50 -
   10.51 -	if (!fd) {
   10.52 -		return 2;
   10.53 -	}
   10.54 -
   10.55 -	event.type = EV_KEY;
   10.56 -	event.code = key;
   10.57 -	event.value = 1;
   10.58 -	write(fd, &event, sizeof event);
   10.59 -
   10.60 -	event.type = EV_KEY;
   10.61 -	event.code = key;
   10.62 -	event.value = 0;
   10.63 -	write(fd, &event, sizeof event);
   10.64 -	
   10.65 -	return 0;
   10.66 -}
   10.67 -