aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-04-26 09:12:14 -0700
committerPaul Eggert2016-04-26 09:13:07 -0700
commit40a03df45353692f73364e488c962f1a7cf2e8bc (patch)
tree73db77552ab96859e688c8898b9b770b99635fc5
parent7b9a5c2a451781f674f0a7ebd71f1061a174f627 (diff)
downloademacs-40a03df45353692f73364e488c962f1a7cf2e8bc.tar.gz
emacs-40a03df45353692f73364e488c962f1a7cf2e8bc.zip
Fix socketd fd startup bug that I introduced
Problem reported by Matthew Leach in: http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00778.html * src/emacs.c (main): Indicate more clearly the coupling between the --daemon option and init_process_emacs. * src/lisp.h: Adjust to API changes. * src/process.c (set_external_socket_descriptor): Remove, replacing by ... (init_process_emacs): ... passing the socket FD here instead. All uses changed.
-rw-r--r--src/emacs.c7
-rw-r--r--src/lisp.h3
-rw-r--r--src/process.c22
3 files changed, 14 insertions, 18 deletions
diff --git a/src/emacs.c b/src/emacs.c
index a738bac4072..a7cbb32e141 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -971,6 +971,9 @@ main (int argc, char **argv)
971 w32_daemon_event = NULL; 971 w32_daemon_event = NULL;
972#endif 972#endif
973 973
974
975 int sockfd = -1;
976
974 if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args) 977 if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
975 || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args)) 978 || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args))
976 { 979 {
@@ -1016,7 +1019,7 @@ main (int argc, char **argv)
1016 else if (systemd_socket == 1 1019 else if (systemd_socket == 1
1017 && (0 < sd_is_socket (SD_LISTEN_FDS_START, 1020 && (0 < sd_is_socket (SD_LISTEN_FDS_START,
1018 AF_UNSPEC, SOCK_STREAM, 1))) 1021 AF_UNSPEC, SOCK_STREAM, 1)))
1019 set_external_socket_descriptor (SD_LISTEN_FDS_START); 1022 sockfd = SD_LISTEN_FDS_START;
1020#endif /* HAVE_LIBSYSTEMD */ 1023#endif /* HAVE_LIBSYSTEMD */
1021 1024
1022#ifndef DAEMON_MUST_EXEC 1025#ifndef DAEMON_MUST_EXEC
@@ -1575,7 +1578,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1575 /* This can create a thread that may call getenv, so it must follow 1578 /* This can create a thread that may call getenv, so it must follow
1576 all calls to putenv and setenv. Also, this sets up 1579 all calls to putenv and setenv. Also, this sets up
1577 add_keyboard_wait_descriptor, which init_display uses. */ 1580 add_keyboard_wait_descriptor, which init_display uses. */
1578 init_process_emacs (); 1581 init_process_emacs (sockfd);
1579 1582
1580 init_keyboard (); /* This too must precede init_sys_modes. */ 1583 init_keyboard (); /* This too must precede init_sys_modes. */
1581 if (!noninteractive) 1584 if (!noninteractive)
diff --git a/src/lisp.h b/src/lisp.h
index c6f8bb89a3f..1fc6130be0b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4181,10 +4181,9 @@ extern void delete_keyboard_wait_descriptor (int);
4181extern void add_gpm_wait_descriptor (int); 4181extern void add_gpm_wait_descriptor (int);
4182extern void delete_gpm_wait_descriptor (int); 4182extern void delete_gpm_wait_descriptor (int);
4183#endif 4183#endif
4184extern void init_process_emacs (void); 4184extern void init_process_emacs (int);
4185extern void syms_of_process (void); 4185extern void syms_of_process (void);
4186extern void setup_process_coding_systems (Lisp_Object); 4186extern void setup_process_coding_systems (Lisp_Object);
4187extern void set_external_socket_descriptor (int);
4188 4187
4189/* Defined in callproc.c. */ 4188/* Defined in callproc.c. */
4190#ifndef DOS_NT 4189#ifndef DOS_NT
diff --git a/src/process.c b/src/process.c
index a222a5b8e26..0dfe1622971 100644
--- a/src/process.c
+++ b/src/process.c
@@ -267,7 +267,10 @@ static int max_process_desc;
267/* The largest descriptor currently in use for input; -1 if none. */ 267/* The largest descriptor currently in use for input; -1 if none. */
268static int max_input_desc; 268static int max_input_desc;
269 269
270/* The descriptor of any socket passed to Emacs; -1 if none. */ 270/* Set the external socket descriptor for Emacs to use when
271 `make-network-process' is called with a non-nil
272 `:use-external-socket' option. The value should be either -1, or
273 the file descriptor of a socket that is already bound. */
271static int external_sock_fd; 274static int external_sock_fd;
272 275
273/* Indexed by descriptor, gives the process (if any) for that descriptor. */ 276/* Indexed by descriptor, gives the process (if any) for that descriptor. */
@@ -7733,24 +7736,14 @@ catch_child_signal (void)
7733} 7736}
7734#endif /* subprocesses */ 7737#endif /* subprocesses */
7735 7738
7736/* Set the external socket descriptor for Emacs to use when
7737 `make-network-process' is called with a non-nil
7738 `:use-external-socket' option. The fd should have been checked to
7739 ensure it is a valid socket and is already bound. */
7740void
7741set_external_socket_descriptor (int fd)
7742{
7743 external_sock_fd = fd;
7744}
7745
7746 7739
7747/* This is not called "init_process" because that is the name of a 7740/* This is not called "init_process" because that is the name of a
7748 Mach system call, so it would cause problems on Darwin systems. */ 7741 Mach system call, so it would cause problems on Darwin systems. */
7749void 7742void
7750init_process_emacs (void) 7743init_process_emacs (int sockfd)
7751{ 7744{
7752#ifdef subprocesses 7745#ifdef subprocesses
7753 register int i; 7746 int i;
7754 7747
7755 inhibit_sentinels = 0; 7748 inhibit_sentinels = 0;
7756 7749
@@ -7772,7 +7765,8 @@ init_process_emacs (void)
7772 FD_ZERO (&non_keyboard_wait_mask); 7765 FD_ZERO (&non_keyboard_wait_mask);
7773 FD_ZERO (&non_process_wait_mask); 7766 FD_ZERO (&non_process_wait_mask);
7774 FD_ZERO (&write_mask); 7767 FD_ZERO (&write_mask);
7775 max_process_desc = max_input_desc = external_sock_fd = -1; 7768 max_process_desc = max_input_desc = -1;
7769 external_sock_fd = sockfd;
7776 memset (fd_callback_info, 0, sizeof (fd_callback_info)); 7770 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7777 7771
7778 FD_ZERO (&connect_wait_mask); 7772 FD_ZERO (&connect_wait_mask);