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: 4 additions & 0 deletions bin/omarchy-launch-shell
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# omarchy:summary=Launch the Omarchy shell with its log kept in the journal
# omarchy:hidden=true

# Drop dead Quickshell instance dirs before a new one starts writing. Stale
# by-id logs otherwise grow without bound on the user runtime tmpfs.
omarchy-quickshell-prune-logs >/dev/null 2>&1 || true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Crash relaunches skip pruning When Quickshell crashes and this launcher starts it again, execution returns to the loop below, not to this prune call. Each crashed instance can leave another log directory behind until a separate launcher process starts, so logs can keep accumulating during repeated relaunches.


# Quickshell only logs to its instance runtime dir (tmpfs), so when the shell
# dies the idle/lock event trail is gone after a reboot. The journal keeps it
# across sessions, bounded and timestamped, under the omarchy-shell tag.
Expand Down
46 changes: 46 additions & 0 deletions bin/omarchy-quickshell-prune-logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# omarchy:summary=Prune stale Quickshell instance log dirs under the user runtime tmpfs
# omarchy:hidden=true

# Each Quickshell instance writes under $XDG_RUNTIME_DIR/quickshell/by-id/ and
# never removes dead instances. Over weeks those logs fill the runtime tmpfs
# and break uwsm-app / systemd --user scopes (issue #13287). Keep only dirs
# still referenced by a live by-pid symlink.

set -euo pipefail

# Canonical, so by-id paths compare equal to the readlink -f'd by-pid targets.
runtime=$(readlink -f -- "${XDG_RUNTIME_DIR:-/run/user/$(id -u)}")
by_id=$runtime/quickshell/by-id
by_pid=$runtime/quickshell/by-pid

[[ -d $by_id ]] || exit 0

declare -A keep=()

if [[ -d $by_pid ]]; then
for link in "$by_pid"/*; do
[[ -e $link || -L $link ]] || continue
pid=${link##*/}
[[ $pid =~ ^[0-9]+$ ]] || continue

if ! kill -0 "$pid" 2>/dev/null; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reused PIDs retain old logs If an unrelated process takes over the PID of a dead Quickshell instance, kill -0 succeeds and the old directory enters the keep set. It will remain on subsequent prunes while that process lives, reducing the effectiveness of the log cleanup. Check that the PID still belongs to the instance, rather than checking only that it exists.

rm -f "$link"
continue
fi

if [[ -L $link ]]; then
target=$(readlink -f "$link" 2>/dev/null || true)
[[ -n $target ]] && keep[$target]=1
fi
done
fi

for dir in "$by_id"/*; do
[[ -d $dir ]] || continue
if [[ -n ${keep[$dir]+x} ]]; then
continue
fi
rm -rf -- "$dir"
Comment on lines +40 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Redirected directory risks data loss If by-id is a symlink to another directory, the earlier -d check accepts it and this glob visits the destination’s children. The prune can then recursively delete directories unrelated to Quickshell instead of only instance logs. Constrain by-id to the intended runtime directory before removing its children.

done
45 changes: 45 additions & 0 deletions test/shell.d/quickshell-log-prune-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

prune="$ROOT/bin/omarchy-quickshell-prune-logs"
[[ -x $prune ]] || fail "quickshell prune helper is executable"
pass "quickshell prune helper is executable"

grep -q 'omarchy-quickshell-prune-logs' "$ROOT/bin/omarchy-launch-shell" ||
fail "shell launch prunes stale quickshell logs"
pass "shell launch prunes stale quickshell logs"

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
runtime=$tmp/run
mkdir -p "$runtime/quickshell/by-id" "$runtime/quickshell/by-pid"

# Live instance: a real sleep process and a by-pid symlink into by-id.
sleep 120 &
live_pid=$!
Comment on lines +21 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed tests leave sleep running If the prune command or a later assertion fails, the test exits before its final kill. The EXIT trap removes only the temporary directory, leaving this sleep 120 process running for up to two minutes. Include the child process in exit cleanup.

mkdir -p "$runtime/quickshell/by-id/live-instance"
echo big >"$runtime/quickshell/by-id/live-instance/log.log"
ln -s "$runtime/quickshell/by-id/live-instance" "$runtime/quickshell/by-pid/$live_pid"

# Stale instance with a dead pid symlink.
mkdir -p "$runtime/quickshell/by-id/stale-instance"
echo huge >"$runtime/quickshell/by-id/stale-instance/log.log"
ln -s "$runtime/quickshell/by-id/stale-instance" "$runtime/quickshell/by-pid/999999"

# Orphan by-id with no by-pid entry at all.
mkdir -p "$runtime/quickshell/by-id/orphan-instance"
echo orphan >"$runtime/quickshell/by-id/orphan-instance/log.log"

# A trailing slash must not make the live instance's path look unreferenced.
XDG_RUNTIME_DIR="$runtime/" "$prune"

[[ -d $runtime/quickshell/by-id/live-instance ]] || fail "prune keeps the live instance"
[[ ! -d $runtime/quickshell/by-id/stale-instance ]] || fail "prune removes stale instance dirs"
[[ ! -d $runtime/quickshell/by-id/orphan-instance ]] || fail "prune removes orphan instance dirs"
[[ ! -L $runtime/quickshell/by-pid/999999 ]] || fail "prune drops dead by-pid symlinks"
pass "prune keeps live dirs and removes stale quickshell instance logs"

kill "$live_pid" 2>/dev/null || true