Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zygisk/module/daemon
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ fi

[ "$debug" = "true" ] && log -p d -t "Vector" "Starting daemon $*"

# Launch the daemon
exec /system/bin/app_process $java_options /system/bin --nice-name=lspd org.matrix.vector.daemon.VectorDaemon "$@" >/dev/null 2>&1
# Launch the daemon (no exec so the watchdog loop in service.sh can restart it)
/system/bin/app_process $java_options /system/bin --nice-name=lspd org.matrix.vector.daemon.VectorDaemon "$@" >/dev/null 2>&1
32 changes: 29 additions & 3 deletions zygisk/module/service.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Extract the directory path and change directory
# Extract the directory path and change directory
MODDIR="${0%/*}"
cd "$MODDIR" || exit 1

# Start the daemon directly in the background within a private mount namespace
unshare --propagation slave -m "$MODDIR/daemon" --system-server-max-retry=3 "$@" &
# Watchdog loop: automatically restart the daemon if it crashes.
# Each iteration creates a fresh mount namespace (unshare -m), so no stale
# mount points accumulate.
#
# Rate-limiting: if the daemon crashes more than 3 times within any 60-second
# window the watchdog enters a 3-minute cooldown before retrying, then resets
# the counter. Otherwise it restarts after a 5-second pause.
fails=0
window_start=$(date +%s)
while true; do
unshare --propagation slave -m "$MODDIR/daemon" --system-server-max-retry=3 "$@"
# daemon exited (crashed)
now=$(date +%s)
fails=$((fails + 1))
if [ $((now - window_start)) -le 60 ] && [ $fails -gt 3 ]; then
# exceeded crash budget → cooldown
sleep 180
fails=0
window_start=$(date +%s)
elif [ $((now - window_start)) -gt 60 ]; then
# window expired, reset
fails=1
window_start=$now
sleep 5
else
sleep 5
fi
done &