Skip to content

Commit 3fa69da

Browse files
committed
env: Persistent files and daemon FIFOs now unique per login session
This fixes the long-standing issue of multiple xwin-* daemons and companion scripts trying to write to the same FIFOs if multiple instances of the graphical shell are running on the same machine. Renamed and moved FIFO paths out of $HOME, making use of $XDG_SESSION_ID everywhere with fallbacks for non-systemd systems. xwin-statusd really doesn't need a computationally slow unique S_FIFO path, now uses PID to match xwin-decor.
1 parent 773944a commit 3fa69da

9 files changed

Lines changed: 37 additions & 29 deletions

File tree

.bashrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export COLOR=1; case $TERM in
1919
*) [ $(tput colors) -lt 8 ] && unset COLOR
2020
esac
2121

22-
# persist $OLDPWD between sessions
23-
export LASTDIR="${XDG_RUNTIME_DIR:-/tmp}/.oldpwd"
22+
# persist $OLDPWD between shells on same login session
23+
export LASTDIR="${XDG_RUNTIME_DIR:-/tmp}/.oldpwd.$XDG_SESSION_ID"
2424
[ -f "$LASTDIR" ] && read -r OLDPWD < "$LASTDIR"
2525

2626
# truncate long prompt pathnames over N characters

.config/sxhkd/default

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ ctrl + alt + {Delete,Insert}
4848
visual {htop,watch -c -n 0.1 'dmesg -e -Lalways | tac'}
4949
# rotate display orientation
5050
shift + super + {Up,Down,Left,Right}
51+
PITCHED_SFX(cncl03) \
5152
sfx-synth btn & \
52-
echo '{bottom-up,normal,right-up,left-up}' >> ~/.rotate
53+
echo '{bottom-up,normal,right-up,left-up}' \
54+
> "$XDG_RUNTIME_DIR/.rotate.$XDG_SESSION_ID"
5355

5456
## function keys
5557
# F1: power/reboot

.local/bin/startx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ done
2222
[ ! -z "$xopt" ] && xopt="-config $(id -u)-override/$xopt.conf"
2323

2424
# record time at startup
25-
date '+%s%N' > "$XDG_RUNTIME_DIR/.$XDG_SESSION_TYPE$XDG_VTNR"
25+
date '+%s%N' > "$XDG_RUNTIME_DIR/.xinit-st.$XDG_SESSION_ID"
2626
exec /usr/bin/startx "$@" -- $xopt

.local/bin/xwin-tabletd

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ dpy_digitizer="$(xinput list --name-only | grep -i wacom)"
1313
# detect laptop mouse pointer devices
1414
ptr_devices="$(xinput list --name-only | egrep -i '(touchpad|trackpoint)')"
1515

16-
trap 'kill $!' 0 1 2 3 6 15
16+
abort() {
17+
kill $!
18+
rm -rf "$R_FIFO"
19+
}
20+
trap abort 0 1 2 3 6 15
1721

1822
# workarounds for iio-sensor-proxy
19-
# repeatedly poke accelerometer on a timer to avoid aggressive battery optimization
23+
# repeatedly poke sensor on a timer to avoid aggressive battery optimization
2024
while :; do
2125
cat /sys/bus/iio/devices/iio:device0/in_accel_x_raw > /dev/null
2226
sleep 2
2327
done &
2428

25-
# sxhkd: allows manual override if and when accelerometer stops responding
26-
RFIFO="$HOME/.rotate"
27-
[ ! -p "$RFIFO" ] && mkfifo "$RFIFO"
28-
monitor-sensor >> "$RFIFO" &
29+
# rotation FIFO for external control via sxhkd
30+
R_FIFO="$XDG_RUNTIME_DIR/.rotate.$XDG_SESSION_ID"
31+
[ ! -p "$R_FIFO" ] && mkfifo "$R_FIFO"
32+
monitor-sensor >> "$R_FIFO" &
2933

3034
while read -r line; do
3135
state="${line##* }"
@@ -53,4 +57,4 @@ while read -r line; do
5357
[ "$rot" = "normal" ] && xinput enable "$f" || xinput disable "$f"
5458
done &
5559
fi
56-
done < "$RFIFO"
60+
done < "$R_FIFO"

.local/lib/notify-send

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# send notifications and OSD messages through xwin-statusd
55
# accepts message arguments or first line passed through stdin
66

7-
NFIFO="$HOME/.notify"
8-
[ -p "$NFIFO" ] ||
9-
{ echo "${0##*/}: Cannot write to '$NFIFO', exiting." 1>&2; exit 1; }
7+
N_FIFO="$XDG_RUNTIME_DIR/.notify.$XDG_SESSION_ID"
8+
[ -p "$N_FIFO" ] ||
9+
{ echo "${0##*/}: Cannot write to '$N_FIFO', exiting." 1>&2; exit 1; }
1010

1111
unset SECS
1212
case "$1" in
@@ -15,5 +15,5 @@ case "$1" in
1515
esac
1616
SECS="${SECS:-5}" # default is 5 seconds
1717

18-
echo "$SECS ${@:-$(cat /dev/stdin)}" >> "$HOME/.notify"
18+
echo "$SECS ${@:-$(cat /dev/stdin)}" >> "$N_FIFO"
1919

.profile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export XDG_CONFIG_HOME="$HOME/.config"
1313

1414
# force cache writes to ramdisk
1515
# fallback to /tmp if pam_systemd doesn't provide ramdisk
16+
# fallback unique session ID on non-systemd systems
1617
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}"
1718
export XDG_CACHE_HOME="$XDG_RUNTIME_DIR"
19+
export XDG_SESSION_ID="${XDG_SESSION_ID:-$$}"
1820

1921
# persist for current session only, return 0 on logout
2022
trap 'ssh-agent -k > /dev/null || :' 0 1 3 6 15

.xinitrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ urxvtd -o &
102102
otd-daemon &
103103
lxpolkit &
104104

105-
## profiling and housekeeping
106-
read st < "$XDG_RUNTIME_DIR/.$XDG_SESSION_TYPE$XDG_VTNR"
105+
## startup profiling and housekeeping
106+
timest="$XDG_RUNTIME_DIR/.xinit-st.$XDG_SESSION_ID"
107+
read st < "$timest"
107108
ed=$(date '+%s%N')
108109
{
109-
rm -rf ~/wget-log*
110+
rm -rf "$timest" wget-log*
110111
sleep 1
111112
echo "~/${0##*/} finished in $(((ed - st) / 1000000))ms." | notify-send -t 0.5
112113
} &

Scripts/wm_status.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,38 @@ for f in $pad $quote; do # surround output with special characters
2424
done
2525
unset IFS
2626

27-
# FIFO locations
27+
# status bar FIFO path not exposed to other scripts for stability
2828
prog="${0##*/}"
29-
key="$(tr -cd 'a-z0-9' < /dev/urandom | dd bs=7 count=1 2> /dev/null)"
30-
FIFO="${XDG_RUNTIME_DIR:-/tmp}/.${prog%.*}.$key"
29+
S_FIFO="${XDG_RUNTIME_DIR:-/tmp}/.${prog%.*}.$$"
3130

3231
# notification FIFO written to by notify-send
33-
NFIFO="$HOME/.notify"
32+
N_FIFO="$XDG_RUNTIME_DIR/.notify.$XDG_SESSION_ID"
3433

3534
abort() {
36-
rm -rf "$FIFO" "$NFIFO"
35+
rm -rf "$S_FIFO" "$N_FIFO"
3736
echo "[!] ${0##*/} terminated unexpectedly" | sed -e "$script"
3837
kill -- -$$ > /dev/null 2>&1
3938
}
4039

4140
trap abort 0 1 2 3 6 15
42-
mkfifo "$FIFO" "$NFIFO"
41+
mkfifo "$S_FIFO" "$N_FIFO"
4342

4443
# monitor and redirect notifications from notify-send
4544
# prevent named pipe from closing
4645
{ while :; do
47-
while read -r msg < "$NFIFO"; do
46+
while read -r msg < "$N_FIFO"; do
4847
echo "MSG $msg"
4948
done
5049
done
51-
} > "$FIFO" &
50+
} > "$S_FIFO" &
5251

5352
# thread loop
5453
launch() {
5554
while :; do
5655
sleep "$2" &
5756
"$1"
5857
wait
59-
done > "$FIFO" &
58+
done > "$S_FIFO" &
6059
}
6160

6261
# individual threads
@@ -268,4 +267,4 @@ while read -r module data; do
268267
# output final formatted status line
269268
echo "$bar" | sed -e "$script"
270269

271-
done < "$FIFO"
270+
done < "$S_FIFO"

Scripts/xwin_decor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ffmpeg_cat() {
7474

7575
# remove trash from previous iterations
7676
rm -rf "$XDG_RUNTIME_DIR/${0##*/}"*
77-
temp="$XDG_RUNTIME_DIR/${0##*/}-$$" && mkdir -p "$temp"
77+
temp="$XDG_RUNTIME_DIR/${0##*/}.$$" && mkdir -p "$temp"
7878

7979
# pcmanfm will randomly re-read wallpaper files after they're deleted, leading
8080
# to black screens, just leave temp dir trash to be cleaned up on next run

0 commit comments

Comments
 (0)