GNU bug report logs - #41707
[PATCH] Try $TMPDIR if $XDG_RUNTIME_DIR has no socket

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Adam Edge <baronedge@HIDDEN>; Keywords: patch; merged with #33847; dated Thu, 4 Jun 2020 13:58:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Forcibly Merged 33847 41707. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Removed tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 41707 <at> debbugs.gnu.org:


Received: (at 41707) by debbugs.gnu.org; 5 Aug 2020 16:30:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Aug 05 12:30:32 2020
Received: from localhost ([127.0.0.1]:52081 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1k3MJE-0006kO-G2
	for submit <at> debbugs.gnu.org; Wed, 05 Aug 2020 12:30:32 -0400
Received: from quimby.gnus.org ([95.216.78.240]:43422)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1k3MJA-0006k4-S1
 for 41707 <at> debbugs.gnu.org; Wed, 05 Aug 2020 12:30:31 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=09jG3wZQaqrTu55ciLFLfj4tRhyNW3nHUnEoKqZEcC8=; b=O3Vqc7KmCXJZ72+dg8ytnWMgZ8
 sbhKqsXlOOoEU7qj7Wyz6mu77JdAILy7HuBqb74oDl2TMBMeWaPVgI3bvxomHjI1zIznx56dRZRG2
 3EFKwaYTuG/09Qwqm57/BSgWJ8LygYVI63wQ42Gsmg+7JM49SiTsUbzJoM2HBKs8TDc0=;
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo)
 by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1k3MIu-0006df-2S; Wed, 05 Aug 2020 18:30:22 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Adam Edge <baronedge@HIDDEN>
Subject: Re: bug#41707: [PATCH] Try $TMPDIR if $XDG_RUNTIME_DIR has no socket
References: <20200604130500.438983-1-baronedge@HIDDEN>
Date: Wed, 05 Aug 2020 18:30:10 +0200
In-Reply-To: <20200604130500.438983-1-baronedge@HIDDEN> (Adam Edge's
 message of "Thu, 4 Jun 2020 16:05:00 +0300")
Message-ID: <87y2mthx7x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Adam Edge <baronedge@HIDDEN> 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 [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 41707
Cc: 41707 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Adam Edge <baronedge@HIDDEN> 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




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#41707; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Jun 2020 13:58:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jun 04 09:58:00 2020
Received: from localhost ([127.0.0.1]:47116 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jgqNb-0004SZ-Jj
	for submit <at> debbugs.gnu.org; Thu, 04 Jun 2020 09:58:00 -0400
Received: from lists.gnu.org ([209.51.188.17]:45064)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <baronedge@HIDDEN>) id 1jgpYg-0002hQ-Dw
 for submit <at> debbugs.gnu.org; Thu, 04 Jun 2020 09:05:22 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:56984)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <baronedge@HIDDEN>)
 id 1jgpYg-0002Qh-92
 for bug-gnu-emacs@HIDDEN; Thu, 04 Jun 2020 09:05:22 -0400
Received: from mail.cock.li ([37.120.193.124]:52092)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <baronedge@HIDDEN>)
 id 1jgpYe-0007Rz-Ku
 for bug-gnu-emacs@HIDDEN; Thu, 04 Jun 2020 09:05:21 -0400
From: Adam Edge <baronedge@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=airmail.cc; s=mail;
 t=1591275909; bh=FZWhliFldyjoLeIKBWOMFuyERrzL2c6y3ov8cwq9+pA=;
 h=From:To:Cc:Subject:Date:From;
 b=EYtMRGWJpY7meaMn9nMekpG7XGUi0xSlLvb9HJgfLV1/9IlCze/ngKVFPKGW4FLD0
 AbHq0Zq8bILAEfaoWmkBRFt8LB9k0PNKVXa+tVY013MMx9ZRMaLPt4SVheIdCA1c+0
 7SAMLmPaCyo2tKB78lr8syyDhCMv1KnvyAplAPYplD58ACuHL+xHLPZGi7ByQy0fEm
 OCedKXeDXgF02/AUgpobxyhBhmW9bOfER7r34vtrt/IFGHbLJtEHLoMlVo9qV2wKBo
 8YGJJAFOHPpCq4IxwSA1Yi296mVuc/GJYdNMGrZ4F1gPLJ8MhmvIPtd3ocEuYlYLn1
 3MYEU0WZ3lKBQ==
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Try $TMPDIR if $XDG_RUNTIME_DIR has no socket
Date: Thu,  4 Jun 2020 16:05:00 +0300
Message-Id: <20200604130500.438983-1-baronedge@HIDDEN>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Received-SPF: permerror client-ip=37.120.193.124;
 envelope-from=baronedge@HIDDEN; helo=mail.cock.li
X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/04 09:05:09
X-ACL-Warn: Detected OS   = Linux 3.11 and newer
X-Spam_score_int: -7
X-Spam_score: -0.8
X-Spam_bar: /
X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_RP_RNBL=1.31,
 T_SPF_PERMERROR=0.01, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN
X-Spam_action: no action
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 04 Jun 2020 09:57:58 -0400
Cc: Adam Edge <baronedge@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

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





Acknowledgement sent to Adam Edge <baronedge@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#41707; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 14 Sep 2020 15:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.