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 Jul 28, 2022
1 parent d2bf86c commit e5501a3
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions ble.pp
Expand Up @@ -350,15 +350,29 @@ function ble/base/initialize-base-directory {
function ble/base/initialize-runtime-directory/.xdg {
[[ $_ble_base != */out ]] || return

local runtime_dir=${XDG_RUNTIME_DIR:-/run/user/$UID}
if [[ ! -d $runtime_dir ]]; then
[[ $XDG_RUNTIME_DIR ]] &&
echo "ble.sh: XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' is not a directory." >&2
return 1
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
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 ]] &&
echo "ble.sh: XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR' doesn't have a proper permission." >&2
[[ $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

0 comments on commit e5501a3

Please sign in to comment.