diff --git a/ble.pp b/ble.pp index 376b665f..4b564c3f 100644 --- a/ble.pp +++ b/ble.pp @@ -877,14 +877,28 @@ function ble/base/initialize-base-directory { ## 3. $_ble_base/tmp/$UID を使う。 ## function ble/base/initialize-runtime-directory/.xdg { - local runtime_dir=${XDG_RUNTIME_DIR:-/run/user/$UID} - if [[ ! -d $runtime_dir ]]; then - [[ $XDG_RUNTIME_DIR ]] && + local runtime_dir= + if [[ $XDG_RUNTIME_DIR ]]; then + if [[ ! -d $XDG_RUNTIME_DIR ]]; then ble/util/print "ble.sh: XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' is not a directory." >&2 - return 1 + return 1 + elif [[ -O $XDG_RUNTIME_DIR ]]; then + runtime_dir=$XDG_RUNTIME_DIR + else + # When XDG_RUNTIME_DIR is not owned by the current user, maybe "su" is + # used to enter this session keeping the environment variables of the + # original user. We just ignore XDG_RUNTIME_DIR (without issueing + # warnings) for such a case. + false + fi + fi + if [[ ! $runtime_dir ]]; then + runtime_dir=/run/user/$UID + [[ -d $runtime_dir && -O $runtime_dir ]] || return 1 fi + if ! [[ -r $runtime_dir && -w $runtime_dir && -x $runtime_dir ]]; then - [[ $XDG_RUNTIME_DIR ]] && + [[ $runtime_dir == "$XDG_RUNTIME_DIR" ]] && ble/util/print "ble.sh: XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' doesn't have a proper permission." >&2 return 1 fi diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 4064e1af..44a54b83 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -268,6 +268,7 @@ - builtin: print usages of emulated builtins on option errors `#D1694` 6f74021 - decode (`ble/builtin/bind`): improve compatibility of the deprecated form `bind key:rlfunc` (motivated by cmplstofB) `#D1698` b6fc4f0 - complete: work around a false warning messages of gawk-4.0.2 `#D1709` 9771693 +- main: work around `XDG_RUNTIME_DIR` of a different user by `su` (reported by zim0369) `#D1712` 0000000 ## Internal changes and fixes diff --git a/note.txt b/note.txt index 93728269..d0ae435f 100644 --- a/note.txt +++ b/note.txt @@ -5934,6 +5934,9 @@ bash_tips 分からないので取り敢えずエラーメッセージを修正して何が表示されるか問い合わ せる事にする。 + 2021-12-19 分かった。'/run/user/1000/blesh' である。つまり、XDG_RUNTIME_DIR + が su する前のユーザーのディレクトリのままになっているのが問題である。 + * complete: FIGNORE で全てが棄却されるバグ (reported by seanfarley) [#D1711] https://github.com/akinomyoga/ble.sh/issues/162