annotate src/w32proc.c @ 15325:5c8e4ef3137c

(Vwin32_downcase_file_names): New variable. (syms_of_win32fns): DEF_VAR it.
author Richard M. Stallman <rms@gnu.org>
date Mon, 03 Jun 1996 21:17:31 +0000
parents 874a66251747
children 6deee3a18ba8
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. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
66 BOOL can_run_dos_process;
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
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
387 start a new one. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
388 if (cp->is_dos_process)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
389 dos_process_running = FALSE;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
391
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
392 /* 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
393 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
394 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
395 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
396 if (cp->fd == -1)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
397 delete_child (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 }
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 /* Wait for any of our existing child processes to die
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 When it does, close its handle
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 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
403
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
405 sys_wait (int *status)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 DWORD active, retval;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 int nh;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
409 int pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 child_process *cp, *cps[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 HANDLE wait_hnd[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 if (dead_child != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 /* 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
417 wait_hnd[nh] = dead_child->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 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
419 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 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
425 /* 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
426 if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
428 wait_hnd[nh] = cp->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 cps[nh] = cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
430 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 }
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 if (nh == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 /* Nothing to wait on, so fail */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 errno = ECHILD;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 }
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 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, INFINITE);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 if (active == WAIT_FAILED)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 errno = EBADF;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 else if (active >= WAIT_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 }
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 if (!GetExitCodeProcess (wait_hnd[active], &retval))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 DebPrint (("Wait.GetExitCodeProcess failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 GetLastError ()));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 retval = 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 if (retval == STILL_ACTIVE)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 DebPrint (("Wait.WaitForMultipleObjects returned an active process\n"));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 }
12325
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
478
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
479 /* 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
480 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
481 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
482
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
483 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
484 retval = SIGINT;
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
485 else
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
486 retval <<= 8;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
487
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 cp = cps[active];
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
489 pid = cp->pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
490 #ifdef FULL_DEBUG
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
491 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
492 #endif
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
493
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 if (status)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
496 *status = retval;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
497 }
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
498 else if (synch_process_alive)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
499 {
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
500 synch_process_alive = 0;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
501
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
502 /* 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
503 if (WIFEXITED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
504 synch_process_retcode = WRETCODE (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
505 else if (WIFSIGNALED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
506 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
507 int code = WTERMSIG (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
508 char *signame = 0;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
509
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
510 if (code < NSIG)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
511 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
512 /* 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
513 signame = (char *) sys_siglist[code];
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
514 }
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
515 if (signame == 0)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
516 signame = "unknown";
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
517
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
518 synch_process_death = signame;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
519 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
520
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
521 reap_subprocess (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
524 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
527 int
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
528 win32_is_dos_binary (char * filename)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
529 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
530 IMAGE_DOS_HEADER dos_header;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
531 DWORD signature;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
532 int fd;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
533 int is_dos_binary = FALSE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
534
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
535 fd = open (filename, O_RDONLY | O_BINARY, 0);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
536 if (fd >= 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
537 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
538 char * p = strrchr (filename, '.');
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
539
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
540 /* 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
541 if (p && stricmp (p, ".com") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
542 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
543 else if (p && stricmp (p, ".bat") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
544 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
545 /* 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
546 to accept this (somewhat surprisingly); presumably it looks
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
547 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
548 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
549 p = getenv ("COMSPEC");
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
550 if (p)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
551 is_dos_binary = win32_is_dos_binary (p);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
552 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
553 else
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
554 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
555 /* 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
556 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
557 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
558 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
559 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
560 && dos_header.e_magic == IMAGE_DOS_SIGNATURE
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
561 && 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
562 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
563 if (read (fd, &signature, sizeof (signature)) != sizeof (signature)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
564 || (signature != IMAGE_NT_SIGNATURE &&
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
565 LOWORD (signature) != IMAGE_OS2_SIGNATURE))
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
566 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
567 }
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 close (fd);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
570 }
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 return is_dos_binary;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
573 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
574
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 /* 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
576 variable in their environment. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 char ppid_env_var_buffer[64];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 /* 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
580 so intercept spawn requests. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
582 sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 {
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
584 Lisp_Object program, full;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 char *cmdline, *env, *parg, **targ;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 int arglen;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
587 int pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
588 child_process *cp;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
589 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
590
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
591 /* 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
592 if (mode != _P_NOWAIT)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
593 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
594 errno = EINVAL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
595 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
596 }
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
597
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
598 /* 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
599 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
600 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
601 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
602 struct gcpro gcpro1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
603
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
604 full = Qnil;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
605 GCPRO1 (program);
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
606 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
607 UNGCPRO;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
608 if (NILP (full))
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
609 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
610 errno = EINVAL;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
611 return -1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
612 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
613 cmdname = XSTRING (full)->data;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
614 argv[0] = cmdname;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
615 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
616
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
617 /* 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
618 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
619 unixtodos_filename (cmdname);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
620 argv[0] = cmdname;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
621
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
622 /* 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
623 allowed to start it. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
624 is_dos_binary = win32_is_dos_binary (cmdname);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
625 if (is_dos_binary && (!can_run_dos_process || dos_process_running))
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
626 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
627 errno = (can_run_dos_process) ? EAGAIN : EINVAL;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
628 return -1;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
629 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 /* 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
632 form CreateProcess wants... argv needs to be a space separated/null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 terminated list of parameters, and envp is a null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 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
635
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
636 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
637 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
638 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
639 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
640 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
641 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
642 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
643 escape them, so we will use that convention.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 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
646 we figure out list lengths on the fly and allocate them. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 /* do argv... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 arglen = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
653 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
654 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
655
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
656 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
657 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
658 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
659 if (*p++ == '"')
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
660 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
661 /* 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
662 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
663 arglen++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
664 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
665 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
666 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
667 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
668 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
669 arglen += 2;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
672 cmdline = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 parg = cmdline;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
677 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
678 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
679
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
680 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
681 add_quotes = 1;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
682
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
683 if (!NILP (Vwin32_quote_process_args))
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
684 {
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
685 /* 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
686 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
687 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
688 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
689 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
690 for ( ; *p; p++)
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
691 if (*p == ' ' || *p == '\t' || *p == '"')
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
692 add_quotes = 1;
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
693 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
694 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
695 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
696 char * first;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
697 char * last;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
698
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
699 p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
700 first = p;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
701 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
702 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
703 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
704 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
705 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
706 *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
707 *parg++ = *p++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
708 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
709 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
710 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
711 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
712 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
713 strcpy (parg, *targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
714 parg += strlen (*targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
715 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 *parg++ = ' ';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
717 targ++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 *--parg = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 /* and envp... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 arglen = 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 GetCurrentProcessId ());
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 arglen += strlen (ppid_env_var_buffer) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
732 env = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 parg = env;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 strcpy (parg, *targ);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 parg += strlen (*targ++);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 *parg++ = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 strcpy (parg, ppid_env_var_buffer);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 parg += strlen (ppid_env_var_buffer);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 *parg++ = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 *parg = '\0';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
745
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
746 cp = new_child ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
747 if (cp == NULL)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
749 errno = EAGAIN;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
750 return -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
753 /* Now create the process. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
754 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
755 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
756 delete_child (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
757 errno = ENOEXEC;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
758 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
759 }
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
760
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
761 if (is_dos_binary)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
762 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
763 cp->is_dos_process = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
764 dos_process_running = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
765 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
767 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 }
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 /* Emulate the select call
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 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
772 a timeout is given and no input is detected
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 wfds and efds are not supported and must be NULL. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 /* From ntterm.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 extern HANDLE keyboard_handle;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 /* From process.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 extern int proc_buffered_char[];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 int
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
781 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
782 EMACS_TIME *timeout)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 SELECT_TYPE orfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 DWORD timeout_ms;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 int i, nh, nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 DWORD active;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
788 child_process *cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
789 HANDLE wait_hnd[MAXDESC];
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
790 int fdindex[MAXDESC]; /* mapping from wait handles back to descriptors */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 /* 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
793 if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
795 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 }
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 /* Otherwise, we only handle rfds, so fail otherwise. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 if (rfds == NULL || wfds != NULL || efds != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 }
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 orfds = *rfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 FD_ZERO (rfds);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 nr = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 /* Build a list of handles to wait on. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 for (i = 0; i < nfds; i++)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 if (FD_ISSET (i, &orfds))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 if (i == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
817 if (keyboard_handle)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
818 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
819 /* Handle stdin specially */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
820 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
821 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
822 nh++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
823 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 /* Check for any emacs-generated input in the queue since
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 it won't be detected in the wait */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 if (detect_input_pending ())
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 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
830 return 1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 }
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 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
835 /* 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
836 cp = fd_info[i].cp;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 if (cp)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
839 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
840
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
841 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
842 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
843 /* 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
844 cp->fd = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
845 /* 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
846 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
847 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
848 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
849 "%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
850 }
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 #ifdef CHECK_INTERLOCK
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
853 /* 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
854
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
855 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
856 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
857 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
858 /* 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
859 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
860 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
861 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
862 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
863 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
864 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
865 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
866 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
867 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
868 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
869 /* 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
870 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
871 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
872 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
873 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
874 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
875 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
876 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
877 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
878 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
879 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
880 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
881 #endif
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
882 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
883 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
884 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
885 nh++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 #ifdef FULL_DEBUG
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 DebPrint (("select waiting on child %d fd %d\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 cp-child_procs, i));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
893 /* 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
894 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
895 abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 }
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 /* Nothing to look for, so we didn't find anything */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 if (nh == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
903 if (timeout)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
904 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 }
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 Wait for input
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 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
911 so the reader thread will signal an error condition, thus, the wait
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 will wake up
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 */
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
914 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
915
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 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
917
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 if (active == WAIT_FAILED)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 DebPrint (("select.WaitForMultipleObjects (%d, %lu) failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 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
922 /* 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
923 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
924 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
925 possibly at other times. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
926 errno = EINTR;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 else if (active >= WAIT_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
943
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
944 /* 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
945 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
946 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
947 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
948 do
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
950 if (fdindex[active] == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
951 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
952 /* Keyboard input available */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
953 FD_SET (0, rfds);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 nr++;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
955 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 else
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
957 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
958 /* 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
959 int current_status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
960
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
961 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
962
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
963 /* 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
964 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
965 nr++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
966 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
967 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
968 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
969 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
970 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
971 "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
972
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
973 /* 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
974 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
975 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
976 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
977 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
978 /* 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
979 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
980 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
981 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
982 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
983 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
984 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
985 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
986 {
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 #ifdef FULL_DEBUG
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
988 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
989 cp->pid));
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 #endif
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
991 dead_child = cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
992 sig_handlers[SIGCHLD] (SIGCHLD);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
993 dead_child = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
994 }
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 /* 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
997 reap_subprocess (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
998 }
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 /* 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
1003 while (++active < nh)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1004 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
1005 break;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1006 } while (active < nh);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1007
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 return nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1011 /* Substitute for certain kill () operations */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1013 sys_kill (int pid, int sig)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1016 HANDLE proc_hand;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1017 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
1018 int rc = 0;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 /* Only handle signals that will result in the process dying */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1026
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 cp = find_child_pid (pid);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 if (cp == NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1030 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
1031 if (proc_hand == NULL)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1032 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1033 errno = EPERM;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1034 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1035 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1036 need_to_free = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1037 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1038 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1039 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1040 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
1041 pid = cp->procinfo.dwProcessId;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 }
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 if (sig == SIGINT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1046 /* Ctrl-Break is NT equivalent of SIGINT. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1049 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1052 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 }
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 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 /* Kill the process. On Win32 this doesn't kill child processes
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 so it doesn't work very well for shells which is why it's
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 not used in every case. */
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1060 if (!TerminateProcess (proc_hand, 0xff))
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1062 DebPrint (("sys_kill.TerminateProcess returned %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1065 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1068
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1069 if (need_to_free)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1070 CloseHandle (proc_hand);
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 return rc;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1075 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
1076
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1077 /* 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
1078 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
1079
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1080 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
1081 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
1082
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1083 - 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
1084 - 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
1085 (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
1086 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
1087 - 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
1088 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
1089 - 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
1090 - 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
1091 (see reset_standard_handles)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1092 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
1093
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1094 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1095 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
1096 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1097 HANDLE parent;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1098 HANDLE newstdin, newstdout, newstderr;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1099
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1100 parent = GetCurrentProcess ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1101
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1102 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
1103 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
1104 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
1105
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1106 /* 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
1107 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1108 (HANDLE) _get_osfhandle (in),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1109 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1110 &newstdin,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1111 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1112 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1113 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1114 report_file_error ("Duplicating input handle for child", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1116 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1117 (HANDLE) _get_osfhandle (out),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1118 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1119 &newstdout,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1120 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1121 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1122 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1123 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
1124
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1125 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1126 (HANDLE) _get_osfhandle (err),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1127 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1128 &newstderr,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1129 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1130 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1131 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1132 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
1133
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1134 /* 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
1135 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
1136 report_file_error ("Changing stdin handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1138 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
1139 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
1140
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1141 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
1142 report_file_error ("Changing stderr handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1144
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1145 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1146 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
1147 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1148 /* 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
1149 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
1150 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
1151 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
1152
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1153 /* 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
1154 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
1155 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
1156 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
1157 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1158
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1159
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1160 syms_of_ntproc ()
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1161 {
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1162 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
1163 "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
1164 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
1165 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
1166 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
1167 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
1168 \n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1169 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
1170 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
1171 option may cause unexpected behavior.");
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1172 Vwin32_quote_process_args = Qnil;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1173
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1174 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
1175 "Forced delay before reading subprocess output.\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1176 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
1177 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
1178 \n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1179 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
1180 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
1181 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
1182 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
1183 Vwin32_pipe_read_delay = 50;
15325
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1184
5c8e4ef3137c (Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15247
diff changeset
1185 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
1186 "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
1187 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
1188 Vwin32_downcase_file_names = Qnil;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1189 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1190 /* end of ntproc.c */