annotate src/w32proc.c @ 15305:29ba4949d3d5

(shell-command-on-region): In output buffer, display first page by setting point, not window-start (which can leave point in an unexpected place).
author Karl Heuer <kwzh@gnu.org>
date Thu, 30 May 1996 20:44:17 +0000
parents 874a66251747
children 5c8e4ef3137c
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
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
60 /* 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
61 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
62 BOOL can_run_dos_process;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
63 BOOL dos_process_running;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
64
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
65 #ifndef SYS_SIGLIST_DECLARED
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
66 extern char *sys_siglist[];
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
67 #endif
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
69 #ifdef EMACSDEBUG
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
70 void _DebPrint (const char *fmt, ...)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
72 char buf[1024];
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 va_list args;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 va_start (args, fmt);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 vsprintf (buf, fmt, args);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 va_end (args);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 OutputDebugString (buf);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
82 typedef void (_CALLBACK_ *signal_handler)(int);
9907
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 /* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 static signal_handler sig_handlers[NSIG];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 /* Fake signal implementation to record the SIGCHLD handler. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 signal_handler
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
89 sys_signal (int sig, signal_handler handler)
9907
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 signal_handler old;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 if (sig != SIGCHLD)
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 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 return SIG_ERR;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 old = sig_handlers[sig];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 sig_handlers[sig] = handler;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 return old;
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
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
103 /* 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
104 #define _P_NOWAIT 1
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
105
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
106 /* Child process management list. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
107 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
108 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
109 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
110
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
111 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
112
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 /* 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
114 child_process *
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 new_child (void)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
118 DWORD id;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 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
122 goto Initialise;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
123 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
124 return NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
125 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
126
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
127 Initialise:
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
128 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
129 cp->fd = -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
130 cp->pid = -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
131 cp->procinfo.hProcess = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
132 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
133
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
134 /* 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
135 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
136 if (cp->char_avail)
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 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
139 if (cp->char_consumed)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
140 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
141 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
142 if (cp->thrd)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
143 return cp;
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 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
146 delete_child (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
147 return NULL;
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 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
151 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
152 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
153 int i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
154
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
155 /* 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
156 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
157 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
158 abort ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
159
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
160 if (!CHILD_ACTIVE (cp))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
161 return;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
162
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
163 /* reap thread if necessary */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
164 if (cp->thrd)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
165 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
166 DWORD rc;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
167
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
168 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
169 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
170 /* 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
171 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
172 SetEvent (cp->char_consumed);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
173 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
174 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
175 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
176 "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
177 TerminateThread (cp->thrd, 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 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
180 CloseHandle (cp->thrd);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
181 cp->thrd = NULL;
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 if (cp->char_avail)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
184 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
185 CloseHandle (cp->char_avail);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
186 cp->char_avail = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
187 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
188 if (cp->char_consumed)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
189 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
190 CloseHandle (cp->char_consumed);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
191 cp->char_consumed = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
192 }
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 /* 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
195 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
196 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
197 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
198 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
199 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
200 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
201 break;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
202 }
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 if (i < 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
205 child_proc_count = 0;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 /* Find a child by pid. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 static child_process *
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 find_child_pid (DWORD pid)
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 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
213
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 if (CHILD_ACTIVE (cp) && pid == cp->pid)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 return cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 return NULL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
221 /* 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
222 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
223 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
224 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
225 DWORD WINAPI
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 reader_thread (void *arg)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 child_process *cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 /* Our identity */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 cp = (child_process *)arg;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 /* 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
234 if (cp == NULL ||
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
235 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
236 return 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
237
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 for (;;)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
240 int rc;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
241
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
242 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
243
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
244 /* 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
245 read-ahead has completed, whether successfully or not. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 if (!SetEvent (cp->char_avail))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 GetLastError (), cp->fd));
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
250 return 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
251 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
252
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
253 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
254 return 1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 /* 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
257 if (rc == STATUS_READ_FAILED)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 break;
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 /* Wait until our input is acknowledged before reading again */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 DebPrint (("reader_thread.WaitForSingleObject failed with "
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 "%lu for fd %ld\n", GetLastError (), cp->fd));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 break;
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 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 }
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 static BOOL
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 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
273 int * pPid, child_process *cp)
9907
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 STARTUPINFO start;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 SECURITY_ATTRIBUTES sec_attrs;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 SECURITY_DESCRIPTOR sec_desc;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
279 if (cp == NULL) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 memset (&start, 0, sizeof (start));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 start.cb = sizeof (start);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
13425
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
284 #ifdef HAVE_NTGUI
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
285 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
286 start.wShowWindow = SW_HIDE;
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
287
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
288 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
289 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
290 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
291 #endif /* HAVE_NTGUI */
b6eacb7da9f6 [HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12325
diff changeset
292
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 /* Explicitly specify no security */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 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
295 goto EH_Fail;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 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
297 goto EH_Fail;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 sec_attrs.nLength = sizeof (sec_attrs);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 sec_attrs.lpSecurityDescriptor = &sec_desc;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 sec_attrs.bInheritHandle = FALSE;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 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
303 CREATE_NEW_PROCESS_GROUP,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
304 env, NULL,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
305 &start, &cp->procinfo))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
306 goto EH_Fail;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
307
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
308 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
309
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
310 /* 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
311 if (cp->pid < 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
312 cp->pid = -cp->pid;
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 /* 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
315 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
316
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 *pPid = cp->pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 return TRUE;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 EH_Fail:
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
323 DebPrint (("create_child.CreateProcess failed: %ld\n", GetLastError()););
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 return FALSE;
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
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 /* 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
328 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
329 to register the handle with the process
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 This way the select emulator knows how to match file handles with
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 entries in child_procs. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 void
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 register_child (int pid, int fd)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 child_process *cp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 cp = find_child_pid (pid);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 if (cp == NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 DebPrint (("register_child unable to find pid %lu\n", pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 return;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 }
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 #ifdef FULL_DEBUG
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 DebPrint (("register_child registered fd %d with pid %lu\n", fd, pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 #endif
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 cp->fd = fd;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
349
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
350 /* 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
351 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
352 cp->status = STATUS_READ_ACKNOWLEDGED;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
354 /* 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
355 if (fd_info[fd].cp != NULL)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
357 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
358 abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
360
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
361 fd_info[fd].cp = cp;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 /* 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
365 signal failure to the select emulator.
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 The select emulator then calls this routine to clean up.
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 Since the thread signaled failure we can assume it is exiting. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 static void
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
369 reap_subprocess (child_process *cp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
371 if (cp->procinfo.hProcess)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
373 /* Reap the process */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
374 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
375 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
376 "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
377 CloseHandle (cp->procinfo.hProcess);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
378 cp->procinfo.hProcess = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
379 CloseHandle (cp->procinfo.hThread);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
380 cp->procinfo.hThread = NULL;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
381
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
382 /* 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
383 start a new one. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
384 if (cp->is_dos_process)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
385 dos_process_running = FALSE;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
387
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
388 /* 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
389 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
390 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
391 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
392 if (cp->fd == -1)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
393 delete_child (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 /* Wait for any of our existing child processes to die
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 When it does, close its handle
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 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
399
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
401 sys_wait (int *status)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 DWORD active, retval;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 int nh;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
405 int pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 child_process *cp, *cps[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 HANDLE wait_hnd[MAX_CHILDREN];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 if (dead_child != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 /* 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
413 wait_hnd[nh] = dead_child->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 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
415 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 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
421 /* 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
422 if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
424 wait_hnd[nh] = cp->procinfo.hProcess;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 cps[nh] = cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
426 if (!wait_hnd[nh]) abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 nh++;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 if (nh == 0)
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 /* Nothing to wait on, so fail */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 errno = ECHILD;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 return -1;
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
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, INFINITE);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 if (active == WAIT_FAILED)
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 errno = EBADF;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 return -1;
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 else if (active >= WAIT_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 if (!GetExitCodeProcess (wait_hnd[active], &retval))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 DebPrint (("Wait.GetExitCodeProcess failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 GetLastError ()));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 retval = 1;
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 if (retval == STILL_ACTIVE)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 /* Should never happen */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 DebPrint (("Wait.WaitForMultipleObjects returned an active process\n"));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 }
12325
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
474
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
475 /* 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
476 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
477 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
478
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
479 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
480 retval = SIGINT;
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
481 else
aa6fc4e97a28 (win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents: 12239
diff changeset
482 retval <<= 8;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
483
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 cp = cps[active];
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
485 pid = cp->pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
486 #ifdef FULL_DEBUG
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
487 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
488 #endif
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
489
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 if (status)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
492 *status = retval;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
493 }
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
494 else if (synch_process_alive)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
495 {
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
496 synch_process_alive = 0;
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
497
13931
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
498 /* 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
499 if (WIFEXITED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
500 synch_process_retcode = WRETCODE (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
501 else if (WIFSIGNALED (retval))
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
502 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
503 int code = WTERMSIG (retval);
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
504 char *signame = 0;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
505
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
506 if (code < NSIG)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
507 {
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
508 /* 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
509 signame = (char *) sys_siglist[code];
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
510 }
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
511 if (signame == 0)
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
512 signame = "unknown";
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
513
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
514 synch_process_death = signame;
c80fb27c183b (win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents: 13425
diff changeset
515 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
516
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
517 reap_subprocess (cp);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
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 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
523 int
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
524 win32_is_dos_binary (char * filename)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
525 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
526 IMAGE_DOS_HEADER dos_header;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
527 DWORD signature;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
528 int fd;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
529 int is_dos_binary = FALSE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
530
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
531 fd = open (filename, O_RDONLY | O_BINARY, 0);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
532 if (fd >= 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
533 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
534 char * p = strrchr (filename, '.');
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
535
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
536 /* 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
537 if (p && stricmp (p, ".com") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
538 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
539 else if (p && stricmp (p, ".bat") == 0)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
540 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
541 /* 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
542 to accept this (somewhat surprisingly); presumably it looks
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
543 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
544 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
545 p = getenv ("COMSPEC");
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
546 if (p)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
547 is_dos_binary = win32_is_dos_binary (p);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
548 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
549 else
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
550 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
551 /* 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
552 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
553 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
554 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
555 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
556 && dos_header.e_magic == IMAGE_DOS_SIGNATURE
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
557 && 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
558 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
559 if (read (fd, &signature, sizeof (signature)) != sizeof (signature)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
560 || (signature != IMAGE_NT_SIGNATURE &&
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
561 LOWORD (signature) != IMAGE_OS2_SIGNATURE))
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
562 is_dos_binary = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
563 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
564 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
565 close (fd);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
566 }
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 return is_dos_binary;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
569 }
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
570
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 /* 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
572 variable in their environment. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 char ppid_env_var_buffer[64];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 /* 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
576 so intercept spawn requests. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
578 sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 {
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
580 Lisp_Object program, full;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 char *cmdline, *env, *parg, **targ;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 int arglen;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
583 int pid;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
584 child_process *cp;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
585 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
586
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
587 /* 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
588 if (mode != _P_NOWAIT)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
589 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
590 errno = EINVAL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
591 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
592 }
12239
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
593
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
594 /* 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
595 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
596 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
597 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
598 struct gcpro gcpro1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
599
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
600 full = Qnil;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
601 GCPRO1 (program);
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
602 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
603 UNGCPRO;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
604 if (NILP (full))
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
605 {
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
606 errno = EINVAL;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
607 return -1;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
608 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
609 cmdname = XSTRING (full)->data;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
610 argv[0] = cmdname;
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
611 }
ff7738cdbd99 (win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents: 12183
diff changeset
612
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
613 /* 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
614 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
615 unixtodos_filename (cmdname);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
616 argv[0] = cmdname;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
617
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
618 /* 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
619 allowed to start it. */
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
620 is_dos_binary = win32_is_dos_binary (cmdname);
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
621 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
622 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
623 errno = (can_run_dos_process) ? EAGAIN : EINVAL;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
624 return -1;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
625 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 /* 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
628 form CreateProcess wants... argv needs to be a space separated/null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 terminated list of parameters, and envp is a null
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 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
631
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
632 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
633 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
634 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
635 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
636 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
637 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
638 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
639 escape them, so we will use that convention.
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 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
642 we figure out list lengths on the fly and allocate them. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 /* do argv... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 arglen = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
649 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
650 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
651
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
652 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
653 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
654 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
655 if (*p++ == '"')
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
656 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
657 /* 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
658 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
659 arglen++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
660 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
661 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
662 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
663 add_quotes = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
664 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
665 arglen += 2;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
668 cmdline = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 targ = argv;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 parg = cmdline;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
673 char * p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
674 int add_quotes = 0;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
675
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
676 if (*p == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
677 add_quotes = 1;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
678
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
679 if (!NILP (Vwin32_quote_process_args))
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
680 {
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
681 /* 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
682 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
683 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
684 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
685 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
686 for ( ; *p; p++)
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
687 if (*p == ' ' || *p == '\t' || *p == '"')
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
688 add_quotes = 1;
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
689 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
690 if (add_quotes)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
691 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
692 char * first;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
693 char * last;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
694
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
695 p = *targ;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
696 first = p;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
697 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
698 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
699 while (*p)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
700 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
701 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
702 *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
703 *parg++ = *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 *parg++ = '"';
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
706 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
707 else
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 strcpy (parg, *targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
710 parg += strlen (*targ);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
711 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 *parg++ = ' ';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
713 targ++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 *--parg = '\0';
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 /* and envp... */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 arglen = 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 arglen += strlen (*targ++) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 GetCurrentProcessId ());
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 arglen += strlen (ppid_env_var_buffer) + 1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
728 env = alloca (arglen);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 targ = envp;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 parg = env;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 while (*targ)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 strcpy (parg, *targ);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 parg += strlen (*targ++);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 *parg++ = '\0';
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, ppid_env_var_buffer);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 parg += strlen (ppid_env_var_buffer);
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 *parg = '\0';
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
741
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
742 cp = new_child ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
743 if (cp == NULL)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
745 errno = EAGAIN;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
746 return -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 }
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 /* Now create the process. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
750 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
751 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
752 delete_child (cp);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
753 errno = ENOEXEC;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
754 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
755 }
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
756
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
757 if (is_dos_binary)
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
758 {
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
759 cp->is_dos_process = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
760 dos_process_running = TRUE;
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
761 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
763 return pid;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 /* Emulate the select call
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 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
768 a timeout is given and no input is detected
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 wfds and efds are not supported and must be NULL. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 /* From ntterm.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 extern HANDLE keyboard_handle;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 /* From process.c */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 extern int proc_buffered_char[];
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 int
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
777 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
778 EMACS_TIME *timeout)
9907
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 SELECT_TYPE orfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 DWORD timeout_ms;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 int i, nh, nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 DWORD active;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
784 child_process *cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
785 HANDLE wait_hnd[MAXDESC];
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
786 int fdindex[MAXDESC]; /* mapping from wait handles back to descriptors */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 /* 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
789 if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
791 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 /* Otherwise, we only handle rfds, so fail otherwise. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 if (rfds == NULL || wfds != NULL || efds != NULL)
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 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 }
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 orfds = *rfds;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 FD_ZERO (rfds);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 nr = 0;
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 /* Build a list of handles to wait on. */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 nh = 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 for (i = 0; i < nfds; i++)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 if (FD_ISSET (i, &orfds))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 if (i == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
813 if (keyboard_handle)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
814 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
815 /* Handle stdin specially */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
816 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
817 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
818 nh++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
819 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 /* Check for any emacs-generated input in the queue since
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 it won't be detected in the wait */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 if (detect_input_pending ())
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 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
826 return 1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 }
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 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
831 /* 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
832 cp = fd_info[i].cp;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 if (cp)
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 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
836
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
837 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
838 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
839 /* 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
840 cp->fd = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
841 /* 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
842 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
843 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
844 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
845 "%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
846 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
847
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
848 #ifdef CHECK_INTERLOCK
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
849 /* 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
850
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
851 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
852 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
853 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
854 /* 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
855 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
856 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
857 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
858 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
859 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
860 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
861 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
862 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
863 else
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
864 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
865 /* 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
866 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
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 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
875 current_status));
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
876 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
877 #endif
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
878 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
879 fdindex[nh] = i;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
880 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
881 nh++;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 #ifdef FULL_DEBUG
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 DebPrint (("select waiting on child %d fd %d\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 cp-child_procs, i));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 #endif
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
889 /* 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
890 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
891 abort ();
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 /* Nothing to look for, so we didn't find anything */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 if (nh == 0)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 {
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
899 if (timeout)
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
900 Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 return 0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 /*
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 Wait for input
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 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
907 so the reader thread will signal an error condition, thus, the wait
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 will wake up
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 */
11388
96fa39ad9403 (win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents: 9907
diff changeset
910 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
911
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 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
913
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 if (active == WAIT_FAILED)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 DebPrint (("select.WaitForMultipleObjects (%d, %lu) failed with %lu\n",
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 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
918 /* 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
919 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
920 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
921 possibly at other times. */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
922 errno = EINTR;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 else if (active == WAIT_TIMEOUT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 return 0;
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_OBJECT_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 active -= WAIT_OBJECT_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 else if (active >= WAIT_ABANDONED_0 &&
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 active -= WAIT_ABANDONED_0;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
939
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
940 /* 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
941 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
942 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
943 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
944 do
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
946 if (fdindex[active] == 0)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
947 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
948 /* Keyboard input available */
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
949 FD_SET (0, rfds);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 nr++;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
951 }
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 else
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
953 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
954 /* 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
955 int current_status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
956
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
957 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
958
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
959 /* 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
960 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
961 nr++;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
962 current_status = cp->status;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
963 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
964 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
965 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
966 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
967 "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
968
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
969 /* 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
970 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
971 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
972 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
973 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
974 /* 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
975 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
976 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
977 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
978 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
979 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
980 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
981 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
982 {
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 #ifdef FULL_DEBUG
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
984 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
985 cp->pid));
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 #endif
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
987 dead_child = cp;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
988 sig_handlers[SIGCHLD] (SIGCHLD);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
989 dead_child = NULL;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
990 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
991
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
992 /* 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
993 reap_subprocess (cp);
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 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
997
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
998 /* 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
999 while (++active < nh)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1000 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
1001 break;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1002 } while (active < nh);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1003
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 return nr;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1007 /* Substitute for certain kill () operations */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 int
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1009 sys_kill (int pid, int sig)
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 child_process *cp;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1012 HANDLE proc_hand;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1013 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
1014 int rc = 0;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 /* Only handle signals that will result in the process dying */
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 errno = EINVAL;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 return -1;
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1022
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 cp = find_child_pid (pid);
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 if (cp == NULL)
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 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
1027 if (proc_hand == NULL)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1028 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1029 errno = EPERM;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1030 return -1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1031 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1032 need_to_free = 1;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1033 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1034 else
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 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
1037 pid = cp->procinfo.dwProcessId;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 if (sig == SIGINT)
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1042 /* Ctrl-Break is NT equivalent of SIGINT. */
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1045 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1048 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 else
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 {
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 /* Kill the process. On Win32 this doesn't kill child processes
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 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
1055 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
1056 if (!TerminateProcess (proc_hand, 0xff))
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1058 DebPrint (("sys_kill.TerminateProcess returned %d "
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 "for pid %lu\n", GetLastError (), pid));
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 errno = EINVAL;
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1061 rc = -1;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1064
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1065 if (need_to_free)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1066 CloseHandle (proc_hand);
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1067
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1068 return rc;
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 }
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1071 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
1072
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1073 /* 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
1074 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
1075
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1076 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
1077 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
1078
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1079 - 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
1080 - 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
1081 (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
1082 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
1083 - 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
1084 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
1085 - 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
1086 - 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
1087 (see reset_standard_handles)
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1088 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
1089
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1090 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1091 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
1092 {
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1093 HANDLE parent;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1094 HANDLE newstdin, newstdout, newstderr;
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1095
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1096 parent = GetCurrentProcess ();
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1097
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1098 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
1099 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
1100 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
1101
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1102 /* 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
1103 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1104 (HANDLE) _get_osfhandle (in),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1105 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1106 &newstdin,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1107 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1108 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1109 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1110 report_file_error ("Duplicating input handle for child", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1112 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1113 (HANDLE) _get_osfhandle (out),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1114 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1115 &newstdout,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1116 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1117 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1118 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1119 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
1120
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1121 if (!DuplicateHandle (parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1122 (HANDLE) _get_osfhandle (err),
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1123 parent,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1124 &newstderr,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1125 0,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1126 TRUE,
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1127 DUPLICATE_SAME_ACCESS))
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1128 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
1129
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1130 /* 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
1131 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
1132 report_file_error ("Changing stdin handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1134 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
1135 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
1136
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1137 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
1138 report_file_error ("Changing stderr handle", Qnil);
9907
2e5a14f7c44e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 }
15145
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 void
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1142 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
1143 {
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1144 /* 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
1145 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
1146 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
1147 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
1148
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1149 /* 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
1150 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
1151 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
1152 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
1153 }
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1154
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1155
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1156 syms_of_ntproc ()
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1157 {
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1158 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
1159 "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
1160 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
1161 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
1162 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
1163 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
1164 \n\
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1165 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
1166 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
1167 option may cause unexpected behavior.");
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1168 Vwin32_quote_process_args = Qnil;
15247
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1169
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1170 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
1171 "Forced delay before reading subprocess output.\n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1172 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
1173 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
1174 \n\
874a66251747 (Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents: 15201
diff changeset
1175 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
1176 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
1177 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
1178 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
1179 Vwin32_pipe_read_delay = 50;
15201
43551ec4b69d (Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 15145
diff changeset
1180 }
15145
86a1f426871e Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14186
diff changeset
1181 /* end of ntproc.c */