From 7559984430d3ce512eb0202e7fac7ade5b074bc0 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Thu, 20 Aug 2020 19:47:08 -0500 Subject: [PATCH] Fix sxmo_notificationmonitor.sh to ensure script running doesnt overlap; (kill) --- scripts/core/sxmo_notificationmonitor.sh | 36 ++++++++++++++---------- scripts/core/sxmo_notificationwrite.sh | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/scripts/core/sxmo_notificationmonitor.sh b/scripts/core/sxmo_notificationmonitor.sh index a876efe..1ccbe39 100755 --- a/scripts/core/sxmo_notificationmonitor.sh +++ b/scripts/core/sxmo_notificationmonitor.sh @@ -1,6 +1,12 @@ #!/usr/bin/env sh +trap gracefulexit INT TERM NOTIFDIR="$XDG_CONFIG_HOME"/sxmo/notifications +gracefulexit() { + echo "Gracefully exiting $0" + kill -9 0 +} + notificationhook() { if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/notification ]; then "$XDG_CONFIG_HOME"/sxmo/hooks/notification @@ -42,24 +48,24 @@ recreateexistingnotifs() { monitorforaddordelnotifs() { while true; do - INOTIFYOUTPUT="$( - inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ - )" - INOTIFYEVENTTYPE="$(echo "$INOTIFYOUTPUT" | cut -d" " -f2)" - - case "$INOTIFYEVENTTYPE" in - "CREATE"|"MOVED_TO") - NOTIFFILE="$NOTIFDIR/$(echo "$INOTIFYOUTPUT" | cut -d" " -f3)" - handlenewnotiffile "$NOTIFFILE" - ;; - "DELETE"|"DELETE_SELF"|"MOVED_FROM") - # E.g. if no more notifications unset LED - find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0 - ;; - esac + inotifywait -e create,moved_to,delete,delete_self,moved_from "$NOTIFDIR"/ | ( + INOTIFYOUTPUT="$(cat)" + INOTIFYEVENTTYPE="$(echo "$INOTIFYOUTPUT" | cut -d" " -f2)" + case "$INOTIFYEVENTTYPE" in + "CREATE"|"MOVED_TO") + NOTIFFILE="$NOTIFDIR/$(echo "$INOTIFYOUTPUT" | cut -d" " -f3)" + handlenewnotiffile "$NOTIFFILE" + ;; + "DELETE"|"DELETE_SELF"|"MOVED_FROM") + # E.g. if no more notifications unset LED + find "$NOTIFDIR"/ -type f -mindepth 1 | read -r || sxmo_setpineled green 0 + ;; + esac + ) & wait done } +pgrep -f "$(command -v sxmo_notificationmonitor.sh)" | grep -Ev "^${$}$" | xargs kill sxmo_setpineled green 0 recreateexistingnotifs monitorforaddordelnotifs diff --git a/scripts/core/sxmo_notificationwrite.sh b/scripts/core/sxmo_notificationwrite.sh index ba6b8af..5061f9f 100755 --- a/scripts/core/sxmo_notificationwrite.sh +++ b/scripts/core/sxmo_notificationwrite.sh @@ -17,7 +17,7 @@ writenotification() { if [ "$NOTIFFILEPATHTOWRITE" = "random" ]; then NOTIFFILEPATHTOWRITE="$NOTIFDIR/$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 10)" fi - rm -f "$NOTIFFILEPATHTOWRITE" + touch "$NOTIFFILEPATHTOWRITE" printf %b "$ACTION\n$WATCHFILE\n$NOTIFMSG\n" > "$NOTIFFILEPATHTOWRITE" }