GNU bug report logs -
#41707
[PATCH] Try $TMPDIR if $XDG_RUNTIME_DIR has no socket
Previous Next
Reported by: Adam Edge <baronedge <at> airmail.cc>
Date: Thu, 4 Jun 2020 13:58:01 UTC
Severity: normal
Tags: patch
Merged with 33847
Found in version 27.0.50
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41707 in the body.
You can then email your comments to 41707 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41707
; Package
emacs
.
(Thu, 04 Jun 2020 13:58:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Adam Edge <baronedge <at> airmail.cc>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 04 Jun 2020 13:58:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Emacsclient currently checks whether $XDG_RUNTIME_DIR exists in
the environment, and if it does, it uses that as a base for the
socket directory. However, Emacs seems to still use $TMPDIR
when the daemon is started (both via emacs --daemon and
M-x start-server). This commit makes Emacsclient first check
whether the socket exists in $XDG_RUNTIME_DIR, and if it doesn't,
fall back to $TMPDIR.
---
lib-src/emacsclient.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 380be95222..926d6cdd45 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1365,6 +1365,19 @@ local_sockname (char *sockname, int socknamesize, int tmpdirlen,
return -1;
}
+/* Check the result the sockname snprintf, and fail () if
+ it's invalid. */
+
+static void
+check_sockname_length (const char *name, int len, int size)
+{
+ if (! (0 <= len && len < size))
+ {
+ message (true, "%s: socket-name %s... too long\n", progname, name);
+ fail ();
+ }
+}
+
/* Create a local socket for SERVER_NAME and connect it to Emacs. If
SERVER_NAME is a file name component, the local socket name
relative to a well-known location in a temporary directory.
@@ -1383,6 +1396,7 @@ set_local_socket (char const *server_name)
int socknamelen = -1;
uid_t uid = geteuid ();
bool tmpdir_used = false;
+ int sock_status = 0;
if (strchr (server_name, '/')
|| (ISSLASH ('\\') && strchr (server_name, '\\')))
@@ -1392,9 +1406,17 @@ set_local_socket (char const *server_name)
/* socket_name is a file name component. */
char const *xdg_runtime_dir = egetenv ("XDG_RUNTIME_DIR");
if (xdg_runtime_dir)
- socknamelen = snprintf (sockname, socknamesize, "%s/emacs/%s",
- xdg_runtime_dir, server_name);
- else
+ {
+ socknamelen = snprintf (sockname, socknamesize, "%s/emacs/%s",
+ xdg_runtime_dir, server_name);
+ check_sockname_length (sockname, socknamelen, socknamesize);
+ /* See if the socket exists, and if it's owned by us. */
+ sock_status = socket_status (sockname, uid);
+ }
+
+ /* If there wasn't a socket in XDG_RUNTIME_DIR, Emacs probably
+ created a socket in TMPDIR instead. */
+ if (sock_status == ENOENT)
{
char const *tmpdir = egetenv ("TMPDIR");
if (tmpdir)
@@ -1415,18 +1437,13 @@ set_local_socket (char const *server_name)
}
socknamelen = local_sockname (sockname, socknamesize, tmpdirlen,
uid, server_name);
+ check_sockname_length (sockname, socknamelen, socknamesize);
+ /* See if the socket exists, and if it's owned by us. */
+ sock_status = socket_status (sockname, uid);
tmpdir_used = true;
}
}
- if (! (0 <= socknamelen && socknamelen < socknamesize))
- {
- message (true, "%s: socket-name %s... too long\n", progname, sockname);
- fail ();
- }
-
- /* See if the socket exists, and if it's owned by us. */
- int sock_status = socket_status (sockname, uid);
if (sock_status)
{
/* Failing that, see if LOGNAME or USER exist and differ from
--
2.26.2
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41707
; Package
emacs
.
(Wed, 05 Aug 2020 16:31:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 41707 <at> debbugs.gnu.org (full text, mbox):
Adam Edge <baronedge <at> airmail.cc> writes:
> Emacsclient currently checks whether $XDG_RUNTIME_DIR exists in
> the environment, and if it does, it uses that as a base for the
> socket directory. However, Emacs seems to still use $TMPDIR
> when the daemon is started (both via emacs --daemon and
> M-x start-server). This commit makes Emacsclient first check
> whether the socket exists in $XDG_RUNTIME_DIR, and if it doesn't,
> fall back to $TMPDIR.
As far as I can see, Emacs uses the XDG directory:
;; We do not use `temporary-file-directory' here, because emacsclient
;; does not read the init file.
(defvar server-socket-dir
(if internal--daemon-sockname
(file-name-directory internal--daemon-sockname)
(and (featurep 'make-network-process '(:family local))
(let ((xdg_runtime_dir (getenv "XDG_RUNTIME_DIR")))
(if xdg_runtime_dir
(format "%s/emacs" xdg_runtime_dir)
(format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))))))
"The directory in which to place the server socket.
If local sockets are not supported, this is nil.")
If your Emacs doesn't, then that seems like a bug that should be fixed,
instead of changing emacsclient to check both directories?
Or perhaps you're running a different version of Emacs and emacsclient?
That often has problems and isn't recommended.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Wed, 05 Aug 2020 16:31:02 GMT)
Full text and
rfc822 format available.
Removed tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Sep 2020 15:03:03 GMT)
Full text and
rfc822 format available.
Forcibly Merged 33847 41707.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 14 Sep 2020 15:04:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
33847 <at> debbugs.gnu.org and Ulrich Mueller <ulm <at> gentoo.org>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Fri, 23 Jul 2021 11:35:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 23 Aug 2021 11:24:04 GMT)
Full text and
rfc822 format available.
bug unarchived.
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Mon, 04 Oct 2021 06:39:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 01 Nov 2021 11:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 225 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.