From 969410c5af909199724973b8851fcb6bf19eaba2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 13 Apr 2015 14:34:02 -0400 Subject: clean up XDG_RUNTIME_DIR handling --- .config/X11/clientrc | 1 + .config/login.d/01_xdg.sh | 27 -------------------------- .config/login.d/02_tmpdir.sh | 2 -- .config/login.d/02_xdg_runtime_dir.sh | 28 +++++++++++++++++++++++++++ .config/login.d/03_tmpdir.sh | 4 ++++ .config/login.d/90_dot-runtime.sh | 4 ---- .config/login.d/90_symlink_xdg_runtime_dir.sh | 4 ++++ .config/ssh/config | 2 +- 8 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 .config/login.d/02_tmpdir.sh create mode 100644 .config/login.d/02_xdg_runtime_dir.sh create mode 100644 .config/login.d/03_tmpdir.sh delete mode 100644 .config/login.d/90_dot-runtime.sh create mode 100644 .config/login.d/90_symlink_xdg_runtime_dir.sh diff --git a/.config/X11/clientrc b/.config/X11/clientrc index 4773ea4..2c965da 100755 --- a/.config/X11/clientrc +++ b/.config/X11/clientrc @@ -17,6 +17,7 @@ if [ -f "$usermodmap" ]; then xmodmap "$usermodmap" fi +[ -n "$XDG_RUNTIME_DIR" ] || exit 1 trap "rm -f $(printf '%q' "${XDG_RUNTIME_DIR}/x11-wm@${DISPLAY}")" EXIT mkfifo "${XDG_RUNTIME_DIR}/x11-wm@${DISPLAY}" diff --git a/.config/login.d/01_xdg.sh b/.config/login.d/01_xdg.sh index c9f789c..22bbc01 100644 --- a/.config/login.d/01_xdg.sh +++ b/.config/login.d/01_xdg.sh @@ -18,30 +18,3 @@ if [ -n "$XDG_RUNTIME_DIR" ] && [ ! -d "$XDG_RUNTIME_DIR" ]; then unset XDG_RUNTIME_DIR fi - -# Set XDG_RUNTIME_DIR if we can -if [ -z "$XDG_RUNTIME_DIR" ] && type flock &>/dev/null; then - _diy_xdg_runtime_login() { - export XDG_RUNTIME_DIR="$XDG_CACHE_HOME/xdg-runtime-dir/$HOSTNAME" - # There's a race condition here, between the `ln -s` and `flock`. - # But it's not like I'll be hammering a box with logins. - if [ ! -d "$XDG_RUNTIME_DIR" ]; then - local tmp="$(mktemp -d --tmpdir -- "${USER}@${HOSTNAME}-runtime.XXXXXXXXXX")" - mkdir -p -- "$XDG_CACHE_HOME/xdg-runtime-dir" - ln -sfT -- "$tmp" "$XDG_RUNTIME_DIR" - fi - if ! [ /dev/fd/7 -ef "$XDG_CACHE_HOME/xdg-runtime-dir/.lock" ]; then - exec 7>"$XDG_CACHE_HOME/xdg-runtime-dir/.lock" - if flock -sn 7; then - # Unfortunately this doesn't survive across exec(1). - trap _diy_xdg_runtime_logout EXIT - fi - fi - } - _diy_xdg_runtime_logout() { - if flock -xn 7; then - rm -rf -- "$(readlink "$XDG_RUNTIME_DIR")" - fi - } - _diy_xdg_runtime_login -fi diff --git a/.config/login.d/02_tmpdir.sh b/.config/login.d/02_tmpdir.sh deleted file mode 100644 index c0d5f18..0000000 --- a/.config/login.d/02_tmpdir.sh +++ /dev/null @@ -1,2 +0,0 @@ -mkdir -p -- "$XDG_RUNTIME_DIR/tmpdir" -export TMPDIR="$XDG_RUNTIME_DIR/tmpdir" diff --git a/.config/login.d/02_xdg_runtime_dir.sh b/.config/login.d/02_xdg_runtime_dir.sh new file mode 100644 index 0000000..6d93359 --- /dev/null +++ b/.config/login.d/02_xdg_runtime_dir.sh @@ -0,0 +1,28 @@ +# This should be readable by /bin/sh + +# Set XDG_RUNTIME_DIR if we can +if [ -z "$XDG_RUNTIME_DIR" ] && shopt -q login_shell && type flock &>/dev/null; then + _diy_xdg_runtime_login() { + export XDG_RUNTIME_DIR="$XDG_CACHE_HOME/xdg-runtime-dir/$HOSTNAME" + # There's a race condition here, between the `ln -s` and `flock`. + # But it's not like I'll be hammering a box with logins. + if [ ! -d "$XDG_RUNTIME_DIR" ]; then + local tmp="$(mktemp -d --tmpdir -- "${USER}@${HOSTNAME}-runtime.XXXXXXXXXX")" + mkdir -p -- "$XDG_CACHE_HOME/xdg-runtime-dir" + ln -sfT -- "$tmp" "$XDG_RUNTIME_DIR" + fi + if ! [ /dev/fd/7 -ef "$XDG_CACHE_HOME/xdg-runtime-dir/.lock" ]; then + exec 7>"$XDG_CACHE_HOME/xdg-runtime-dir/.lock" + if flock -sn 7; then + # Unfortunately this doesn't survive across exec(1). + trap _diy_xdg_runtime_logout EXIT + fi + fi + } + _diy_xdg_runtime_logout() { + if flock -xn 7; then + rm -rf -- "$(readlink "$XDG_RUNTIME_DIR")" + fi + } + _diy_xdg_runtime_login +fi diff --git a/.config/login.d/03_tmpdir.sh b/.config/login.d/03_tmpdir.sh new file mode 100644 index 0000000..b94ef1a --- /dev/null +++ b/.config/login.d/03_tmpdir.sh @@ -0,0 +1,4 @@ +if [ -n "$XDG_RUNTIME_DIR" ]; then + mkdir -p -- "$XDG_RUNTIME_DIR/tmpdir" + export TMPDIR="$XDG_RUNTIME_DIR/tmpdir" +fi diff --git a/.config/login.d/90_dot-runtime.sh b/.config/login.d/90_dot-runtime.sh deleted file mode 100644 index 87d30ec..0000000 --- a/.config/login.d/90_dot-runtime.sh +++ /dev/null @@ -1,4 +0,0 @@ -# This is really only needed for ssh ControlPath; as I don't have a -# way to communicate XD -mkdir -p -- ~/.runtime -ln -sfT -- "$XDG_RUNTIME_DIR" ~/.runtime/"$HOSTNAME" diff --git a/.config/login.d/90_symlink_xdg_runtime_dir.sh b/.config/login.d/90_symlink_xdg_runtime_dir.sh new file mode 100644 index 0000000..b89f7b1 --- /dev/null +++ b/.config/login.d/90_symlink_xdg_runtime_dir.sh @@ -0,0 +1,4 @@ +# This is really only needed for ssh ControlPath; as I don't have a +# way to communicate XDG_RUNTIME_DIR +mkdir -p -- "$XDG_CACHE_HOME/xdg-runtime-dir" +ln -sfT -- "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/xdg-runtime-dir/$HOSTNAME" diff --git a/.config/ssh/config b/.config/ssh/config index cc796ed..5ea36ba 100644 --- a/.config/ssh/config +++ b/.config/ssh/config @@ -1,7 +1,7 @@ Host * Protocol 2 ControlMaster auto - ControlPath ~/.runtime/%l/ssh-%r@%h:%p + ControlPath ~/.cache/xdg-runtime-dir/%l/ssh-%r@%h:%p Compression yes # Purdue ################################################### -- cgit v1.2.3