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
;; 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.
(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)))
#ifdef HAVE_LIBSYSTEMD
# include <systemd/sd-daemon.h>
# include <sys/socket.h>
-# include <sys/un.h>
#endif
#ifdef HAVE_WINDOW_SYSTEM
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))
"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
/* 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)
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);
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
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 *);
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;
}
\f
-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;
#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));
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");
defsubr (&Sprocess_inherit_coding_system_flag);
defsubr (&Slist_system_processes);
defsubr (&Sprocess_attributes);
- defsubr (&Sget_external_sockname);
}