Skip to content

Commit

Permalink
main: work around "XDG_RUNTIME_DIR" of a different user by "su"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 19, 2021
1 parent 22a2449 commit 8d37048
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
24 changes: 19 additions & 5 deletions ble.pp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions note.txt
Expand Up @@ -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

Expand Down

0 comments on commit 8d37048

Please sign in to comment.