switched to implementation with pipe due to possible race conditions

This commit is contained in:
root 2017-02-23 11:49:57 +00:00
parent 79098d7e62
commit 468576ecd0
2 changed files with 10 additions and 13 deletions

View File

@ -1,7 +1,6 @@
#!/bin/bash
COMMAND_FILE=/tmp/command
COMMAND_FILE_TMP=/tmp/command_tmp
lounge_light() {
echo "not implemented"
@ -12,13 +11,12 @@ lounge_light_toggle() {
}
cd "$(dirname $0)"
touch "$COMMAND_FILE"
chmod -f 666 "$COMMAND_FILE"
while inotifywait -qq -e close_write "$COMMAND_FILE"; do
mv "$COMMAND_FILE" "$COMMAND_FILE_TMP"
sleep .1 # wait for possible further/parallel writes to end
rm -f $COMMAND_FILE
mkfifo $COMMAND_FILE
chmod 666 $COMMAND_FILE
while true; do
while IFS='' read -r line || [[ -n "$line" ]]; do
echo "Text read from file: $line"
echo "command received: $line"
case "$line" in
lounge_light_toggle)
lounge_light_toggle
@ -31,8 +29,5 @@ while inotifywait -qq -e close_write "$COMMAND_FILE"; do
echo "lounge_light lounge_light_toggle" >&2
;;
esac
done < "$COMMAND_FILE_TMP"
rm "$COMMAND_FILE_TMP"
touch "$COMMAND_FILE"
chmod -f 666 "$COMMAND_FILE"
done < "$COMMAND_FILE"
done

View File

@ -6,8 +6,10 @@
# command="/home/automation/chch-power/shell.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAA...
COMMAND_FILE=/tmp/command
touch $COMMAND_FILE
chmod -f 666 $COMMAND_FILE
if [ ! -p $COMMAND_FILE ]; then
echo "ERROR; command watcher not listening:" >&2
exit 1
fi
status() {
STATUS="$(cat /tmp/status)"