From 1500ec504e44c3b2a3367c6bb54c1be865f7416e Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:23:15 +0000 Subject: [PATCH] Use actual locks instead of pgrep --- .local/bin/statusbar/sb-forecast | 4 ++-- .local/bin/statusbar/sb-iplocate | 6 +++--- .local/bin/statusbar/sb-moonphase | 4 ++-- .local/bin/statusbar/sb-price | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast index 91592ca8..07742dc7 100755 --- a/.local/bin/statusbar/sb-forecast +++ b/.local/bin/statusbar/sb-forecast @@ -49,8 +49,8 @@ case $BLOCK_BUTTON in esac checkforecast && showweather || - { [ -z "$(pgrep 'sb-forecast' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && getforecast; do sleep 60; done && pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}" ) & - echo; } + echo ) 9>/tmp/sb-forecast.lock diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate index 8cf17421..eaf1941f 100755 --- a/.local/bin/statusbar/sb-iplocate +++ b/.local/bin/statusbar/sb-iplocate @@ -9,11 +9,11 @@ ifinstalled "geoip" || exit 1 ipfile="$XDG_RUNTIME_DIR/iplocate" addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" || - { [ -z "$(pgrep 'sb-iplocate' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && - curl -sf ifconfig.me --output "$ipfile"; do sleep 60; done && + curl -sf api.ipify.org --output "$ipfile"; do sleep 60; done && pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } + echo; exit ) 9>/tmp/sb-iplocate.lock name="${addr##*, }" flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")" flag="${flag%% *}" diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase index 26e3f13f..ec059885 100755 --- a/.local/bin/statusbar/sb-moonphase +++ b/.local/bin/statusbar/sb-moonphase @@ -5,11 +5,11 @@ moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || - { [ -z "$(pgrep 'sb-moonphase' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"; do sleep 60; done && pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } + echo; exit ) 9>/tmp/sb-moonphase.lock icon="$(cat "$moonfile")" diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price index 94d25b9a..ce266c3a 100755 --- a/.local/bin/statusbar/sb-price +++ b/.local/bin/statusbar/sb-price @@ -51,11 +51,11 @@ esac updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")" else [ -n "$4" ] && - { [ -z "$(pgrep 'sb-price' | tail -n +3)" ] && + ( flock -n 9 && ( until { [ "$(cat /sys/class/net/w*/operstate)" = 'up' ] || [ "$(cat /sys/class/net/e*/operstate)" = 'up' ]; } && updateprice; do sleep 60; done && pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}" ) & - echo; exit; } || + echo; exit ) 9>/tmp/sb-price.lock || updateprice fi