Repository navigation
Prune stale Quickshell instance logs on shell launch #13651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| done | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.