More updates to the watchdog.
This commit is contained in:
+28
-5
@@ -19,6 +19,7 @@ timeoutSeconds=2 # Consider i3 locked if it doesn't respond within 2 seconds
|
||||
pidFile="${HOME}/.config/i3/i3_watchdog.pid"
|
||||
logFile="/tmp/i38-i3-watchdog-${UID}.log"
|
||||
maxLogBytes=262144
|
||||
displayFailureLimit=3
|
||||
|
||||
rotate_log() {
|
||||
local logSize
|
||||
@@ -53,6 +54,20 @@ check_health() {
|
||||
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
|
||||
if [[ -f "$pidFile" ]]; then
|
||||
oldPid=$(cat "$pidFile")
|
||||
@@ -64,20 +79,28 @@ fi
|
||||
|
||||
# Write our PID
|
||||
echo "$$" > "$pidFile"
|
||||
trap cleanup_pid_file EXIT
|
||||
|
||||
log_message "I38 Watchdog started (PID: $$)"
|
||||
|
||||
lastSuccessTime=$(date +%s)
|
||||
consecutiveFailures=0
|
||||
consecutiveDisplayFailures=0
|
||||
|
||||
while true; do
|
||||
sleep "$checkInterval"
|
||||
|
||||
# Check if i3 is still running
|
||||
if ! pgrep -x i3 > /dev/null; then
|
||||
log_message "i3 process not found - exiting watchdog"
|
||||
rm -f "$pidFile"
|
||||
exit 0
|
||||
# An i3 restart leaves X available and launches a replacement watchdog via
|
||||
# exec_always. Only exit when the X session itself is no longer available.
|
||||
if check_x_display; then
|
||||
consecutiveDisplayFailures=0
|
||||
else
|
||||
((consecutiveDisplayFailures++))
|
||||
if [[ $consecutiveDisplayFailures -ge $displayFailureLimit ]]; then
|
||||
log_message "X display unavailable for $consecutiveDisplayFailures consecutive checks - exiting watchdog"
|
||||
exit 0
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
|
||||
# Try to communicate with i3 IPC AND check X focus
|
||||
|
||||
Reference in New Issue
Block a user