More updates to the watchdog.

This commit is contained in:
Storm Dragon
2026-09-14 09:45:47 -04:00
parent fc08e505b2
commit 1d20d95b26
+27 -4
View File
@@ -19,6 +19,7 @@ timeoutSeconds=2 # Consider i3 locked if it doesn't respond within 2 seconds
pidFile="${HOME}/.config/i3/i3_watchdog.pid" pidFile="${HOME}/.config/i3/i3_watchdog.pid"
logFile="/tmp/i38-i3-watchdog-${UID}.log" logFile="/tmp/i38-i3-watchdog-${UID}.log"
maxLogBytes=262144 maxLogBytes=262144
displayFailureLimit=3
rotate_log() { rotate_log() {
local logSize local logSize
@@ -53,6 +54,20 @@ check_health() {
fi fi
} }
check_x_display() {
timeout 1 xdotool getmouselocation > /dev/null 2>&1
}
cleanup_pid_file() {
local recordedPid
[[ -r "$pidFile" ]] || return 0
read -r recordedPid < "$pidFile"
if [[ "$recordedPid" == "$$" ]]; then
rm -f -- "$pidFile"
fi
}
# Kill any existing watchdog instances # Kill any existing watchdog instances
if [[ -f "$pidFile" ]]; then if [[ -f "$pidFile" ]]; then
oldPid=$(cat "$pidFile") oldPid=$(cat "$pidFile")
@@ -64,21 +79,29 @@ fi
# Write our PID # Write our PID
echo "$$" > "$pidFile" echo "$$" > "$pidFile"
trap cleanup_pid_file EXIT
log_message "I38 Watchdog started (PID: $$)" log_message "I38 Watchdog started (PID: $$)"
lastSuccessTime=$(date +%s) lastSuccessTime=$(date +%s)
consecutiveFailures=0 consecutiveFailures=0
consecutiveDisplayFailures=0
while true; do while true; do
sleep "$checkInterval" sleep "$checkInterval"
# Check if i3 is still running # An i3 restart leaves X available and launches a replacement watchdog via
if ! pgrep -x i3 > /dev/null; then # exec_always. Only exit when the X session itself is no longer available.
log_message "i3 process not found - exiting watchdog" if check_x_display; then
rm -f "$pidFile" consecutiveDisplayFailures=0
else
((consecutiveDisplayFailures++))
if [[ $consecutiveDisplayFailures -ge $displayFailureLimit ]]; then
log_message "X display unavailable for $consecutiveDisplayFailures consecutive checks - exiting watchdog"
exit 0 exit 0
fi fi
continue
fi
# Try to communicate with i3 IPC AND check X focus # Try to communicate with i3 IPC AND check X focus
check_health check_health