diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-13 14:34:02 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-04-13 15:39:51 -0400 |
commit | 969410c5af909199724973b8851fcb6bf19eaba2 (patch) | |
tree | 14d7e75ecebda9439a4a96b647e13ecb2d66622a /.config/login.d | |
parent | c0a9c2902e60cc980343a65f5519e7c9e2dcd081 (diff) |
clean up XDG_RUNTIME_DIR handling
Diffstat (limited to '.config/login.d')
-rw-r--r-- | .config/login.d/01_xdg.sh | 27 | ||||
-rw-r--r-- | .config/login.d/02_tmpdir.sh | 2 | ||||
-rw-r--r-- | .config/login.d/02_xdg_runtime_dir.sh | 28 | ||||
-rw-r--r-- | .config/login.d/03_tmpdir.sh | 4 | ||||
-rw-r--r-- | .config/login.d/90_dot-runtime.sh | 4 | ||||
-rw-r--r-- | .config/login.d/90_symlink_xdg_runtime_dir.sh | 4 |
6 files changed, 36 insertions, 33 deletions
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" |