File tree Expand file tree Collapse file tree
root/etc/s6-overlay/s6-rc.d/svc-de Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /etc/s6-overlay/s6-rc.d/svc-de/finish
Original file line number Diff line number Diff line change 1+ #!/usr/bin/with-contenv bash
2+
3+ # exit early if no pid file
4+ PID_FILE="/de-pid"
5+ WAIT_SECONDS=5
6+ if [ ! -r "$PID_FILE" ]; then
7+ exit 0
8+ fi
9+ PARENT_PID=$(cat "$PID_FILE")
10+ if [ -z "$PARENT_PID" ]; then
11+ rm -f "$PID_FILE"
12+ exit 0
13+ fi
14+
15+ # get all descendant pids of de
16+ PIDS_TO_KILL=$(pstree -p "$PARENT_PID" | grep -o '([0-9]\+)' | grep -o '[0-9]\+' | grep -v "^${PARENT_PID}$")
17+
18+ # kill all descendant pids
19+ if [ -z "$PIDS_TO_KILL" ]; then
20+ echo "No desktop processes found to terminate."
21+ else
22+ echo "$PIDS_TO_KILL" | xargs --no-run-if-empty kill -TERM -- 2>/dev/null
23+ echo "Waiting up to ${WAIT_SECONDS} seconds for desktop processes to terminate..."
24+ for ((i=0; i < WAIT_SECONDS * 4; i++)); do
25+ all_gone=1
26+ for pid in $PIDS_TO_KILL; do
27+ if kill -0 "$pid" 2>/dev/null; then
28+ all_gone=0
29+ break
30+ fi
31+ done
32+ if [ "$all_gone" -eq 1 ]; then
33+ echo "All desktop processes terminated cleanly."
34+ break
35+ fi
36+ sleep 0.25
37+ done
38+ if [ "$all_gone" -eq 0 ]; then
39+ echo "Timeout reached. Handing off to s6 for final termination."
40+ fi
41+ fi
42+
43+ # clean up the PID file.
44+ rm -f "$PID_FILE"
45+
46+ exit 0
Original file line number Diff line number Diff line change @@ -26,4 +26,7 @@ chmod 777 /tmp/selkies*
2626# run
2727cd $HOME
2828exec s6-setuidgid abc \
29- /bin/bash /defaults/startwm.sh
29+ /bin/bash /defaults/startwm.sh &
30+ PID=$!
31+ echo "$PID" > /de-pid
32+ wait "$PID"
You can’t perform that action at this time.
0 commit comments