sxmo_daemons: only run one process at a time

There seems to be a race somewhere in sxmo_demons that can cause it to
spawn multiple copies of a task. This patch does the equivalent of using
sxmo_uniq_exec, but it doesn't require changing all the calls to
sxmo_daemons.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
This commit is contained in:
ArenM
2023-02-15 21:12:19 -05:00
committed by Willow Barraco
parent d125c1b206
commit 89c8e5cae8

View File

@@ -4,11 +4,14 @@
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
. sxmo_common.sh
ROOT="$XDG_RUNTIME_DIR/sxmo_daemons"
mkdir -p "$ROOT"
exec 3<> "$ROOT/daemons.lock"
flock -x 3
list() {
find "$ROOT" -mindepth 1 -exec 'basename' '{}' ';'
}
@@ -79,8 +82,13 @@ start() {
fi
sxmo_debug "start $id"
"$@" &
printf "%s\n" "$!" > "$ROOT"/"$id"
(
# We need a subshell so we can close the lock fd, without
# releasing the lock
exec 3<&-
"$@" &
printf "%s\n" "$!" > "$ROOT"/"$id"
)
}
running() {