aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-02-12 12:52:43 -0800
committerPaul Eggert2018-02-12 12:57:58 -0800
commitd43a724f4ee247ad7a95d9e6ef174c7d16195fbe (patch)
tree48d9180e3ecfe87dea83b06939d2d6d36ac1d158 /src
parente1ca0ea87222e70710b3878ac80ed01f2378f050 (diff)
downloademacs-d43a724f4ee247ad7a95d9e6ef174c7d16195fbe.tar.gz
emacs-d43a724f4ee247ad7a95d9e6ef174c7d16195fbe.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c16
-rw-r--r--src/lisp.h2
-rw-r--r--src/process.c58
3 files changed, 34 insertions, 42 deletions
diff --git a/src/emacs.c b/src/emacs.c
index c423faf6c0d..8ea61b71fb7 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -60,7 +60,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
60#ifdef HAVE_LIBSYSTEMD 60#ifdef HAVE_LIBSYSTEMD
61# include <systemd/sd-daemon.h> 61# include <systemd/sd-daemon.h>
62# include <sys/socket.h> 62# include <sys/socket.h>
63# include <sys/un.h>
64#endif 63#endif
65 64
66#ifdef HAVE_WINDOW_SYSTEM 65#ifdef HAVE_WINDOW_SYSTEM
@@ -1003,7 +1002,6 @@ main (int argc, char **argv)
1003 1002
1004 1003
1005 int sockfd = -1; 1004 int sockfd = -1;
1006 char *sockname = NULL;
1007 1005
1008 if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args) 1006 if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args)
1009 || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args)) 1007 || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, &skip_args))
@@ -1063,16 +1061,8 @@ main (int argc, char **argv)
1063 "Try 'Accept=false' in the Emacs socket unit file.\n")); 1061 "Try 'Accept=false' in the Emacs socket unit file.\n"));
1064 else if (systemd_socket == 1 1062 else if (systemd_socket == 1
1065 && (0 < sd_is_socket (SD_LISTEN_FDS_START, 1063 && (0 < sd_is_socket (SD_LISTEN_FDS_START,
1066 AF_UNIX, SOCK_STREAM, 1))) 1064 AF_UNSPEC, SOCK_STREAM, 1)))
1067 { 1065 sockfd = SD_LISTEN_FDS_START;
1068 struct sockaddr_un sockaddr;
1069 socklen_t sockaddr_sz = sizeof(sockaddr);
1070
1071 sockfd = SD_LISTEN_FDS_START;
1072
1073 if (!getsockname(sockfd, &sockaddr, &sockaddr_sz))
1074 sockname = strdup(sockaddr.sun_path);
1075 }
1076#endif /* HAVE_LIBSYSTEMD */ 1066#endif /* HAVE_LIBSYSTEMD */
1077 1067
1078#ifdef USE_GTK 1068#ifdef USE_GTK
@@ -1670,7 +1660,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1670 /* This can create a thread that may call getenv, so it must follow 1660 /* This can create a thread that may call getenv, so it must follow
1671 all calls to putenv and setenv. Also, this sets up 1661 all calls to putenv and setenv. Also, this sets up
1672 add_keyboard_wait_descriptor, which init_display uses. */ 1662 add_keyboard_wait_descriptor, which init_display uses. */
1673 init_process_emacs (sockfd, sockname); 1663 init_process_emacs (sockfd);
1674 1664
1675 init_keyboard (); /* This too must precede init_sys_modes. */ 1665 init_keyboard (); /* This too must precede init_sys_modes. */
1676 if (!noninteractive) 1666 if (!noninteractive)
diff --git a/src/lisp.h b/src/lisp.h
index 0bd0e5e53cf..a7f0a1d78ff 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4316,7 +4316,7 @@ extern void delete_keyboard_wait_descriptor (int);
4316extern void add_gpm_wait_descriptor (int); 4316extern void add_gpm_wait_descriptor (int);
4317extern void delete_gpm_wait_descriptor (int); 4317extern void delete_gpm_wait_descriptor (int);
4318#endif 4318#endif
4319extern void init_process_emacs (int, char *); 4319extern void init_process_emacs (int);
4320extern void syms_of_process (void); 4320extern void syms_of_process (void);
4321extern void setup_process_coding_systems (Lisp_Object); 4321extern void setup_process_coding_systems (Lisp_Object);
4322 4322
diff --git a/src/process.c b/src/process.c
index 405c06db46d..8396a939c2b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -160,6 +160,18 @@ static bool kbd_is_on_hold;
160 when exiting. */ 160 when exiting. */
161bool inhibit_sentinels; 161bool inhibit_sentinels;
162 162
163union u_sockaddr
164{
165 struct sockaddr sa;
166 struct sockaddr_in in;
167#ifdef AF_INET6
168 struct sockaddr_in6 in6;
169#endif
170#ifdef HAVE_LOCAL_SOCKETS
171 struct sockaddr_un un;
172#endif
173};
174
163#ifdef subprocesses 175#ifdef subprocesses
164 176
165#ifndef SOCK_CLOEXEC 177#ifndef SOCK_CLOEXEC
@@ -276,10 +288,6 @@ static int max_desc;
276 the file descriptor of a socket that is already bound. */ 288 the file descriptor of a socket that is already bound. */
277static int external_sock_fd; 289static int external_sock_fd;
278 290
279/* The name (path) of the socket that was passed to Emacs, when
280 `external_sock_fd' is not -1. */
281static const char *external_sock_name = NULL;
282
283/* Indexed by descriptor, gives the process (if any) for that descriptor. */ 291/* Indexed by descriptor, gives the process (if any) for that descriptor. */
284static Lisp_Object chan_process[FD_SETSIZE]; 292static Lisp_Object chan_process[FD_SETSIZE];
285static void wait_for_socket_fds (Lisp_Object, char const *); 293static void wait_for_socket_fds (Lisp_Object, char const *);
@@ -4677,16 +4685,7 @@ server_accept_connection (Lisp_Object server, int channel)
4677 struct Lisp_Process *ps = XPROCESS (server); 4685 struct Lisp_Process *ps = XPROCESS (server);
4678 struct Lisp_Process *p; 4686 struct Lisp_Process *p;
4679 int s; 4687 int s;
4680 union u_sockaddr { 4688 union u_sockaddr saddr;
4681 struct sockaddr sa;
4682 struct sockaddr_in in;
4683#ifdef AF_INET6
4684 struct sockaddr_in6 in6;
4685#endif
4686#ifdef HAVE_LOCAL_SOCKETS
4687 struct sockaddr_un un;
4688#endif
4689 } saddr;
4690 socklen_t len = sizeof saddr; 4689 socklen_t len = sizeof saddr;
4691 ptrdiff_t count; 4690 ptrdiff_t count;
4692 4691
@@ -7976,21 +7975,10 @@ restore_nofile_limit (void)
7976} 7975}
7977 7976
7978 7977
7979DEFUN ("get-external-sockname", Fget_external_sockname, Sget_external_sockname, 0, 0, 0,
7980 doc: /* Return the path of an external socket passed to Emacs.
7981Otherwise return nil. */)
7982 (void)
7983{
7984 if (external_sock_name)
7985 return make_string(external_sock_name, strlen(external_sock_name));
7986 else
7987 return Qnil;
7988}
7989
7990/* This is not called "init_process" because that is the name of a 7978/* This is not called "init_process" because that is the name of a
7991 Mach system call, so it would cause problems on Darwin systems. */ 7979 Mach system call, so it would cause problems on Darwin systems. */
7992void 7980void
7993init_process_emacs (int sockfd, char *sockname) 7981init_process_emacs (int sockfd)
7994{ 7982{
7995#ifdef subprocesses 7983#ifdef subprocesses
7996 int i; 7984 int i;
@@ -8025,7 +8013,18 @@ init_process_emacs (int sockfd, char *sockname)
8025#endif 8013#endif
8026 8014
8027 external_sock_fd = sockfd; 8015 external_sock_fd = sockfd;
8028 external_sock_name = sockname; 8016 Lisp_Object sockname = Qnil;
8017# if HAVE_GETSOCKNAME
8018 if (0 <= sockfd)
8019 {
8020 union u_sockaddr sa;
8021 socklen_t salen = sizeof sa;
8022 if (getsockname (sockfd, &sa.sa, &salen) == 0)
8023 sockname = conv_sockaddr_to_lisp (&sa.sa, salen);
8024 }
8025# endif
8026 Vinternal__external_sockname = sockname;
8027
8029 max_desc = -1; 8028 max_desc = -1;
8030 memset (fd_callback_info, 0, sizeof (fd_callback_info)); 8029 memset (fd_callback_info, 0, sizeof (fd_callback_info));
8031 8030
@@ -8218,6 +8217,10 @@ These functions are called in the order of the list, until one of them
8218returns non-`nil'. */); 8217returns non-`nil'. */);
8219 Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); 8218 Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process);
8220 8219
8220 DEFVAR_LISP ("internal--external-sockname", Vinternal__external_sockname,
8221 doc: /* Name of external socket passed to Emacs, or nil if none. */);
8222 Vinternal__external_sockname = Qnil;
8223
8221 DEFSYM (Qinternal_default_interrupt_process, 8224 DEFSYM (Qinternal_default_interrupt_process,
8222 "internal-default-interrupt-process"); 8225 "internal-default-interrupt-process");
8223 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); 8226 DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions");
@@ -8320,5 +8323,4 @@ returns non-`nil'. */);
8320 defsubr (&Sprocess_inherit_coding_system_flag); 8323 defsubr (&Sprocess_inherit_coding_system_flag);
8321 defsubr (&Slist_system_processes); 8324 defsubr (&Slist_system_processes);
8322 defsubr (&Sprocess_attributes); 8325 defsubr (&Sprocess_attributes);
8323 defsubr (&Sget_external_sockname);
8324} 8326}