summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-03-29 14:24:19 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-03-29 14:24:19 -0700
commitd16fb740912bf4874e7087f6f419427516047977 (patch)
tree0704317ab37ce7a842d0cfe3b739d89e98d8b630
parent97d44922da3c22b3973f95892bfa2ee4afc0ceac (diff)
parent4d2e7e17547edda414129aeee910cd0334b4e85e (diff)
downloademacs-d16fb740912bf4874e7087f6f419427516047977.tar.gz
Merge from origin/emacs-24
4d2e7e1 Fixes: debbugs:19175 2e0cfcc Fix the preamble text of the DIR file we install (Bug#20213) 22ece83 src/w32proc.c: Describe in a comment w32 subprocess implementation. Conflicts: ChangeLog src/ChangeLog src/xterm.c
-rw-r--r--ChangeLog5
-rw-r--r--build-aux/dir_top1
-rw-r--r--src/ChangeLog6
-rw-r--r--src/gtkutil.c2
-rw-r--r--src/w32proc.c132
-rw-r--r--src/xterm.c9
6 files changed, 155 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f550c6d9c63..f45e32fbc28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-29 Eli Zaretskii <eliz@gnu.org>
+
+ * build-aux/dir_top (File): Fix the description of selecting a
+ menu item by its number. (Bug#20213)
+
2015-03-29 Paul Eggert <eggert@cs.ucla.edu>
Fix 'commit-msg' to cite 'CONTRIBUTE'
diff --git a/build-aux/dir_top b/build-aux/dir_top
index 321a39dc35e..928da0415ee 100644
--- a/build-aux/dir_top
+++ b/build-aux/dir_top
@@ -15,6 +15,7 @@ The Info Directory
In Emacs Info, you can click mouse button 2 on a menu item
or cross reference to follow it to its target.
Each menu line that starts with a * is a topic you can select with "m".
+ You can also select a topic by typing its ordinal number.
Every third topic has a red * to help pick the right number to type.
* Menu:
diff --git a/src/ChangeLog b/src/ChangeLog
index c11ecb7e3ae..f0ed9e74745 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-29 Jan Djärv <jan.h.d@swipnet.se>
+
+ * gtkutil.c (xg_display_open):
+ * xterm.c (x_display_ok, x_term_init): Block SIGIO when opening
+ a display (Bug#19175).
+
2015-03-29 Martin Rudalics <rudalics@gmx.at>
* gtkutil.c (update_theme_scrollbar_width): Don't round up
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 061af7baa9a..41cc7a74664 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -187,7 +187,9 @@ xg_display_open (char *display_name, Display **dpy)
{
GdkDisplay *gdpy;
+ unrequest_sigio (); // See comment in x_display_ok, xterm.c.
gdpy = gdk_display_open (display_name);
+ request_sigio ();
if (!gdpy_def && gdpy)
{
gdpy_def = gdpy;
diff --git a/src/w32proc.c b/src/w32proc.c
index 2d10534aa47..7d982f831e2 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -786,6 +786,138 @@ alarm (int seconds)
#endif
}
+
+
+/* Here's an overview of how support for subprocesses and
+ network/serial streams is implemented on MS-Windows.
+
+ The management of both subprocesses and network/serial streams
+ circles around the child_procs[] array, which can record up to the
+ grand total of MAX_CHILDREN (= 32) of these. (The reasons for the
+ 32 limitation will become clear below.) Each member of
+ child_procs[] is a child_process structure, defined on w32.h.
+
+ A related data structure is the fd_info[] array, which holds twice
+ as many members, 64, and records the information about file
+ descriptors used for communicating with subprocesses and
+ network/serial devices. Each member of the array is the filedesc
+ structure, which records the Windows handle for communications,
+ such as the read end of the pipe to a subprocess, a socket handle,
+ etc.
+
+ Both these arrays reference each other: there's a member of
+ child_process structure that records the file corresponding
+ descriptor, and there's a member of filedesc structure that holds a
+ pointer to the corresponding child_process.
+
+ Whenever Emacs starts a subprocess or opens a network/serial
+ stream, the function new_child is called to prepare a new
+ child_process structure. new_child looks for the first vacant slot
+ in the child_procs[] array, initializes it, and starts a "reader
+ thread" that will watch the output of the subprocess/stream and its
+ status. (If no vacant slot can be found, new_child returns a
+ failure indication to its caller, and the higher-level Emacs
+ primitive will then fail with EMFILE or EAGAIN.)
+
+ The reader thread started by new_child communicates with the main
+ (a.k.a. "Lisp") thread via two event objects and a status, all of
+ them recorded by the members of the child_process structure in
+ child_procs[]. The event objects serve as semaphores between the
+ reader thread and the 'select' emulation in sys_select, as follows:
+
+ . Initially, the reader thread is waiting for the char_consumed
+ event to become signaled by sys_select, which is an indication
+ for the reader thread to go ahead and try reading more stuff
+ from the subprocess/stream.
+
+ . The reader thread then attempts to read by calling a
+ blocking-read function. When the read call returns, either
+ successfully or with some failure indication, the reader thread
+ updates the status of the read accordingly, and signals the 2nd
+ event object, char_avail, on whose handle sys_select is
+ waiting. This tells sys_select that the file descriptor
+ allocated for the subprocess or the the stream is ready to be
+ read from.
+
+ When the subprocess exits or the network/serial stream is closed,
+ the reader thread sets the status accordingly and exits. It also
+ exits when the main thread sets the ststus to STATUS_READ_ERROR
+ and/or the char_avail and char_consumed event handles are NULL;
+ this is how delete_child, called by Emacs when a subprocess or a
+ stream is terminated, terminates the reader thread as part of
+ deleting the child_process object.
+
+ The sys_select function emulates the Posix 'pselect' function; it
+ is needed because the Windows 'select' function supports only
+ network sockets, while Emacs expects 'pselect' to work for any file
+ descriptor, including pipes and serial streams.
+
+ When sys_select is called, it uses the information in fd_info[]
+ array to convert the file descriptors which it was asked to watch
+ into Windows handles. In general, the handle to watch is the
+ handle of the char_avail event of the child_process structure that
+ corresponds to the file descriptor. In addition, for subprocesses,
+ sys_select watches one more handle: the handle for the subprocess,
+ so that it could emulate the SIGCHLD signal when the subprocess
+ exits.
+
+ If file descriptor zero (stdin) doesn't have its bit set in the
+ 'rfds' argument to sys_select, the function always watches for
+ keyboard interrupts, to be able to return when the user presses
+ C-g.
+
+ Having collected the handles to watch, sys_select calls
+ WaitForMultipleObjects to wait for any one of them to become
+ signaled. Since WaitForMultipleObjects can only watch up to 64
+ handles, Emacs on Windows is limited to maximum 32 child_process
+ objects (since a subprocess consumes 2 handles to be watched, see
+ above).
+
+ When any of the handles become signaled, sys_select does whatever
+ is appropriate for the corresponding child_process object:
+
+ . If it's a handle to the char_avail event, sys_select marks the
+ corresponding bit in 'rfds', and Emacs will then read from that
+ file descriptor.
+
+ . If it's a handle to the process, sys_select calls the SIGCHLD
+ handler, to inform Emacs of the fact that the subprocess
+ exited.
+
+ The waitpid emulation works very similar to sys_select, except that
+ it only watches handles of subprocesses, and doesn't synchronize
+ with the reader thread.
+
+ Because socket descriptors on Windows are handles, while Emacs
+ expects them to be file descriptors, all low-level I/O functions,
+ such as 'read' and 'write', and all socket operations, like
+ 'connect', 'recvfrom', 'accept', etc., are redirected to the
+ corresponding 'sys_*' functions, which must convert a file
+ descriptor to a handle using the fd_info[] array, and then invoke
+ the corresponding Windows API on the handle. Most of these
+ redirected 'sys_*' functions are implemented on w32.c.
+
+ When the file descriptor was produced by functions such as 'open',
+ the corresponding handle is obtained by calling _get_osfhandle. To
+ produce a file descriptor for a socket handle, which has no file
+ descriptor as far as Windows is concerned, the function
+ socket_to_fd opens the null device; the resulting file descriptor
+ will never be used directly in any I/O API, but serves as an index
+ into the fd_info[] array, where the socket handle is stored. The
+ SOCK_HANDLE macro retrieves the handle when given the file
+ descriptor.
+
+ The function sys_kill emulates the Posix 'kill' functionality to
+ terminate other processes. It does that by attaching to the
+ foreground window of the process and sending a Ctrl-C or Ctrl-BREAK
+ signal to the process; if that doesn't work, then it calls
+ TerminateProcess to forcibly terminate the process. Note that this
+ only terminates the immediate process whose PID was passed to
+ sys_kill; it doesn't terminate the child processes of that process.
+ This means, for example, that an Emacs subprocess run through a
+ shell might not be killed, because sys_kill will only terminate the
+ shell. (In practice, however, such problems are very rare.) */
+
/* Defined in <process.h> which conflicts with the local copy */
#define _P_NOWAIT 1
diff --git a/src/xterm.c b/src/xterm.c
index 03c081179a6..bdc85ae71fc 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10684,7 +10684,10 @@ get_bits_and_offset (unsigned long mask, int *bits, int *offset)
bool
x_display_ok (const char *display)
{
+ /* XOpenDisplay fails if it gets a signal. Block SIGIO which may arrive. */
+ unrequest_sigio ();
Display *dpy = XOpenDisplay (display);
+ request_sigio ();
if (!dpy)
return false;
XCloseDisplay (dpy);
@@ -10864,7 +10867,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
/* gtk_init does set_locale. Fix locale before and after. */
fixup_locale ();
+ unrequest_sigio (); /* See comment in x_display_ok. */
gtk_init (&argc, &argv2);
+ request_sigio ();
fixup_locale ();
g_log_remove_handler ("GLib", id);
@@ -10914,10 +10919,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
argv[argc++] = xrm_option;
}
turn_on_atimers (false);
+ unrequest_sigio (); /* See comment in x_display_ok. */
dpy = XtOpenDisplay (Xt_app_con, SSDATA (display_name),
resource_name, EMACS_CLASS,
emacs_options, XtNumber (emacs_options),
&argc, argv);
+ request_sigio ();
turn_on_atimers (true);
#ifdef HAVE_X11XTR6
@@ -10928,7 +10935,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
#else /* not USE_X_TOOLKIT */
XSetLocaleModifiers ("");
+ unrequest_sigio (); // See comment in x_display_ok.
dpy = XOpenDisplay (SSDATA (display_name));
+ request_sigio ();
#endif /* not USE_X_TOOLKIT */
#endif /* not USE_GTK*/