diff options
author | Po Lu <luangruo@yahoo.com> | 2024-05-07 09:21:59 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2024-05-07 09:21:59 +0800 |
commit | 3bc9c38c471983431bc6768dd6cfe9e059e44a3b (patch) | |
tree | e85a1fdb61c403a502cb059c39da2915cb7a2acb | |
parent | d4d9db8dc6ee20d3c0c1b2e647f40ebf2cc719f3 (diff) | |
download | emacs-3bc9c38c471983431bc6768dd6cfe9e059e44a3b.tar.gz |
Simplify Emacs server detection on Android
* lib-src/emacsclient.c (set_local_socket) [HAVE_ANDROID]: Do
not consider XDG_RUNTIME_DIR or test the ownership or
accessibility of TMPDIR.
-rw-r--r-- | lib-src/emacsclient.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index ea34d5f7b93..bee95e2bd5c 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -1460,8 +1460,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen, this user's directory and does not let others write to it; this fends off some symlink attacks. To avoid races, keep the parent directory open while checking. */ - char *emacsdirend = sockname + tmpdirlen + suffixlen - - strlen(server_name) - 1; + char *emacsdirend = (sockname + tmpdirlen + suffixlen + - strlen(server_name) - 1); *emacsdirend = '\0'; int dir = open (sockname, O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); *emacsdirend = '/'; @@ -1505,6 +1505,7 @@ set_local_socket (char const *server_name) } else { +#ifndef HAVE_ANDROID /* socket_name is a file name component. */ char const *xdg_runtime_dir = egetenv ("XDG_RUNTIME_DIR"); if (xdg_runtime_dir) @@ -1534,10 +1535,35 @@ set_local_socket (char const *server_name) if (tmpdirlen < 0) tmpdirlen = snprintf (sockname, socknamesize, "/tmp"); } + sock_status = local_sockname (s, sockname, tmpdirlen, uid, server_name); tmpdir_used = true; } +#else /* HAVE_ANDROID */ + char const *tmpdir; + int socknamelen; + uintmax_t uidmax; + + /* The TMPDIR of any process to which this binary is + accessible must be reserved for Emacs, so the checks in + local_sockname and the like are redundant. */ + tmpdir = egetenv ("TMPDIR"); + + /* Resort to the usual location of the cache directory, though + this location is not guaranteed to remain stable over + future releases of Android. */ + if (!tmpdir) + tmpdir = "/data/data/org.gnu.emacs/cache"; + + uidmax = uid; + socknamelen = snprintf (sockname, socknamesize, + "%s/emacs%"PRIuMAX"/%s", + tmpdir, uidmax, server_name); + sock_status = (0 <= socknamelen && socknamelen < socknamesize + ? connect_socket (AT_FDCWD, sockname, s, 0) + : ENAMETOOLONG); +#endif /* !HAVE_ANDROID */ } if (sock_status == 0) |