aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
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/process.c
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/process.c')
-rw-r--r--src/process.c58
1 files changed, 30 insertions, 28 deletions
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}