Skip to content
Closed
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
25 changes: 24 additions & 1 deletion bin/omarchy-brightness-display-ddc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ step="${2:-}"

[[ -n $monitor ]] || exit 1

cache_dir="${XDG_RUNTIME_DIR:-/tmp}/omarchy-brightness-display-ddc"
# Bus/range cache must not land at a fixed name in world-writable /tmp.
# Prefer XDG_RUNTIME_DIR; otherwise a private 0700 owner-checked state dir.
private_cache_root() {
local root mode

if [[ -n ${XDG_RUNTIME_DIR:-} ]]; then
printf '%s\n' "$XDG_RUNTIME_DIR"
return 0
fi

root="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy"
mkdir -p "$root" || return 1
chmod 700 "$root" || return 1
[[ -O $root ]] || return 1
mode=$(stat -c '%a' "$root" 2>/dev/null || stat -f '%Lp' "$root")
[[ $mode == 700 ]] || return 1
printf '%s\n' "$root"
}

cache_root=$(private_cache_root) || {
echo "Failed to resolve a private cache directory for DDC brightness." >&2
exit 1
}
cache_dir="$cache_root/omarchy-brightness-display-ddc"
cache_name="${monitor//[^[:alnum:]_.-]/_}"
cache_file="$cache_dir/$cache_name.bus"
unavailable_cache_seconds=60
Expand Down
28 changes: 26 additions & 2 deletions bin/omarchy-capture-region
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,32 @@
# --match-monitor print "monitor:NAME" instead when the picked geometry
# exactly matches a monitor

FULLSCREEN_MARKER="${XDG_RUNTIME_DIR:-/tmp}/omarchy-capture-region-fullscreen"
WINDOW_MARKER="${XDG_RUNTIME_DIR:-/tmp}/omarchy-capture-region-window"
# Fullscreen/window markers must not sit at fixed names in world-writable /tmp.
# Prefer XDG_RUNTIME_DIR; otherwise a private 0700 owner-checked state dir.
private_marker_root() {
local root mode

if [[ -n ${XDG_RUNTIME_DIR:-} ]]; then
printf '%s\n' "$XDG_RUNTIME_DIR"
return 0
fi

root="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy"
mkdir -p "$root" || return 1
chmod 700 "$root" || return 1
[[ -O $root ]] || return 1
mode=$(stat -c '%a' "$root" 2>/dev/null || stat -f '%Lp' "$root")
[[ $mode == 700 ]] || return 1
printf '%s\n' "$root"
}

marker_root=$(private_marker_root) || {
echo "Failed to resolve a private directory for capture-region markers." >&2
exit 1
}
mkdir -p "$marker_root"
FULLSCREEN_MARKER="$marker_root/omarchy-capture-region-fullscreen"
WINDOW_MARKER="$marker_root/omarchy-capture-region-window"

# accounting for portrait/transformed displays
JQ_MONITOR_GEO='
Expand Down
28 changes: 27 additions & 1 deletion bin/omarchy-update-stay-awake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,32 @@

set -e

state_dir="${XDG_RUNTIME_DIR:-/tmp/omarchy-$UID}/omarchy-update-stay-awake"
# Inhibit pid + idle-owner tokens must not land under a predictable name in
# world-writable /tmp. XDG_RUNTIME_DIR is already 0700 when the session set it;
# without one, use a private state dir we create/repair ourselves (same shape as
# the screenrecording tip-ready fix) rather than a predictable /tmp name.
private_root() {
local root mode

if [[ -n ${XDG_RUNTIME_DIR:-} ]]; then
printf '%s\n' "$XDG_RUNTIME_DIR"
return 0
fi

root="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy"
mkdir -p "$root" || return 1
chmod 700 "$root" || return 1
[[ -O $root ]] || return 1
mode=$(stat -c '%a' "$root" 2>/dev/null || stat -f '%Lp' "$root")
[[ $mode == 700 ]] || return 1
printf '%s\n' "$root"
}

state_root=$(private_root) || {
echo "Failed to resolve a private state directory for update stay-awake." >&2
exit 1
}
state_dir="$state_root/omarchy-update-stay-awake"
idle_owner_file="$state_dir/idle-owner"
inhibit_pid_file="$state_dir/inhibit-pid"
stay_awake_state="$HOME/.local/state/omarchy/indicators/stay-awake"
Expand Down Expand Up @@ -88,6 +113,7 @@ start() {

stop
mkdir -p "$state_dir"
chmod 700 "$state_dir" 2>/dev/null || true

if omarchy-cmd-present systemd-inhibit; then
if (( EUID != 0 )); then
Expand Down
42 changes: 42 additions & 0 deletions test/shell.d/brightness-display-ddc-cache-path-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -euo pipefail

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

script="$ROOT/bin/omarchy-brightness-display-ddc"

if grep -Fq '${XDG_RUNTIME_DIR:-/tmp}/omarchy-brightness-display-ddc' "$script"; then
fail "DDC brightness no longer caches under world-writable /tmp"
fi

grep -Fq 'private_cache_root' "$script" || fail "DDC brightness resolves a private cache root"
grep -Fq 'XDG_STATE_HOME' "$script" || fail "DDC brightness falls back to XDG_STATE_HOME when runtime dir is unset"
grep -Fq 'chmod 700' "$script" || fail "DDC brightness enforces mode 0700 on the private cache root"
pass "DDC brightness cache path avoids world-writable /tmp"

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

stub_bin="$tmp/bin"
mkdir -p "$stub_bin" "$tmp/home" "$tmp/state"
cat >"$stub_bin/ddcutil" <<'SH'
#!/bin/bash
exit 1
SH
chmod +x "$stub_bin/ddcutil"

export PATH="$stub_bin:$PATH"
export HOME="$tmp/home"
unset XDG_RUNTIME_DIR
export XDG_STATE_HOME="$tmp/state"

bash "$script" DP-1 >/dev/null 2>&1 || true

[[ -d $XDG_STATE_HOME/omarchy/omarchy-brightness-display-ddc ]] ||
fail "creates cache under XDG_STATE_HOME/omarchy" "$(find "$tmp" -type d)"
mode=$(stat -c '%a' "$XDG_STATE_HOME/omarchy" 2>/dev/null || stat -f '%Lp' "$XDG_STATE_HOME/omarchy")
[[ $mode == 700 ]] || fail "private cache root is mode 0700" "mode=$mode"
[[ ! -e /tmp/omarchy-brightness-display-ddc ]] ||
fail "does not create /tmp/omarchy-brightness-display-ddc"
pass "DDC brightness stages cache under a private state directory"
19 changes: 19 additions & 0 deletions test/shell.d/capture-region-marker-path-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -euo pipefail

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

script="$ROOT/bin/omarchy-capture-region"

if grep -Fq '${XDG_RUNTIME_DIR:-/tmp}/omarchy-capture-region-fullscreen' "$script"; then
fail "capture-region fullscreen marker no longer falls back to /tmp"
fi
if grep -Fq '${XDG_RUNTIME_DIR:-/tmp}/omarchy-capture-region-window' "$script"; then
fail "capture-region window marker no longer falls back to /tmp"
fi

grep -Fq 'private_marker_root' "$script" || fail "capture-region resolves a private marker root"
grep -Fq 'XDG_STATE_HOME' "$script" || fail "capture-region falls back to XDG_STATE_HOME when runtime dir is unset"
grep -Fq 'chmod 700' "$script" || fail "capture-region enforces mode 0700 on the private marker root"
pass "capture-region marker paths avoid world-writable /tmp"
59 changes: 59 additions & 0 deletions test/shell.d/update-stay-awake-path-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -euo pipefail

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

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

stub_bin="$tmp/bin"
mkdir -p "$stub_bin" "$tmp/home" "$tmp/run" "$tmp/state"

cat >"$stub_bin/omarchy-cmd-present" <<'SH'
#!/bin/bash
[[ $1 == systemd-inhibit ]] && exit 1
exit 1
SH

cat >"$stub_bin/omarchy-toggle-idle" <<'SH'
#!/bin/bash
exit 0
SH

chmod +x "$stub_bin"/*
export PATH="$stub_bin:$PATH"
export HOME="$tmp/home"
unset XDG_RUNTIME_DIR
export XDG_STATE_HOME="$tmp/state"

script="$ROOT/bin/omarchy-update-stay-awake"

# Tip still names /tmp/omarchy-$UID; the tip-ready body must not.
if grep -q '/tmp/omarchy-\$UID\|/tmp/omarchy-$UID' "$script"; then
fail "stay-awake no longer falls back to /tmp/omarchy-\$UID"
fi
pass "stay-awake source does not name /tmp/omarchy-\$UID"

# Without XDG_RUNTIME_DIR, start must stage under the private state home.
bash "$script" start >/dev/null

state_dir="$XDG_STATE_HOME/omarchy/omarchy-update-stay-awake"
[[ -d $state_dir ]] || fail "creates state under XDG_STATE_HOME/omarchy" "$(find "$tmp" -type d)"
pass "creates state under XDG_STATE_HOME/omarchy"

mode=$(stat -c '%a' "$XDG_STATE_HOME/omarchy" 2>/dev/null || stat -f '%Lp' "$XDG_STATE_HOME/omarchy")
[[ $mode == 700 ]] || fail "private root is mode 0700" "mode=$mode"
pass "private root is mode 0700"

[[ ! -e /tmp/omarchy-$UID/omarchy-update-stay-awake ]] ||
fail "does not create /tmp/omarchy-\$UID/omarchy-update-stay-awake"
pass "does not create /tmp/omarchy-\$UID/omarchy-update-stay-awake"

# With XDG_RUNTIME_DIR set, prefer it.
export XDG_RUNTIME_DIR="$tmp/run"
bash "$script" stop >/dev/null 2>&1 || true
bash "$script" start >/dev/null
[[ -d $XDG_RUNTIME_DIR/omarchy-update-stay-awake ]] ||
fail "prefers XDG_RUNTIME_DIR when set"
pass "prefers XDG_RUNTIME_DIR when set"