Use actual locks instead of pgrep

This commit is contained in:
appeasementPolitik 2023-10-03 21:23:15 +00:00 committed by GitHub
parent b5317fdaf2
commit 1500ec504e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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%% *}"

View File

@ -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")"

View File

@ -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