summaryrefslogtreecommitdiff
path: root/bin/emacsclient
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-01-27 17:16:42 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-01-27 17:33:44 -0700
commit29cff70c83e7b614055cbb01965a5177e99272a5 (patch)
treec7e5ff10fc6902dc4dcf0c22b8550c8fae650029 /bin/emacsclient
parentc53e87f671cffded00719a747ba339fc8708dc8f (diff)
downloaddotfiles-29cff70c83e7b614055cbb01965a5177e99272a5.tar.gz
emacsclient wrapper: check whether /run/user/$(id -u) exists
Diffstat (limited to 'bin/emacsclient')
-rwxr-xr-xbin/emacsclient18
1 files changed, 13 insertions, 5 deletions
diff --git a/bin/emacsclient b/bin/emacsclient
index cb371608..928badb2 100755
--- a/bin/emacsclient
+++ b/bin/emacsclient
@@ -27,6 +27,7 @@ want_installed=false
want_eval=false
want_version=false
timeout=
+euid=
devel_running=false
installed_running=false
make=
@@ -182,16 +183,23 @@ done
# -sgdbmacs implies --spw/installed, as a special case.
[ "$daemon_name" = gdbmacs ] && want_installed=true
-# We set and export XDG_RUNTIME_DIR such that Emacs doesn't choose
-# "/tmp/emacs$(id -u)" as the socket dir.
+# We set and export XDG_RUNTIME_DIR such that Emacs doesn't choose a directory
+# under /tmp as the socket directory. However, if /run/user/$(id -u) does not
+# already exist, then we probably don't have permission to create it.
if [ -n "$XDG_RUNTIME_DIR" ]; then
was_set=true
+ socket_dir="$XDG_RUNTIME_DIR/emacs/"
+ locks_dir="$XDG_RUNTIME_DIR/spw_emacsclient/"
+elif [ -d "/run/user/${euid:=$(id -u)}" ]; then
+ was_set=false
+ export XDG_RUNTIME_DIR="/run/user/$euid"
+ socket_dir="$XDG_RUNTIME_DIR/emacs/"
+ locks_dir="$XDG_RUNTIME_DIR/spw_emacsclient/"
else
was_set=false
- export XDG_RUNTIME_DIR=/run/user/$(id -u)
+ socket_dir="${TMPDIR:-/tmp}/emacs$euid/"
+ locks_dir="${socket_dir}spw_emacsclient/"
fi
-socket_dir="$XDG_RUNTIME_DIR/emacs/"
-locks_dir="$XDG_RUNTIME_DIR/spw_emacsclient/"
$want_version || spw_flock 3 "${daemon_name:-server}"