From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#24218: 25.1.50; server-name, server-socket-dir and daemon start through, systemd socket Date: Sat, 10 Feb 2018 08:07:47 -0800 Organization: UCLA Computer Science Department Message-ID: <52b062c7-adb2-c8ad-dc57-b5af849d5b18@cs.ucla.edu> References: <87popclj82.fsf@yandex.ru> <83608d80vy.fsf@gnu.org> <878td6u7vk.fsf@mattleach.net> <3d2e3962-9592-2d0a-b50b-52e2dddfbb66@cs.ucla.edu> <87k1w5d978.fsf@1e0.co.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9332E000B217EE43AA5F7FAF" X-Trace: blaine.gmane.org 1518278854 26007 195.159.176.226 (10 Feb 2018 16:07:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Feb 2018 16:07:34 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Cc: 24218@debbugs.gnu.org, lomov.vl@gmail.com To: Matthew Leach Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Feb 10 17:07:29 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ekXgM-0005lM-Ic for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Feb 2018 17:07:18 +0100 Original-Received: from localhost ([::1]:59358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekXiM-0002l6-7q for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Feb 2018 11:09:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekXi7-0002jw-OV for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2018 11:09:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekXi2-0003U7-Q6 for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2018 11:09:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57503) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ekXi2-0003TU-G2 for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2018 11:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ekXi2-0003em-85 for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2018 11:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Feb 2018 16:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24218 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24218-submit@debbugs.gnu.org id=B24218.151827888113977 (code B ref 24218); Sat, 10 Feb 2018 16:09:02 +0000 Original-Received: (at 24218) by debbugs.gnu.org; 10 Feb 2018 16:08:01 +0000 Original-Received: from localhost ([127.0.0.1]:37167 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ekXh2-0003dI-QV for submit@debbugs.gnu.org; Sat, 10 Feb 2018 11:08:01 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48246) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ekXgz-0003d3-Lx for 24218@debbugs.gnu.org; Sat, 10 Feb 2018 11:07:59 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 64E21161748; Sat, 10 Feb 2018 08:07:51 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id v12rFScoicJK; Sat, 10 Feb 2018 08:07:48 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A779616174C; Sat, 10 Feb 2018 08:07:48 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Y53z24uzbhu7; Sat, 10 Feb 2018 08:07:48 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.154.30.119]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3B1ED161748; Sat, 10 Feb 2018 08:07:48 -0800 (PST) In-Reply-To: <87k1w5d978.fsf@1e0.co.uk> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143099 Archived-At: This is a multi-part message in MIME format. --------------9332E000B217EE43AA5F7FAF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Matthew Leach wrote: > Paul Eggert writes: > >> On 01/09/2018 11:53 AM, Matthew Leach wrote: >>> May I suggest `internal--daemon-sockname'? >> >> Yes, that sounds good. Can you prepare a patch along those lines? > > Sure, please see the attached patch series. Thanks, but aren't there some more places where the variable needs to be renamed to internal--daemon-sockname? Also, I would rather not document it in the Emacs Lisp reference manual, as it is an internal detail that outside code shouldn't depend on. Proposed further patch attached (it's the last of the attachments, which contain all the patches for this bug). --------------9332E000B217EE43AA5F7FAF Content-Type: text/x-patch; name="0001-Fix-server-name-and-server-socket-dir-for-Bug-24218.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-server-name-and-server-socket-dir-for-Bug-24218.pat"; filename*1="ch" >From b71632dbba803c2cd22e9f18231d4eb38b1521f9 Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Feb 2018 07:44:13 -0800 Subject: [PATCH 1/5] Fix `server-name' and `server-socket-dir' for (Bug#24218) * lisp/server.el: (server-external-socket-initialised): New (server-name): Compute server name from `get-external-sockname'. (server-socket-dir): Compute socket dir from `get-external-sockname'. (server-start): Don't check for existing server when an uninitialised external socket has been passed to Emacs. * src/emacs.c: (main): Obtain socket name via getsockname and pass to `init_process_emacs'. * src/lisp.h: (init_process_emacs): Add second parameter. * src/process.c: (external_sock_name): New. (get-external-sockname): New. (init_process_emacs): Set `external_sock_name' to `sockname' parameter. --- lisp/server.el | 56 ++++++++++++++++++++++++++++++++++++-------------------- src/emacs.c | 16 +++++++++++++--- src/lisp.h | 2 +- src/process.c | 19 ++++++++++++++++++- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index d91a51e..d2406e2 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,8 +251,16 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -;;;###autoload -(defcustom server-name "server" +(defvar server-external-socket-initialised nil + "When an external socket is passed into Emacs, we need to call +`server-start' in order to initialise the connection. This flag +prevents multiple initialisations when an external socket has +been consumed.") + +(defcustom server-name + (if (get-external-sockname) + (file-name-nondirectory (get-external-sockname)) + "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be changed while a server is running." @@ -263,8 +271,10 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (and (featurep 'make-network-process '(:family local)) - (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) + (if (get-external-sockname) + (file-name-directory (get-external-sockname)) + (and (featurep 'make-network-process '(:family local)) + (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.") @@ -618,23 +628,29 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Delete the socket files made by previous server invocations. - (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file - (ignore-errors - (let (delete-by-moving-to-trash) - (delete-file server-file))) - (setq server-mode nil) ;; already set by the minor mode code - (display-warning - 'server - (concat "Unable to start the Emacs server.\n" - (format "There is an existing Emacs server, named %S.\n" - server-name) - (substitute-command-keys - "To start the server in this Emacs process, stop the existing + ;; Check to see if an uninitialised external socket has been + ;; passed in, if that is the case, skip checking + ;; `server-running-p' as this will return the wrong result. + (if (and (get-external-sockname) + (not server-external-socket-initialised)) + (setq server-external-socket-initialised t) + ;; Delete the socket files made by previous server invocations. + (if (not (eq t (server-running-p server-name))) + ;; Remove any leftover socket or authentication file + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file server-file))) + (setq server-mode nil) ;; already set by the minor mode code + (display-warning + 'server + (concat "Unable to start the Emacs server.\n" + (format "There is an existing Emacs server, named %S.\n" + server-name) + (substitute-command-keys + "To start the server in this Emacs process, stop the existing server or call `\\[server-force-delete]' to forcibly disconnect it.")) - :warning) - (setq leave-dead t)) + :warning) + (setq leave-dead t))) ;; If this Emacs already had a server, clear out associated status. (while server-clients (server-delete-client (car server-clients))) diff --git a/src/emacs.c b/src/emacs.c index 8ea61b7..c423faf 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,6 +60,7 @@ along with GNU Emacs. If not, see . */ #ifdef HAVE_LIBSYSTEMD # include # include +# include #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1002,6 +1003,7 @@ main (int argc, char **argv) int sockfd = -1; + char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1061,8 +1063,16 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNSPEC, SOCK_STREAM, 1))) - sockfd = SD_LISTEN_FDS_START; + AF_UNIX, SOCK_STREAM, 1))) + { + struct sockaddr_un sockaddr; + socklen_t sockaddr_sz = sizeof(sockaddr); + + sockfd = SD_LISTEN_FDS_START; + + if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) + sockname = strdup(sockaddr.sun_path); + } #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1660,7 +1670,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd); + init_process_emacs (sockfd, sockname); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index a7f0a1d..0bd0e5e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4316,7 +4316,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int); +extern void init_process_emacs (int, char *); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index 2cc2c86..405c06d 100644 --- a/src/process.c +++ b/src/process.c @@ -276,6 +276,10 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; +/* The name (path) of the socket that was passed to Emacs, when + `external_sock_fd' is not -1. */ +static const char *external_sock_name = NULL; + /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -7972,10 +7976,21 @@ restore_nofile_limit (void) } +DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, + doc: /* Return the path of an external socket passed to Emacs. +Otherwise return nil. */) + (void) +{ + if (external_sock_name) + return make_string(external_sock_name, strlen(external_sock_name)); + else + return Qnil; +} + /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd) +init_process_emacs (int sockfd, char *sockname) { #ifdef subprocesses int i; @@ -8010,6 +8025,7 @@ init_process_emacs (int sockfd) #endif external_sock_fd = sockfd; + external_sock_name = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8304,4 +8320,5 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); + defsubr (&Sget_external_sockname); } -- 2.7.4 --------------9332E000B217EE43AA5F7FAF Content-Type: text/x-patch; name="0002-Minor-cleanups-for-server-name-fix-Bug-24218.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-Minor-cleanups-for-server-name-fix-Bug-24218.patch" >From dd3e2ccd71a137ec549fdfe6b9c5201c62f5f978 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Feb 2018 07:44:13 -0800 Subject: [PATCH 2/5] Minor cleanups for server-name fix (Bug#24218) * lisp/server.el (server--external-socket-initialized): Rename from server-external-socket-initialised, since it should be private and Emacs uses American spelling. All uses changed. * src/emacs.c, src/lisp.h: Revert previous changes, as the initialization is now done in src/process.c, which already includes the relevant files. * src/process.c (union u_sockaddr): Move decl to top level. (external_sock_name, Fget_external_sockname): Remove, replacing with Vinternal__external_sockname. All uses changed. (init_process_emacs): Deduce socket name ourselves rather than have main.c do it. Use conv_sockaddr_to_lisp instead of doing it by hand. Conditionalize it on HAVE_GETSOCKNAME. --- lisp/server.el | 24 ++++++++++++------------ src/emacs.c | 16 +++------------- src/lisp.h | 2 +- src/process.c | 58 ++++++++++++++++++++++++++++++---------------------------- 4 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index d2406e2..70ac51e 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -251,15 +251,15 @@ server-existing-buffer are done with it in the server.") (make-variable-buffer-local 'server-existing-buffer) -(defvar server-external-socket-initialised nil +(defvar server--external-socket-initialized nil "When an external socket is passed into Emacs, we need to call -`server-start' in order to initialise the connection. This flag -prevents multiple initialisations when an external socket has +`server-start' in order to initialize the connection. This flag +prevents multiple initializations when an external socket has been consumed.") (defcustom server-name - (if (get-external-sockname) - (file-name-nondirectory (get-external-sockname)) + (if internal--external-sockname + (file-name-nondirectory internal--external-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if (get-external-sockname) - (file-name-directory (get-external-sockname)) + (if internal--external-sockname + (file-name-directory internal--external-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -628,15 +628,15 @@ server-start (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) - ;; Check to see if an uninitialised external socket has been + ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and (get-external-sockname) - (not server-external-socket-initialised)) - (setq server-external-socket-initialised t) + (if (and internal--external-sockname + (not server--external-socket-initialized)) + (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. (if (not (eq t (server-running-p server-name))) - ;; Remove any leftover socket or authentication file + ;; Remove any leftover socket or authentication file. (ignore-errors (let (delete-by-moving-to-trash) (delete-file server-file))) diff --git a/src/emacs.c b/src/emacs.c index c423faf..8ea61b7 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -60,7 +60,6 @@ along with GNU Emacs. If not, see . */ #ifdef HAVE_LIBSYSTEMD # include # include -# include #endif #ifdef HAVE_WINDOW_SYSTEM @@ -1003,7 +1002,6 @@ main (int argc, char **argv) int sockfd = -1; - char *sockname = NULL; if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) @@ -1063,16 +1061,8 @@ main (int argc, char **argv) "Try 'Accept=false' in the Emacs socket unit file.\n")); else if (systemd_socket == 1 && (0 < sd_is_socket (SD_LISTEN_FDS_START, - AF_UNIX, SOCK_STREAM, 1))) - { - struct sockaddr_un sockaddr; - socklen_t sockaddr_sz = sizeof(sockaddr); - - sockfd = SD_LISTEN_FDS_START; - - if (!getsockname(sockfd, &sockaddr, &sockaddr_sz)) - sockname = strdup(sockaddr.sun_path); - } + AF_UNSPEC, SOCK_STREAM, 1))) + sockfd = SD_LISTEN_FDS_START; #endif /* HAVE_LIBSYSTEMD */ #ifdef USE_GTK @@ -1670,7 +1660,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* This can create a thread that may call getenv, so it must follow all calls to putenv and setenv. Also, this sets up add_keyboard_wait_descriptor, which init_display uses. */ - init_process_emacs (sockfd, sockname); + init_process_emacs (sockfd); init_keyboard (); /* This too must precede init_sys_modes. */ if (!noninteractive) diff --git a/src/lisp.h b/src/lisp.h index 0bd0e5e..a7f0a1d 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4316,7 +4316,7 @@ extern void delete_keyboard_wait_descriptor (int); extern void add_gpm_wait_descriptor (int); extern void delete_gpm_wait_descriptor (int); #endif -extern void init_process_emacs (int, char *); +extern void init_process_emacs (int); extern void syms_of_process (void); extern void setup_process_coding_systems (Lisp_Object); diff --git a/src/process.c b/src/process.c index 405c06d..8396a93 100644 --- a/src/process.c +++ b/src/process.c @@ -160,6 +160,18 @@ static bool kbd_is_on_hold; when exiting. */ bool inhibit_sentinels; +union u_sockaddr +{ + struct sockaddr sa; + struct sockaddr_in in; +#ifdef AF_INET6 + struct sockaddr_in6 in6; +#endif +#ifdef HAVE_LOCAL_SOCKETS + struct sockaddr_un un; +#endif +}; + #ifdef subprocesses #ifndef SOCK_CLOEXEC @@ -276,10 +288,6 @@ static int max_desc; the file descriptor of a socket that is already bound. */ static int external_sock_fd; -/* The name (path) of the socket that was passed to Emacs, when - `external_sock_fd' is not -1. */ -static const char *external_sock_name = NULL; - /* Indexed by descriptor, gives the process (if any) for that descriptor. */ static Lisp_Object chan_process[FD_SETSIZE]; static void wait_for_socket_fds (Lisp_Object, char const *); @@ -4677,16 +4685,7 @@ server_accept_connection (Lisp_Object server, int channel) struct Lisp_Process *ps = XPROCESS (server); struct Lisp_Process *p; int s; - union u_sockaddr { - struct sockaddr sa; - struct sockaddr_in in; -#ifdef AF_INET6 - struct sockaddr_in6 in6; -#endif -#ifdef HAVE_LOCAL_SOCKETS - struct sockaddr_un un; -#endif - } saddr; + union u_sockaddr saddr; socklen_t len = sizeof saddr; ptrdiff_t count; @@ -7976,21 +7975,10 @@ restore_nofile_limit (void) } -DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0, - doc: /* Return the path of an external socket passed to Emacs. -Otherwise return nil. */) - (void) -{ - if (external_sock_name) - return make_string(external_sock_name, strlen(external_sock_name)); - else - return Qnil; -} - /* This is not called "init_process" because that is the name of a Mach system call, so it would cause problems on Darwin systems. */ void -init_process_emacs (int sockfd, char *sockname) +init_process_emacs (int sockfd) { #ifdef subprocesses int i; @@ -8025,7 +8013,18 @@ init_process_emacs (int sockfd, char *sockname) #endif external_sock_fd = sockfd; - external_sock_name = sockname; + Lisp_Object sockname = Qnil; +# if HAVE_GETSOCKNAME + if (0 <= sockfd) + { + union u_sockaddr sa; + socklen_t salen = sizeof sa; + if (getsockname (sockfd, &sa.sa, &salen) == 0) + sockname = conv_sockaddr_to_lisp (&sa.sa, salen); + } +# endif + Vinternal__external_sockname = sockname; + max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8218,6 +8217,10 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); + DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + doc: /* Name of external socket passed to Emacs, or nil if none. */); + Vinternal__external_sockname = Qnil; + DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); @@ -8320,5 +8323,4 @@ returns non-`nil'. */); defsubr (&Sprocess_inherit_coding_system_flag); defsubr (&Slist_system_processes); defsubr (&Sprocess_attributes); - defsubr (&Sget_external_sockname); } -- 2.7.4 --------------9332E000B217EE43AA5F7FAF Content-Type: text/x-patch; name="0003-Update-server-name-version-document-sockname-Bug-242.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0003-Update-server-name-version-document-sockname-Bug-242.pa"; filename*1="tch" >From 705e134823603689cc2fb0a58719bd13eb13250c Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Feb 2018 07:47:45 -0800 Subject: [PATCH 3/5] Update `server-name' :version & document sockname (Bug#24218) * lisp/server.el: (server-name): Update :version tag. * etc/NEWS: Document that `server-name' and `server-socket-dir' automatically update. * doc/misc.texi: (Emacs Server): Likewise. --- etc/NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 8fed15a..772dff7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -248,6 +248,9 @@ forward-comment, scan-sexps, and forward-sexp when parsing backward. The new variable 'comment-use-syntax-ppss' can be set to nil to recover the old behavior if needed. +** The `server-name' and `server-socket-dir' variables are set when a +socket has been pased to Emacs (Bug#24218). + --- ** The 'file-system-info' function is now available on all platforms. instead of just Microsoft platforms. This fixes a 'get-free-disk-space' -- 2.7.4 --------------9332E000B217EE43AA5F7FAF Content-Type: text/x-patch; name="0004-Rename-internal-external-sockname-and-document-Bug-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0004-Rename-internal-external-sockname-and-document-Bug-2.pa"; filename*1="tch" >From 84288f3afb711ac27219263aed5c2caa45608d32 Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Feb 2018 07:47:45 -0800 Subject: [PATCH 4/5] Rename internal--external-sockname and document (Bug#24218) * lisp/server.el: Rename `internal--external-sockname' to `internal-daemon-sockname'. * src/process.c: Likewise. * doc/lispref/processes.texi: Document `internal-daemon-sockname'. --- doc/lispref/processes.texi | 17 ++++++++++++++--- lisp/server.el | 10 +++++----- src/process.c | 6 +++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index af177e0..07317dd 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -2862,9 +2862,9 @@ Network Feature Testing @node Misc Network @section Misc Network Facilities - These additional functions are useful for creating and operating -on network connections. Note that they are supported only on some -systems. + These additional functions and variables are useful for creating and +operating on network connections. Note that they are supported only +on some systems. @defun network-interface-list This function returns a list describing the network interfaces @@ -2913,6 +2913,17 @@ Misc Network @code{:@var{p}} suffix. @end defun +@defvar internal--daemon-sockname +This variable is set to the full path of the socket that has been +passed to Emacs during socket activation. This is then used to update +the @code{server-name} and @code{server-socket-dir} variables to +reflect the name and path of the socket that was used to launch the +Emacs daemon process. + +If Emacs wasn't started with socket activation, the value of this +variable is @code{nil}. +@end defvar + @node Serial Ports @section Communicating with Serial Ports @cindex @file{/dev/tty} diff --git a/lisp/server.el b/lisp/server.el index 70ac51e..744568a 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -258,8 +258,8 @@ server--external-socket-initialized been consumed.") (defcustom server-name - (if internal--external-sockname - (file-name-nondirectory internal--external-sockname) + (if internal-daemon-sockname + (file-name-nondirectory internal-daemon-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; We do not use `temporary-file-directory' here, because emacsclient ;; does not read the init file. (defvar server-socket-dir - (if internal--external-sockname - (file-name-directory internal--external-sockname) + (if internal-daemon-sockname + (file-name-directory internal-daemon-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -631,7 +631,7 @@ server-start ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and internal--external-sockname + (if (and internal-daemon-sockname (not server--external-socket-initialized)) (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. diff --git a/src/process.c b/src/process.c index 8396a93..fe55a48 100644 --- a/src/process.c +++ b/src/process.c @@ -8023,7 +8023,7 @@ init_process_emacs (int sockfd) sockname = conv_sockaddr_to_lisp (&sa.sa, salen); } # endif - Vinternal__external_sockname = sockname; + Vinternal_daemon_sockname = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8217,9 +8217,9 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); - DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname, + DEFVAR_LISP ("internal-daemon-sockname", Vinternal_daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. */); - Vinternal__external_sockname = Qnil; + Vinternal_daemon_sockname = Qnil; DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); -- 2.7.4 --------------9332E000B217EE43AA5F7FAF Content-Type: text/x-patch; name="0005-Finish-renaming-to-internal-daemon-sockname.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0005-Finish-renaming-to-internal-daemon-sockname.patch" >From f5a3f2a5d79308473cd8aa360b2ff1bd72b7f734 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Feb 2018 08:03:33 -0800 Subject: [PATCH 5/5] Finish renaming to internal--daemon-sockname * doc/lispref/processes.texi (Misc Network): Omit discussion of internal--daemon-sockname, as non-Emacs code shouldn't rely on it. * src/process.c (syms_of_process): Rename internal-daemon-sockname to internal--daemon-sockname. All uses changed. --- doc/lispref/processes.texi | 17 +++-------------- lisp/server.el | 10 +++++----- src/process.c | 6 +++--- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 07317dd..af177e0 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -2862,9 +2862,9 @@ Network Feature Testing @node Misc Network @section Misc Network Facilities - These additional functions and variables are useful for creating and -operating on network connections. Note that they are supported only -on some systems. + These additional functions are useful for creating and operating +on network connections. Note that they are supported only on some +systems. @defun network-interface-list This function returns a list describing the network interfaces @@ -2913,17 +2913,6 @@ Misc Network @code{:@var{p}} suffix. @end defun -@defvar internal--daemon-sockname -This variable is set to the full path of the socket that has been -passed to Emacs during socket activation. This is then used to update -the @code{server-name} and @code{server-socket-dir} variables to -reflect the name and path of the socket that was used to launch the -Emacs daemon process. - -If Emacs wasn't started with socket activation, the value of this -variable is @code{nil}. -@end defvar - @node Serial Ports @section Communicating with Serial Ports @cindex @file{/dev/tty} diff --git a/lisp/server.el b/lisp/server.el index 744568a..d393388 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -258,8 +258,8 @@ server--external-socket-initialized been consumed.") (defcustom server-name - (if internal-daemon-sockname - (file-name-nondirectory internal-daemon-sockname) + (if internal--daemon-sockname + (file-name-nondirectory internal--daemon-sockname) "server") "The name of the Emacs server, if this Emacs process creates one. The command `server-start' makes use of this. It should not be @@ -271,8 +271,8 @@ server-name ;; 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) + (if internal--daemon-sockname + (file-name-directory internal--daemon-sockname) (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid)))) "The directory in which to place the server socket. @@ -631,7 +631,7 @@ server-start ;; Check to see if an uninitialized external socket has been ;; passed in, if that is the case, skip checking ;; `server-running-p' as this will return the wrong result. - (if (and internal-daemon-sockname + (if (and internal--daemon-sockname (not server--external-socket-initialized)) (setq server--external-socket-initialized t) ;; Delete the socket files made by previous server invocations. diff --git a/src/process.c b/src/process.c index fe55a48..2ec10b1 100644 --- a/src/process.c +++ b/src/process.c @@ -8023,7 +8023,7 @@ init_process_emacs (int sockfd) sockname = conv_sockaddr_to_lisp (&sa.sa, salen); } # endif - Vinternal_daemon_sockname = sockname; + Vinternal__daemon_sockname = sockname; max_desc = -1; memset (fd_callback_info, 0, sizeof (fd_callback_info)); @@ -8217,9 +8217,9 @@ These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); - DEFVAR_LISP ("internal-daemon-sockname", Vinternal_daemon_sockname, + DEFVAR_LISP ("internal--daemon-sockname", Vinternal__daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. */); - Vinternal_daemon_sockname = Qnil; + Vinternal__daemon_sockname = Qnil; DEFSYM (Qinternal_default_interrupt_process, "internal-default-interrupt-process"); -- 2.7.4 --------------9332E000B217EE43AA5F7FAF--