annotate src/w32proc.c @ 15415:68887d34a610

(restrict_dos_process): Renamed from can_run_dos_process. (sys_spawnve): Refer to restrict_dos_process.
author Richard M. Stallman <rms@gnu.org>
date Wed, 12 Jun 1996 16:02:09 +0000
parents 1a917c5d944c
children 424ef4258b34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Process support for Windows NT port of GNU EMACS.
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
4 This file is part of GNU Emacs.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
9 any later version.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
14 GNU General Public License for more details.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
19 Boston, MA 02111-1307, USA.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 Drew Bliss Oct 14, 1993
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 Adapted from alarm.c by Tim Fleehart
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 #include <stdio.h>
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 #include <stdlib.h>
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 #include <errno.h>
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 #include <io.h>
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
29 #include <fcntl.h>
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 #include <signal.h>
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
32 /* must include CRT headers *before* config.h */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
33 #include "config.h"
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
34 #undef signal
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
35 #undef wait
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
36 #undef spawnve
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
37 #undef select
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
38 #undef kill
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
39
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 #include <windows.h>
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 #include "lisp.h"
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 #include "nt.h"
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 #include "systime.h"
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
45 #include "syswait.h"
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
46 #include "process.h"
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
47
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
48 /* Control whether spawnve quotes arguments as necessary to ensure
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
49 correct parsing by child process. Because not all uses of spawnve
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
50 are careful about constructing argv arrays, we make this behaviour
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
51 conditional (off by default). */
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
52 Lisp_Object Vwin32_quote_process_args;
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
53
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
54 /* Time to sleep before reading from a subprocess output pipe - this
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
55 avoids the inefficiency of frequently reading small amounts of data.
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
56 This is primarily necessary for handling DOS processes on Windows 95,
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
57 but is useful for Win32 processes on both Win95 and NT as well. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
58 Lisp_Object Vwin32_pipe_read_delay;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
59
15325
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
60 /* Control conversion of upper case file names to lower case.
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
61 nil means no, t means yes. */
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
62 Lisp_Object Vwin32_downcase_file_names;
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
63
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
64 /* Keep track of whether we have already started a DOS program, and
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
65 whether we can run them in the first place. */
15415
68887d34a610 (restrict_dos_process): Renamed from can_run_dos_process.
Richard M. Stallman <rms@gnu.org>
parents: 15356
diff changeset
66 BOOL restrict_dos_process;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
67 BOOL dos_process_running;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
68
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
69 #ifndef SYS_SIGLIST_DECLARED
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
70 extern char *sys_siglist[];
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
71 #endif
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
73 #ifdef EMACSDEBUG
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
74 void _DebPrint (const char *fmt, ...)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
76 char buf[1024];
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 va_list args;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 va_start (args, fmt);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 vsprintf (buf, fmt, args);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 va_end (args);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 OutputDebugString (buf);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
86 typedef void (_CALLBACK_ *signal_handler)(int);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 /* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 static signal_handler sig_handlers[NSIG];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 /* Fake signal implementation to record the SIGCHLD handler. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 signal_handler
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
93 sys_signal (int sig, signal_handler handler)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 signal_handler old;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 if (sig != SIGCHLD)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 return SIG_ERR;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 old = sig_handlers[sig];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 sig_handlers[sig] = handler;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 return old;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
107 /* Defined in <process.h> which conflicts with the local copy */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
108 #define _P_NOWAIT 1
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
109
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
110 /* Child process management list. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
111 int child_proc_count = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
112 child_process child_procs[ MAX_CHILDREN ];
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
113 child_process *dead_child = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
114
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
115 DWORD WINAPI reader_thread (void *arg);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
116
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 /* Find an unused process slot. */
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
118 child_process *
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 new_child (void)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
122 DWORD id;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 if (!CHILD_ACTIVE (cp))
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
126 goto Initialise;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
127 if (child_proc_count == MAX_CHILDREN)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
128 return NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
129 cp = &child_procs[child_proc_count++];
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
130
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
131 Initialise:
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
132 memset (cp, 0, sizeof(*cp));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
133 cp->fd = -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
134 cp->pid = -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
135 cp->procinfo.hProcess = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
136 cp->status = STATUS_READ_ERROR;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
137
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
138 /* use manual reset event so that select() will function properly */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
139 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
140 if (cp->char_avail)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
141 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
142 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
143 if (cp->char_consumed)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
144 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
145 cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
146 if (cp->thrd)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
147 return cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
148 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
149 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
150 delete_child (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
151 return NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
152 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
153
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
154 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
155 delete_child (child_process *cp)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
156 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
157 int i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
158
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
159 /* Should not be deleting a child that is still needed. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
160 for (i = 0; i < MAXDESC; i++)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
161 if (fd_info[i].cp == cp)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
162 abort ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
163
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
164 if (!CHILD_ACTIVE (cp))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
165 return;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
166
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
167 /* reap thread if necessary */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
168 if (cp->thrd)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
169 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
170 DWORD rc;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
171
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
172 if (GetExitCodeThread (cp->thrd, &rc) && rc == STILL_ACTIVE)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
173 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
174 /* let the thread exit cleanly if possible */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
175 cp->status = STATUS_READ_ERROR;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
176 SetEvent (cp->char_consumed);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
177 if (WaitForSingleObject (cp->thrd, 1000) != WAIT_OBJECT_0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
178 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
179 DebPrint (("delete_child.WaitForSingleObject (thread) failed "
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
180 "with %lu for fd %ld\n", GetLastError (), cp->fd));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
181 TerminateThread (cp->thrd, 0);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
182 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
183 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
184 CloseHandle (cp->thrd);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
185 cp->thrd = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
186 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
187 if (cp->char_avail)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
188 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
189 CloseHandle (cp->char_avail);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
190 cp->char_avail = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
191 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
192 if (cp->char_consumed)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
193 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
194 CloseHandle (cp->char_consumed);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
195 cp->char_consumed = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
196 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
197
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
198 /* update child_proc_count (highest numbered slot in use plus one) */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
199 if (cp == child_procs + child_proc_count - 1)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
200 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
201 for (i = child_proc_count-1; i >= 0; i--)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
202 if (CHILD_ACTIVE (&child_procs[i]))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
203 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
204 child_proc_count = i + 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
205 break;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
206 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
207 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
208 if (i < 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
209 child_proc_count = 0;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 /* Find a child by pid. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 static child_process *
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 find_child_pid (DWORD pid)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
217
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 if (CHILD_ACTIVE (cp) && pid == cp->pid)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 return cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 return NULL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
225 /* Thread proc for child process and socket reader threads. Each thread
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
226 is normally blocked until woken by select() to check for input by
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
227 reading one char. When the read completes, char_avail is signalled
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
228 to wake up the select emulator and the thread blocks itself again. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 DWORD WINAPI
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 reader_thread (void *arg)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 child_process *cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 /* Our identity */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 cp = (child_process *)arg;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 /* We have to wait for the go-ahead before we can start */
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
238 if (cp == NULL ||
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
239 WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
240 return 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
241
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 for (;;)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
244 int rc;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
245
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
246 rc = _sys_read_ahead (cp->fd);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
247
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
248 /* The name char_avail is a misnomer - it really just means the
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
249 read-ahead has completed, whether successfully or not. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 if (!SetEvent (cp->char_avail))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 GetLastError (), cp->fd));
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
254 return 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
255 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
256
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
257 if (rc == STATUS_READ_ERROR)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
258 return 1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 /* If the read died, the child has died so let the thread die */
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
261 if (rc == STATUS_READ_FAILED)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 break;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 /* Wait until our input is acknowledged before reading again */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 DebPrint (("reader_thread.WaitForSingleObject failed with "
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 "%lu for fd %ld\n", GetLastError (), cp->fd));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 break;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 static BOOL
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 create_child (char *exe, char *cmdline, char *env,
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
277 int * pPid, child_process *cp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 STARTUPINFO start;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 SECURITY_ATTRIBUTES sec_attrs;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 SECURITY_DESCRIPTOR sec_desc;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
283 if (cp == NULL) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 memset (&start, 0, sizeof (start));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 start.cb = sizeof (start);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
13425
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
288 #ifdef HAVE_NTGUI
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
289 start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
290 start.wShowWindow = SW_HIDE;
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
291
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
292 start.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
293 start.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
294 start.hStdError = GetStdHandle (STD_ERROR_HANDLE);
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
295 #endif /* HAVE_NTGUI */
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
296
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 /* Explicitly specify no security */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 if (!InitializeSecurityDescriptor (&sec_desc, SECURITY_DESCRIPTOR_REVISION))
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
299 goto EH_Fail;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 if (!SetSecurityDescriptorDacl (&sec_desc, TRUE, NULL, FALSE))
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
301 goto EH_Fail;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 sec_attrs.nLength = sizeof (sec_attrs);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 sec_attrs.lpSecurityDescriptor = &sec_desc;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 sec_attrs.bInheritHandle = FALSE;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 if (!CreateProcess (exe, cmdline, &sec_attrs, NULL, TRUE,
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
307 CREATE_NEW_PROCESS_GROUP,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
308 env, NULL,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
309 &start, &cp->procinfo))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
310 goto EH_Fail;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
311
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
312 cp->pid = (int) cp->procinfo.dwProcessId;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
313
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
314 /* Hack for Windows 95, which assigns large (ie negative) pids */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
315 if (cp->pid < 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
316 cp->pid = -cp->pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
317
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
318 /* pid must fit in a Lisp_Int */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
319 cp->pid = (cp->pid & VALMASK);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
320
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
321
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
322 *pPid = cp->pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 return TRUE;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 EH_Fail:
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
327 DebPrint (("create_child.CreateProcess failed: %ld\n", GetLastError()););
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 return FALSE;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 /* create_child doesn't know what emacs' file handle will be for waiting
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 on output from the child, so we need to make this additional call
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 to register the handle with the process
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 This way the select emulator knows how to match file handles with
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 entries in child_procs. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 void
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 register_child (int pid, int fd)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 child_process *cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 cp = find_child_pid (pid);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 if (cp == NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 DebPrint (("register_child unable to find pid %lu\n", pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 return;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 #ifdef FULL_DEBUG
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 DebPrint (("register_child registered fd %d with pid %lu\n", fd, pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 cp->fd = fd;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
353
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
354 /* thread is initially blocked until select is called; set status so
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
355 that select will release thread */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
356 cp->status = STATUS_READ_ACKNOWLEDGED;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
358 /* attach child_process to fd_info */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
359 if (fd_info[fd].cp != NULL)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
361 DebPrint (("register_child: fd_info[%d] apparently in use!\n", fd));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
362 abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
364
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
365 fd_info[fd].cp = cp;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 /* When a process dies its pipe will break so the reader thread will
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 signal failure to the select emulator.
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 The select emulator then calls this routine to clean up.
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 Since the thread signaled failure we can assume it is exiting. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 static void
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
373 reap_subprocess (child_process *cp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
375 if (cp->procinfo.hProcess)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
377 /* Reap the process */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
378 if (WaitForSingleObject (cp->procinfo.hProcess, INFINITE) != WAIT_OBJECT_0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
379 DebPrint (("reap_subprocess.WaitForSingleObject (process) failed "
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
380 "with %lu for fd %ld\n", GetLastError (), cp->fd));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
381 CloseHandle (cp->procinfo.hProcess);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
382 cp->procinfo.hProcess = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
383 CloseHandle (cp->procinfo.hThread);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
384 cp->procinfo.hThread = NULL;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
385
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
386 /* If this was a DOS process, indicate that it is now safe to
15415
68887d34a610 (restrict_dos_process): Renamed from can_run_dos_process.
Richard M. Stallman <rms@gnu.org>
parents: 15356
diff changeset
387 start a new one. dos_process_running is only referred to under
68887d34a610 (restrict_dos_process): Renamed from can_run_dos_process.
Richard M. Stallman <rms@gnu.org>
parents: 15356
diff changeset
388 Win95, so it doesn't matter if it is incorrect on NT. */
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
389 if (cp->is_dos_process)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
390 dos_process_running = FALSE;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
392
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
393 /* For asynchronous children, the child_proc resources will be freed
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
394 when the last pipe read descriptor is closed; for synchronous
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
395 children, we must explicitly free the resources now because
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
396 register_child has not been called. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
397 if (cp->fd == -1)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
398 delete_child (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 /* Wait for any of our existing child processes to die
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 When it does, close its handle
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 Return the pid and fill in the status if non-NULL. */
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
404
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
406 sys_wait (int *status)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 DWORD active, retval;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 int nh;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
410 int pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 child_process *cp, *cps[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 HANDLE wait_hnd[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 if (dead_child != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 /* We want to wait for a specific child */
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
418 wait_hnd[nh] = dead_child->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 cps[nh] = dead_child;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
420 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
426 /* some child_procs might be sockets; ignore them */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
427 if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
429 wait_hnd[nh] = cp->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 cps[nh] = cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
431 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 if (nh == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 /* Nothing to wait on, so fail */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 errno = ECHILD;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, INFINITE);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 if (active == WAIT_FAILED)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 errno = EBADF;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 else if (active >= WAIT_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 if (!GetExitCodeProcess (wait_hnd[active], &retval))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 DebPrint (("Wait.GetExitCodeProcess failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 GetLastError ()));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 retval = 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 if (retval == STILL_ACTIVE)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 DebPrint (("Wait.WaitForMultipleObjects returned an active process\n"));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 }
12325
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
479
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
480 /* Massage the exit code from the process to match the format expected
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 13931
diff changeset
481 by the WIFSTOPPED et al macros in syswait.h. Only WIFSIGNALED and
12325
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
482 WIFEXITED are supported; WIFSTOPPED doesn't make sense under NT. */
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
483
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
484 if (retval == STATUS_CONTROL_C_EXIT)
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
485 retval = SIGINT;
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
486 else
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
487 retval <<= 8;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
488
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 cp = cps[active];
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
490 pid = cp->pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
491 #ifdef FULL_DEBUG
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
492 DebPrint (("Wait signaled with process pid %d\n", cp->pid));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
493 #endif
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
494
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 if (status)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
497 *status = retval;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
498 }
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
499 else if (synch_process_alive)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
500 {
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
501 synch_process_alive = 0;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
502
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
503 /* Report the status of the synchronous process. */
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
504 if (WIFEXITED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
505 synch_process_retcode = WRETCODE (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
506 else if (WIFSIGNALED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
507 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
508 int code = WTERMSIG (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
509 char *signame = 0;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
510
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
511 if (code < NSIG)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
512 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
513 /* Suppress warning if the table has const char *. */
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
514 signame = (char *) sys_siglist[code];
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
515 }
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
516 if (signame == 0)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
517 signame = "unknown";
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
518
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
519 synch_process_death = signame;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
520 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
521
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
522 reap_subprocess (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
525 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
528 int
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
529 win32_is_dos_binary (char * filename)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
530 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
531 IMAGE_DOS_HEADER dos_header;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
532 DWORD signature;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
533 int fd;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
534 int is_dos_binary = FALSE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
535
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
536 fd = open (filename, O_RDONLY | O_BINARY, 0);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
537 if (fd >= 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
538 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
539 char * p = strrchr (filename, '.');
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
540
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
541 /* We can only identify DOS .com programs from the extension. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
542 if (p && stricmp (p, ".com") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
543 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
544 else if (p && stricmp (p, ".bat") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
545 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
546 /* A DOS shell script - it appears that CreateProcess is happy
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
547 to accept this (somewhat surprisingly); presumably it looks
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
548 at COMSPEC to determine what executable to actually invoke.
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
549 Therefore, we have to do the same here as well. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
550 p = getenv ("COMSPEC");
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
551 if (p)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
552 is_dos_binary = win32_is_dos_binary (p);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
553 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
554 else
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
555 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
556 /* Look for DOS .exe signature - if found, we must also check
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
557 that it isn't really a 16- or 32-bit Windows exe, since
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
558 both formats start with a DOS program stub. Note that
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
559 16-bit Windows executables use the OS/2 1.x format. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
560 if (read (fd, &dos_header, sizeof (dos_header)) == sizeof (dos_header)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
561 && dos_header.e_magic == IMAGE_DOS_SIGNATURE
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
562 && lseek (fd, dos_header.e_lfanew, SEEK_SET) != -1)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
563 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
564 if (read (fd, &signature, sizeof (signature)) != sizeof (signature)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
565 || (signature != IMAGE_NT_SIGNATURE &&
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
566 LOWORD (signature) != IMAGE_OS2_SIGNATURE))
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
567 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
568 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
569 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
570 close (fd);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
571 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
572
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
573 return is_dos_binary;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
574 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
575
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 /* We pass our process ID to our children by setting up an environment
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 variable in their environment. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 char ppid_env_var_buffer[64];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 /* When a new child process is created we need to register it in our list,
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 so intercept spawn requests. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
583 sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 {
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
585 Lisp_Object program, full;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 char *cmdline, *env, *parg, **targ;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 int arglen;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
588 int pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
589 child_process *cp;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
590 int is_dos_binary;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
591
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
592 /* We don't care about the other modes */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
593 if (mode != _P_NOWAIT)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
594 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
595 errno = EINVAL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
596 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
597 }
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
598
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
599 /* Handle executable names without an executable suffix. */
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
600 program = make_string (cmdname, strlen (cmdname));
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
601 if (NILP (Ffile_executable_p (program)))
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
602 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
603 struct gcpro gcpro1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
604
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
605 full = Qnil;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
606 GCPRO1 (program);
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
607 openp (Vexec_path, program, EXEC_SUFFIXES, &full, 1);
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
608 UNGCPRO;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
609 if (NILP (full))
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
610 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
611 errno = EINVAL;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
612 return -1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
613 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
614 cmdname = XSTRING (full)->data;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
615 argv[0] = cmdname;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
616 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
617
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
618 /* make sure cmdname is in DOS format */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
619 strcpy (cmdname = alloca (strlen (cmdname) + 1), argv[0]);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
620 unixtodos_filename (cmdname);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
621 argv[0] = cmdname;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
622
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
623 /* Check if program is a DOS executable, and if so whether we are
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
624 allowed to start it. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
625 is_dos_binary = win32_is_dos_binary (cmdname);
15415
68887d34a610 (restrict_dos_process): Renamed from can_run_dos_process.
Richard M. Stallman <rms@gnu.org>
parents: 15356
diff changeset
626 if (is_dos_binary && restrict_dos_process && dos_process_running)
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
627 {
15415
68887d34a610 (restrict_dos_process): Renamed from can_run_dos_process.
Richard M. Stallman <rms@gnu.org>
parents: 15356
diff changeset
628 errno = EAGAIN;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
629 return -1;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
630 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 /* we have to do some conjuring here to put argv and envp into the
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 form CreateProcess wants... argv needs to be a space separated/null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 terminated list of parameters, and envp is a null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 separated/double-null terminated list of parameters.
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
636
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
637 Additionally, zero-length args and args containing whitespace need
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
638 to be wrapped in double quotes. Args containing embedded double
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
639 quotes (as opposed to enclosing quotes, which we leave alone) are
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
640 usually illegal (most Win32 programs do not implement escaping of
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
641 double quotes - sad but true, at least for programs compiled with
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
642 MSVC), but we will escape quotes anyway for those programs that can
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
643 handle it. The Win32 gcc library from Cygnus doubles quotes to
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
644 escape them, so we will use that convention.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 Since I have no idea how large argv and envp are likely to be
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 we figure out list lengths on the fly and allocate them. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 /* do argv... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 arglen = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
654 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
655 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
656
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
657 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
658 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
659 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
660 if (*p++ == '"')
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
661 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
662 /* allow for embedded quotes to be doubled - we won't
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
663 actually double quotes that aren't embedded though */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
664 arglen++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
665 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
666 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
667 else if (*p == ' ' || *p == '\t')
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
668 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
669 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
670 arglen += 2;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
673 cmdline = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 parg = cmdline;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
678 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
679 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
680
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
681 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
682 add_quotes = 1;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
683
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
684 if (!NILP (Vwin32_quote_process_args))
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
685 {
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
686 /* This is conditional because it sometimes causes more
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
687 problems than it solves, since argv arrays are not always
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
688 carefully constructed. M-x grep, for instance, passes the
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
689 whole command line as one argument, so it becomes
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
690 impossible to pass a regexp which contains spaces. */
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
691 for ( ; *p; p++)
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
692 if (*p == ' ' || *p == '\t' || *p == '"')
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
693 add_quotes = 1;
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
694 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
695 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
696 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
697 char * first;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
698 char * last;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
699
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
700 p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
701 first = p;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
702 last = p + strlen (p) - 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
703 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
704 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
705 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
706 if (*p == '"' && p > first && p < last)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
707 *parg++ = '"'; /* double up embedded quotes only */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
708 *parg++ = *p++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
709 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
710 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
711 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
712 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
713 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
714 strcpy (parg, *targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
715 parg += strlen (*targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
716 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 *parg++ = ' ';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
718 targ++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 *--parg = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 /* and envp... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 arglen = 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 GetCurrentProcessId ());
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 arglen += strlen (ppid_env_var_buffer) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
733 env = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 parg = env;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 strcpy (parg, *targ);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 parg += strlen (*targ++);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 *parg++ = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 strcpy (parg, ppid_env_var_buffer);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 parg += strlen (ppid_env_var_buffer);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 *parg++ = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 *parg = '\0';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
746
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
747 cp = new_child ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
748 if (cp == NULL)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
750 errno = EAGAIN;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
751 return -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
754 /* Now create the process. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
755 if (!create_child (cmdname, cmdline, env, &pid, cp))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
756 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
757 delete_child (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
758 errno = ENOEXEC;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
759 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
760 }
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
761
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
762 if (is_dos_binary)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
763 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
764 cp->is_dos_process = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
765 dos_process_running = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
766 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
768 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 /* Emulate the select call
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 Wait for available input on any of the given rfds, or timeout if
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 a timeout is given and no input is detected
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 wfds and efds are not supported and must be NULL. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 /* From ntterm.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 extern HANDLE keyboard_handle;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 /* From process.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 extern int proc_buffered_char[];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 int
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
782 sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
783 EMACS_TIME *timeout)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 SELECT_TYPE orfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 DWORD timeout_ms;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 int i, nh, nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 DWORD active;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
789 child_process *cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
790 HANDLE wait_hnd[MAXDESC];
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
791 int fdindex[MAXDESC]; /* mapping from wait handles back to descriptors */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 /* If the descriptor sets are NULL but timeout isn't, then just Sleep. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
796 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 /* Otherwise, we only handle rfds, so fail otherwise. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 if (rfds == NULL || wfds != NULL || efds != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 orfds = *rfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 FD_ZERO (rfds);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 nr = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 /* Build a list of handles to wait on. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 for (i = 0; i < nfds; i++)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 if (FD_ISSET (i, &orfds))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 if (i == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
818 if (keyboard_handle)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
819 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
820 /* Handle stdin specially */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
821 wait_hnd[nh] = keyboard_handle;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
822 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
823 nh++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
824 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 /* Check for any emacs-generated input in the queue since
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 it won't be detected in the wait */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 if (detect_input_pending ())
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 FD_SET (i, rfds);
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
831 return 1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
836 /* Child process and socket input */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
837 cp = fd_info[i].cp;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 if (cp)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
840 int current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
841
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
842 if (current_status == STATUS_READ_ACKNOWLEDGED)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
843 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
844 /* Tell reader thread which file handle to use. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
845 cp->fd = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
846 /* Wake up the reader thread for this process */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
847 cp->status = STATUS_READ_READY;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
848 if (!SetEvent (cp->char_consumed))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
849 DebPrint (("nt_select.SetEvent failed with "
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
850 "%lu for fd %ld\n", GetLastError (), i));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
851 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
852
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
853 #ifdef CHECK_INTERLOCK
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
854 /* slightly crude cross-checking of interlock between threads */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
855
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
856 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
857 if (WaitForSingleObject (cp->char_avail, 0) == WAIT_OBJECT_0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
858 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
859 /* char_avail has been signalled, so status (which may
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
860 have changed) should indicate read has completed
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
861 but has not been acknowledged. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
862 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
863 if (current_status != STATUS_READ_SUCCEEDED &&
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
864 current_status != STATUS_READ_FAILED)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
865 DebPrint (("char_avail set, but read not completed: status %d\n",
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
866 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
867 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
868 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
869 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
870 /* char_avail has not been signalled, so status should
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
871 indicate that read is in progress; small possibility
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
872 that read has completed but event wasn't yet signalled
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
873 when we tested it (because a context switch occurred
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
874 or if running on separate CPUs). */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
875 if (current_status != STATUS_READ_READY &&
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
876 current_status != STATUS_READ_IN_PROGRESS &&
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
877 current_status != STATUS_READ_SUCCEEDED &&
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
878 current_status != STATUS_READ_FAILED)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
879 DebPrint (("char_avail reset, but read status is bad: %d\n",
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
880 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
881 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
882 #endif
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
883 wait_hnd[nh] = cp->char_avail;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
884 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
885 if (!wait_hnd[nh]) abort ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
886 nh++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 #ifdef FULL_DEBUG
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 DebPrint (("select waiting on child %d fd %d\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 cp-child_procs, i));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
894 /* Unable to find something to wait on for this fd, skip */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
895 DebPrint (("sys_select: fd %ld is invalid! ignoring\n", i));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
896 abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 /* Nothing to look for, so we didn't find anything */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 if (nh == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
904 if (timeout)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
905 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 /*
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 Wait for input
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 If a child process dies while this is waiting, its pipe will break
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 so the reader thread will signal an error condition, thus, the wait
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 will wake up
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 */
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
915 timeout_ms = timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFINITE;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
916
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, timeout_ms);
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
918
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 if (active == WAIT_FAILED)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 DebPrint (("select.WaitForMultipleObjects (%d, %lu) failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 nh, timeout_ms, GetLastError ()));
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
923 /* don't return EBADF - this causes wait_reading_process_input to
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
924 abort; WAIT_FAILED is returned when single-stepping under
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
925 Windows 95 after switching thread focus in debugger, and
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
926 possibly at other times. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
927 errno = EINTR;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 else if (active >= WAIT_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
944
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
945 /* Loop over all handles after active (now officially documented as
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
946 being the first signalled handle in the array). We do this to
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
947 ensure fairness, so that all channels with data available will be
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
948 processed - otherwise higher numbered channels could be starved. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
949 do
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
951 if (fdindex[active] == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
952 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
953 /* Keyboard input available */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
954 FD_SET (0, rfds);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 nr++;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
956 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 else
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
958 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
959 /* must be a socket or pipe */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
960 int current_status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
961
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
962 cp = fd_info[ fdindex[active] ].cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
963
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
964 /* Read ahead should have completed, either succeeding or failing. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
965 FD_SET (fdindex[active], rfds);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
966 nr++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
967 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
968 if (current_status != STATUS_READ_SUCCEEDED)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
969 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
970 if (current_status != STATUS_READ_FAILED)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
971 DebPrint (("internal error: subprocess pipe signalled "
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
972 "at the wrong time (status %d)\n!", current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
973
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
974 /* The child_process entry for a socket or pipe will be
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
975 freed when the last descriptor using it is closed; for
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
976 pipes, we call the SIGCHLD handler. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
977 if (fd_info[ fdindex[active] ].flags & FILE_PIPE)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
978 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
979 /* The SIGCHLD handler will do a Wait so we know it won't
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
980 return until the process is dead
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
981 We force Wait to only wait for this process to avoid it
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
982 picking up other children that happen to be dead but that
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
983 we haven't noticed yet
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
984 SIG_DFL for SIGCHLD is ignore? */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
985 if (sig_handlers[SIGCHLD] != SIG_DFL &&
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
986 sig_handlers[SIGCHLD] != SIG_IGN)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
987 {
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 #ifdef FULL_DEBUG
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
989 DebPrint (("select calling SIGCHLD handler for pid %d\n",
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
990 cp->pid));
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 #endif
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
992 dead_child = cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
993 sig_handlers[SIGCHLD] (SIGCHLD);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
994 dead_child = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
995 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
996
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
997 /* Clean up the child process entry in the table */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
998 reap_subprocess (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
999 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1000 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1001 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1002
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1003 /* Test for input on remaining channels. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1004 while (++active < nh)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1005 if (WaitForSingleObject (wait_hnd[active], 0) == WAIT_OBJECT_0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1006 break;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1007 } while (active < nh);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1008
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 return nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1012 /* Substitute for certain kill () operations */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1014 sys_kill (int pid, int sig)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1017 HANDLE proc_hand;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1018 int need_to_free = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1019 int rc = 0;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 /* Only handle signals that will result in the process dying */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1027
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 cp = find_child_pid (pid);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 if (cp == NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1031 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1032 if (proc_hand == NULL)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1033 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1034 errno = EPERM;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1035 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1036 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1037 need_to_free = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1038 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1039 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1040 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1041 proc_hand = cp->procinfo.hProcess;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1042 pid = cp->procinfo.dwProcessId;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 if (sig == SIGINT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1047 /* Ctrl-Break is NT equivalent of SIGINT. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1050 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1053 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 /* Kill the process. On Win32 this doesn't kill child processes
15351
6deee3a18ba8 (sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents: 15325
diff changeset
1059 so it doesn't work very well for shells which is why it's not
6deee3a18ba8 (sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents: 15325
diff changeset
1060 used in every case. Also, don't try to terminate DOS processes
6deee3a18ba8 (sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents: 15325
diff changeset
1061 (on Win95), because this will hang Emacs. */
6deee3a18ba8 (sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents: 15325
diff changeset
1062 if (!(cp && cp->is_dos_process)
6deee3a18ba8 (sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents: 15325
diff changeset
1063 && !TerminateProcess (proc_hand, 0xff))
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1065 DebPrint (("sys_kill.TerminateProcess returned %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1068 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1071
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1072 if (need_to_free)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1073 CloseHandle (proc_hand);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1074
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1075 return rc;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1078 extern int report_file_error (char *, Lisp_Object);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1079
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1080 /* The following two routines are used to manipulate stdin, stdout, and
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1081 stderr of our child processes.
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1082
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1083 Assuming that in, out, and err are *not* inheritable, we make them
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1084 stdin, stdout, and stderr of the child as follows:
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1085
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1086 - Save the parent's current standard handles.
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1087 - Set the std handles to inheritable duplicates of the ones being passed in.
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1088 (Note that _get_osfhandle() is an io.h procedure that retrieves the
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1089 NT file handle for a crt file descriptor.)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1090 - Spawn the child, which inherits in, out, and err as stdin,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1091 stdout, and stderr. (see Spawnve)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1092 - Close the std handles passed to the child.
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1093 - Reset the parent's standard handles to the saved handles.
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1094 (see reset_standard_handles)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1095 We assume that the caller closes in, out, and err after calling us. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1096
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1097 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1098 prepare_standard_handles (int in, int out, int err, HANDLE handles[3])
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1100 HANDLE parent;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1101 HANDLE newstdin, newstdout, newstderr;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1102
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1103 parent = GetCurrentProcess ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1104
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1105 handles[0] = GetStdHandle (STD_INPUT_HANDLE);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1106 handles[1] = GetStdHandle (STD_OUTPUT_HANDLE);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1107 handles[2] = GetStdHandle (STD_ERROR_HANDLE);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1108
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1109 /* make inheritable copies of the new handles */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1110 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1111 (HANDLE) _get_osfhandle (in),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1112 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1113 &newstdin,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1114 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1115 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1116 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1117 report_file_error ("Duplicating input handle for child", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1119 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1120 (HANDLE) _get_osfhandle (out),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1121 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1122 &newstdout,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1123 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1124 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1125 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1126 report_file_error ("Duplicating output handle for child", Qnil);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1127
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1128 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1129 (HANDLE) _get_osfhandle (err),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1130 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1131 &newstderr,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1132 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1133 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1134 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1135 report_file_error ("Duplicating error handle for child", Qnil);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1136
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1137 /* and store them as our std handles */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1138 if (!SetStdHandle (STD_INPUT_HANDLE, newstdin))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1139 report_file_error ("Changing stdin handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1141 if (!SetStdHandle (STD_OUTPUT_HANDLE, newstdout))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1142 report_file_error ("Changing stdout handle", Qnil);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1143
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1144 if (!SetStdHandle (STD_ERROR_HANDLE, newstderr))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1145 report_file_error ("Changing stderr handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1147
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1148 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1149 reset_standard_handles (int in, int out, int err, HANDLE handles[3])
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1150 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1151 /* close the duplicated handles passed to the child */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1152 CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1153 CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1154 CloseHandle (GetStdHandle (STD_ERROR_HANDLE));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1155
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1156 /* now restore parent's saved std handles */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1157 SetStdHandle (STD_INPUT_HANDLE, handles[0]);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1158 SetStdHandle (STD_OUTPUT_HANDLE, handles[1]);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1159 SetStdHandle (STD_ERROR_HANDLE, handles[2]);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1160 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1161
15356
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1162 #ifdef HAVE_SOCKETS
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1163
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1164 /* To avoid problems with winsock implementations that work over dial-up
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1165 connections causing or requiring a connection to exist while Emacs is
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1166 running, Emacs no longer automatically loads winsock on startup if it
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1167 is present. Instead, it will be loaded when open-network-stream is
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1168 first called.
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1169
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1170 To allow full control over when winsock is loaded, we provide these
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1171 two functions to dynamically load and unload winsock. This allows
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1172 dial-up users to only be connected when they actually need to use
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1173 socket services. */
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1174
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1175 /* From nt.c */
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1176 extern HANDLE winsock_lib;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1177 extern BOOL term_winsock (void);
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1178 extern BOOL init_winsock (int load_now);
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1179
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1180 extern Lisp_Object Vsystem_name;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1181
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1182 DEFUN ("win32-has-winsock", Fwin32_has_winsock, Swin32_has_winsock, 0, 1, 0,
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1183 "Test for presence of the Windows socket library `winsock'.\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1184 Returns non-nil if winsock support is present, nil otherwise.\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1185 \n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1186 If the optional argument LOAD-NOW is non-nil, the winsock library is\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1187 also loaded immediately if not already loaded. If winsock is loaded,\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1188 the winsock local hostname is returned (since this may be different from\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1189 the value of `system-name' and should supplant it), otherwise t is\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1190 returned to indicate winsock support is present.")
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1191 (load_now)
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1192 Lisp_Object load_now;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1193 {
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1194 int have_winsock;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1195
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1196 have_winsock = init_winsock (!NILP (load_now));
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1197 if (have_winsock)
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1198 {
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1199 if (winsock_lib != NULL)
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1200 {
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1201 /* Return new value for system-name. The best way to do this
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1202 is to call init_system_name, saving and restoring the
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1203 original value to avoid side-effects. */
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1204 Lisp_Object orig_hostname = Vsystem_name;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1205 Lisp_Object hostname;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1206
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1207 init_system_name ();
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1208 hostname = Vsystem_name;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1209 Vsystem_name = orig_hostname;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1210 return hostname;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1211 }
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1212 return Qt;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1213 }
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1214 return Qnil;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1215 }
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1216
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1217 DEFUN ("win32-unload-winsock", Fwin32_unload_winsock, Swin32_unload_winsock,
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1218 0, 0, 0,
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1219 "Unload the Windows socket library `winsock' if loaded.\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1220 This is provided to allow dial-up socket connections to be disconnected\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1221 when no longer needed. Returns nil without unloading winsock if any\n\
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1222 socket connections still exist.")
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1223 ()
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1224 {
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1225 return term_winsock () ? Qt : Qnil;
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1226 }
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1227
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1228 #endif /* HAVE_SOCKETS */
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1229
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1230
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1231 syms_of_ntproc ()
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1232 {
15356
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1233 #ifdef HAVE_SOCKETS
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1234 defsubr (&Swin32_has_winsock);
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1235 defsubr (&Swin32_unload_winsock);
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1236 #endif
1a917c5d944c (Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents: 15351
diff changeset
1237
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1238 DEFVAR_LISP ("win32-quote-process-args", &Vwin32_quote_process_args,
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1239 "Non-nil enables quoting of process arguments to ensure correct parsing.\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1240 Because Windows does not directly pass argv arrays to child processes,\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1241 programs have to reconstruct the argv array by parsing the command\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1242 line string. For an argument to contain a space, it must be enclosed\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1243 in double quotes or it will be parsed as multiple arguments.\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1244 \n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1245 However, the argument list to call-process is not always correctly\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1246 constructed (or arguments have already been quoted), so enabling this\n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1247 option may cause unexpected behavior.");
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1248 Vwin32_quote_process_args = Qnil;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1249
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1250 DEFVAR_INT ("win32-pipe-read-delay", &Vwin32_pipe_read_delay,
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1251 "Forced delay before reading subprocess output.\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1252 This is done to improve the buffering of subprocess output, by\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1253 avoiding the inefficiency of frequently reading small amounts of data.\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1254 \n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1255 If positive, the value is the number of milliseconds to sleep before\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1256 reading the subprocess output. If negative, the magnitude is the number\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1257 of time slices to wait (effectively boosting the priority of the child\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1258 process temporarily). A value of zero disables waiting entirely.");
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1259 Vwin32_pipe_read_delay = 50;
15325
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1260
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1261 DEFVAR_LISP ("win32-downcase-file-names", &Vwin32_downcase_file_names,
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1262 "Non-nil means convert all-upper case file names to lower case.\n\
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1263 This applies when performing completions and file name expansion.");
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1264 Vwin32_downcase_file_names = Qnil;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1265 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1266 /* end of ntproc.c */