Prevent duplicate X11 session loops from killing Conky and daemonize Conky cleanly

This commit is contained in:
Luxferre
2026-10-25 16:18:43 +02:00
parent 651720b56b
commit 0aff8a3379
5 changed files with 24 additions and 10 deletions
@@ -89,7 +89,7 @@ if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then
fi
# Start the desktop widget (e.g. clock)
pidof -s conky >/dev/null 2>&1 || (DISPLAY=:0 CONKY_DPY=:0 setsid conky -c /home/user/.config/sxmo/conky.conf >/dev/null 2>&1 </dev/null &)
pidof -s conky >/dev/null 2>&1 || DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
# Monitor the battery
superctl start sxmo_battery_monitor
@@ -80,14 +80,27 @@ else
xset s off s noblank s 0 0 -dpms >/dev/null 2>&1 || true
fi
SESSION_PID_FILE="/tmp/bananarchy-x11-session.pid"
printf "%s\n" "$$" > "$SESSION_PID_FILE"
for old_pid in $(pgrep -f "/usr/bin/bananarchy-x11-session.sh" 2>/dev/null || true); do
if [ "$old_pid" != "$$" ] && [ "$old_pid" != "$PPID" ]; then
kill -9 "$old_pid" >/dev/null 2>&1 || true
fi
done
pkill -x dwm >/dev/null 2>&1 || true
trap 'rm -f "$SESSION_PID_FILE"; pkill -P $$ >/dev/null 2>&1 || true; exit 0' INT TERM HUP QUIT
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
(DISPLAY=:0 CONKY_DPY=:0 setsid conky -c /home/user/.config/sxmo/conky.conf >/dev/null 2>&1 </dev/null &)
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
pidof -s fcitx5 >/dev/null 2>&1 || fcitx5 -d >/tmp/fcitx5.log 2>&1 </dev/null &
sxmo_hook_start.sh >/tmp/sxmo_hook_start.log 2>&1 </dev/null &
first_iter=1
while :; do
while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
if pidof -s dwm >/dev/null 2>&1; then
exit 0
fi
xrdb -merge "$HOME/.Xresources" >/dev/null 2>&1 || true
WP_FILE="/usr/share/wallpapers/bananarchy.png"
if [ -f "$XDG_CONFIG_HOME/sxmo/wallpaper" ]; then
@@ -111,10 +124,13 @@ while :; do
sleep 0.05
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
(DISPLAY=:0 CONKY_DPY=:0 setsid conky -c /home/user/.config/sxmo/conky.conf >/dev/null 2>&1 </dev/null &)
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
pidof -s fcitx5 >/dev/null 2>&1 || fcitx5 -d >/tmp/fcitx5.log 2>&1 </dev/null &
fi
first_iter=0
dwm >/tmp/dwm.log 2>&1 || true
if [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" != "$$" ] || pidof -s dwm >/dev/null 2>&1; then
exit 0
fi
sleep 0.2
done
+1 -1
View File
@@ -68,7 +68,7 @@ setup_tz() {
export XDG_CONFIG_HOME="/home/user/.config"
sxmo_hook_statusbar.sh time >/dev/null 2>&1 || {
pkill -9 -x conky >/dev/null 2>&1 || true
(DISPLAY=:0 CONKY_DPY=:0 setsid conky -c /home/user/.config/sxmo/conky.conf >/dev/null 2>&1 </dev/null &)
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
}
' >/dev/null 2>&1 || true
fi
@@ -89,7 +89,7 @@ if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then
fi
# Start the desktop widget (e.g. clock)
pidof -s conky >/dev/null 2>&1 || (DISPLAY=:0 CONKY_DPY=:0 setsid conky -c /home/user/.config/sxmo/conky.conf >/dev/null 2>&1 </dev/null &)
pidof -s conky >/dev/null 2>&1 || DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
# Monitor the battery
superctl start sxmo_battery_monitor
@@ -26,10 +26,8 @@ restart_conky() {
pkill -x conky >/dev/null 2>&1 || true
sleep 0.05
pkill -9 -x conky >/dev/null 2>&1 || true
(
DISPLAY="${DISPLAY:-:0}" CONKY_DPY="${DISPLAY:-:0}" \
setsid conky -c "${XDG_CONFIG_HOME:-/home/user/.config}/sxmo/conky.conf" >/dev/null 2>&1 </dev/null &
)
DISPLAY="${DISPLAY:-:0}" CONKY_DPY="${DISPLAY:-:0}" \
conky -c "${XDG_CONFIG_HOME:-/home/user/.config}/sxmo/conky.conf" -d >/dev/null 2>&1 </dev/null || true
rmdir "$lockdir" 2>/dev/null || true
}