aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2015-03-29 14:24:19 -0700
committerPaul Eggert2015-03-29 14:24:19 -0700
commitd16fb740912bf4874e7087f6f419427516047977 (patch)
tree0704317ab37ce7a842d0cfe3b739d89e98d8b630 /src
parent97d44922da3c22b3973f95892bfa2ee4afc0ceac (diff)
parent4d2e7e17547edda414129aeee910cd0334b4e85e (diff)
downloademacs-d16fb740912bf4874e7087f6f419427516047977.tar.gz
emacs-d16fb740912bf4874e7087f6f419427516047977.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/gtkutil.c2
-rw-r--r--src/w32proc.c132
-rw-r--r--src/xterm.c9
4 files changed, 149 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c11ecb7e3ae..f0ed9e74745 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12015-03-29 Jan Djärv <jan.h.d@swipnet.se>
2
3 * gtkutil.c (xg_display_open):
4 * xterm.c (x_display_ok, x_term_init): Block SIGIO when opening
5 a display (Bug#19175).
6
12015-03-29 Martin Rudalics <rudalics@gmx.at> 72015-03-29 Martin Rudalics <rudalics@gmx.at>
2 8
3 * gtkutil.c (update_theme_scrollbar_width): Don't round up 9 * 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)
187{ 187{
188 GdkDisplay *gdpy; 188 GdkDisplay *gdpy;
189 189
190 unrequest_sigio (); // See comment in x_display_ok, xterm.c.
190 gdpy = gdk_display_open (display_name); 191 gdpy = gdk_display_open (display_name);
192 request_sigio ();
191 if (!gdpy_def && gdpy) 193 if (!gdpy_def && gdpy)
192 { 194 {
193 gdpy_def = gdpy; 195 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)
786#endif 786#endif
787} 787}
788 788
789
790
791/* Here's an overview of how support for subprocesses and
792 network/serial streams is implemented on MS-Windows.
793
794 The management of both subprocesses and network/serial streams
795 circles around the child_procs[] array, which can record up to the
796 grand total of MAX_CHILDREN (= 32) of these. (The reasons for the
797 32 limitation will become clear below.) Each member of
798 child_procs[] is a child_process structure, defined on w32.h.
799
800 A related data structure is the fd_info[] array, which holds twice
801 as many members, 64, and records the information about file
802 descriptors used for communicating with subprocesses and
803 network/serial devices. Each member of the array is the filedesc
804 structure, which records the Windows handle for communications,
805 such as the read end of the pipe to a subprocess, a socket handle,
806 etc.
807
808 Both these arrays reference each other: there's a member of
809 child_process structure that records the file corresponding
810 descriptor, and there's a member of filedesc structure that holds a
811 pointer to the corresponding child_process.
812
813 Whenever Emacs starts a subprocess or opens a network/serial
814 stream, the function new_child is called to prepare a new
815 child_process structure. new_child looks for the first vacant slot
816 in the child_procs[] array, initializes it, and starts a "reader
817 thread" that will watch the output of the subprocess/stream and its
818 status. (If no vacant slot can be found, new_child returns a
819 failure indication to its caller, and the higher-level Emacs
820 primitive will then fail with EMFILE or EAGAIN.)
821
822 The reader thread started by new_child communicates with the main
823 (a.k.a. "Lisp") thread via two event objects and a status, all of
824 them recorded by the members of the child_process structure in
825 child_procs[]. The event objects serve as semaphores between the
826 reader thread and the 'select' emulation in sys_select, as follows:
827
828 . Initially, the reader thread is waiting for the char_consumed
829 event to become signaled by sys_select, which is an indication
830 for the reader thread to go ahead and try reading more stuff
831 from the subprocess/stream.
832
833 . The reader thread then attempts to read by calling a
834 blocking-read function. When the read call returns, either
835 successfully or with some failure indication, the reader thread
836 updates the status of the read accordingly, and signals the 2nd
837 event object, char_avail, on whose handle sys_select is
838 waiting. This tells sys_select that the file descriptor
839 allocated for the subprocess or the the stream is ready to be
840 read from.
841
842 When the subprocess exits or the network/serial stream is closed,
843 the reader thread sets the status accordingly and exits. It also
844 exits when the main thread sets the ststus to STATUS_READ_ERROR
845 and/or the char_avail and char_consumed event handles are NULL;
846 this is how delete_child, called by Emacs when a subprocess or a
847 stream is terminated, terminates the reader thread as part of
848 deleting the child_process object.
849
850 The sys_select function emulates the Posix 'pselect' function; it
851 is needed because the Windows 'select' function supports only
852 network sockets, while Emacs expects 'pselect' to work for any file
853 descriptor, including pipes and serial streams.
854
855 When sys_select is called, it uses the information in fd_info[]
856 array to convert the file descriptors which it was asked to watch
857 into Windows handles. In general, the handle to watch is the
858 handle of the char_avail event of the child_process structure that
859 corresponds to the file descriptor. In addition, for subprocesses,
860 sys_select watches one more handle: the handle for the subprocess,
861 so that it could emulate the SIGCHLD signal when the subprocess
862 exits.
863
864 If file descriptor zero (stdin) doesn't have its bit set in the
865 'rfds' argument to sys_select, the function always watches for
866 keyboard interrupts, to be able to return when the user presses
867 C-g.
868
869 Having collected the handles to watch, sys_select calls
870 WaitForMultipleObjects to wait for any one of them to become
871 signaled. Since WaitForMultipleObjects can only watch up to 64
872 handles, Emacs on Windows is limited to maximum 32 child_process
873 objects (since a subprocess consumes 2 handles to be watched, see
874 above).
875
876 When any of the handles become signaled, sys_select does whatever
877 is appropriate for the corresponding child_process object:
878
879 . If it's a handle to the char_avail event, sys_select marks the
880 corresponding bit in 'rfds', and Emacs will then read from that
881 file descriptor.
882
883 . If it's a handle to the process, sys_select calls the SIGCHLD
884 handler, to inform Emacs of the fact that the subprocess
885 exited.
886
887 The waitpid emulation works very similar to sys_select, except that
888 it only watches handles of subprocesses, and doesn't synchronize
889 with the reader thread.
890
891 Because socket descriptors on Windows are handles, while Emacs
892 expects them to be file descriptors, all low-level I/O functions,
893 such as 'read' and 'write', and all socket operations, like
894 'connect', 'recvfrom', 'accept', etc., are redirected to the
895 corresponding 'sys_*' functions, which must convert a file
896 descriptor to a handle using the fd_info[] array, and then invoke
897 the corresponding Windows API on the handle. Most of these
898 redirected 'sys_*' functions are implemented on w32.c.
899
900 When the file descriptor was produced by functions such as 'open',
901 the corresponding handle is obtained by calling _get_osfhandle. To
902 produce a file descriptor for a socket handle, which has no file
903 descriptor as far as Windows is concerned, the function
904 socket_to_fd opens the null device; the resulting file descriptor
905 will never be used directly in any I/O API, but serves as an index
906 into the fd_info[] array, where the socket handle is stored. The
907 SOCK_HANDLE macro retrieves the handle when given the file
908 descriptor.
909
910 The function sys_kill emulates the Posix 'kill' functionality to
911 terminate other processes. It does that by attaching to the
912 foreground window of the process and sending a Ctrl-C or Ctrl-BREAK
913 signal to the process; if that doesn't work, then it calls
914 TerminateProcess to forcibly terminate the process. Note that this
915 only terminates the immediate process whose PID was passed to
916 sys_kill; it doesn't terminate the child processes of that process.
917 This means, for example, that an Emacs subprocess run through a
918 shell might not be killed, because sys_kill will only terminate the
919 shell. (In practice, however, such problems are very rare.) */
920
789/* Defined in <process.h> which conflicts with the local copy */ 921/* Defined in <process.h> which conflicts with the local copy */
790#define _P_NOWAIT 1 922#define _P_NOWAIT 1
791 923
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)
10684bool 10684bool
10685x_display_ok (const char *display) 10685x_display_ok (const char *display)
10686{ 10686{
10687 /* XOpenDisplay fails if it gets a signal. Block SIGIO which may arrive. */
10688 unrequest_sigio ();
10687 Display *dpy = XOpenDisplay (display); 10689 Display *dpy = XOpenDisplay (display);
10690 request_sigio ();
10688 if (!dpy) 10691 if (!dpy)
10689 return false; 10692 return false;
10690 XCloseDisplay (dpy); 10693 XCloseDisplay (dpy);
@@ -10864,7 +10867,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10864 10867
10865 /* gtk_init does set_locale. Fix locale before and after. */ 10868 /* gtk_init does set_locale. Fix locale before and after. */
10866 fixup_locale (); 10869 fixup_locale ();
10870 unrequest_sigio (); /* See comment in x_display_ok. */
10867 gtk_init (&argc, &argv2); 10871 gtk_init (&argc, &argv2);
10872 request_sigio ();
10868 fixup_locale (); 10873 fixup_locale ();
10869 10874
10870 g_log_remove_handler ("GLib", id); 10875 g_log_remove_handler ("GLib", id);
@@ -10914,10 +10919,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10914 argv[argc++] = xrm_option; 10919 argv[argc++] = xrm_option;
10915 } 10920 }
10916 turn_on_atimers (false); 10921 turn_on_atimers (false);
10922 unrequest_sigio (); /* See comment in x_display_ok. */
10917 dpy = XtOpenDisplay (Xt_app_con, SSDATA (display_name), 10923 dpy = XtOpenDisplay (Xt_app_con, SSDATA (display_name),
10918 resource_name, EMACS_CLASS, 10924 resource_name, EMACS_CLASS,
10919 emacs_options, XtNumber (emacs_options), 10925 emacs_options, XtNumber (emacs_options),
10920 &argc, argv); 10926 &argc, argv);
10927 request_sigio ();
10921 turn_on_atimers (true); 10928 turn_on_atimers (true);
10922 10929
10923#ifdef HAVE_X11XTR6 10930#ifdef HAVE_X11XTR6
@@ -10928,7 +10935,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10928 10935
10929#else /* not USE_X_TOOLKIT */ 10936#else /* not USE_X_TOOLKIT */
10930 XSetLocaleModifiers (""); 10937 XSetLocaleModifiers ("");
10938 unrequest_sigio (); // See comment in x_display_ok.
10931 dpy = XOpenDisplay (SSDATA (display_name)); 10939 dpy = XOpenDisplay (SSDATA (display_name));
10940 request_sigio ();
10932#endif /* not USE_X_TOOLKIT */ 10941#endif /* not USE_X_TOOLKIT */
10933#endif /* not USE_GTK*/ 10942#endif /* not USE_GTK*/
10934 10943