Mercurial > emacs
annotate src/w32proc.c @ 15265:658224992372
(win32-handle-scroll-bar-event): Restore
original window selection after scrolling.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 21 May 1996 14:40:56 +0000 |
parents | 874a66251747 |
children | 5c8e4ef3137c |
rev | line source |
---|---|
9907 | 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 | 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 | 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 | 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 | 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 | 20 |
21 Drew Bliss Oct 14, 1993 | |
22 Adapted from alarm.c by Tim Fleehart | |
23 */ | |
24 | |
25 #include <stdio.h> | |
26 #include <stdlib.h> | |
27 #include <errno.h> | |
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 | 30 #include <signal.h> |
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 | 40 #include <windows.h> |
41 | |
42 #include "lisp.h" | |
43 #include "nt.h" | |
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 | 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 | 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 | 73 va_list args; |
74 | |
75 va_start (args, fmt); | |
76 vsprintf (buf, fmt, args); | |
77 va_end (args); | |
78 OutputDebugString (buf); | |
79 } | |
80 #endif | |
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 | 83 |
84 /* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */ | |
85 static signal_handler sig_handlers[NSIG]; | |
86 | |
87 /* Fake signal implementation to record the SIGCHLD handler. */ | |
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 | 90 { |
91 signal_handler old; | |
92 | |
93 if (sig != SIGCHLD) | |
94 { | |
95 errno = EINVAL; | |
96 return SIG_ERR; | |
97 } | |
98 old = sig_handlers[sig]; | |
99 sig_handlers[sig] = handler; | |
100 return old; | |
101 } | |
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 | 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 | 115 new_child (void) |
116 { | |
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 | 119 |
120 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) | |
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 | 206 } |
207 | |
208 /* Find a child by pid. */ | |
209 static child_process * | |
210 find_child_pid (DWORD pid) | |
211 { | |
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 | 214 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) |
215 if (CHILD_ACTIVE (cp) && pid == cp->pid) | |
216 return cp; | |
217 return NULL; | |
218 } | |
219 | |
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 | 225 DWORD WINAPI |
226 reader_thread (void *arg) | |
227 { | |
228 child_process *cp; | |
229 | |
230 /* Our identity */ | |
231 cp = (child_process *)arg; | |
232 | |
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 | 238 for (;;) |
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 | 246 if (!SetEvent (cp->char_avail)) |
247 { | |
248 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n", | |
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 | 255 |
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 | 258 break; |
259 | |
260 /* Wait until our input is acknowledged before reading again */ | |
261 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) | |
262 { | |
263 DebPrint (("reader_thread.WaitForSingleObject failed with " | |
264 "%lu for fd %ld\n", GetLastError (), cp->fd)); | |
265 break; | |
266 } | |
267 } | |
268 return 0; | |
269 } | |
270 | |
271 static BOOL | |
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 | 274 { |
275 STARTUPINFO start; | |
276 SECURITY_ATTRIBUTES sec_attrs; | |
277 SECURITY_DESCRIPTOR sec_desc; | |
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 | 280 |
281 memset (&start, 0, sizeof (start)); | |
282 start.cb = sizeof (start); | |
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 | 293 /* Explicitly specify no security */ |
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 | 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 | 298 sec_attrs.nLength = sizeof (sec_attrs); |
299 sec_attrs.lpSecurityDescriptor = &sec_desc; | |
300 sec_attrs.bInheritHandle = FALSE; | |
301 | |
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 | 319 |
320 return TRUE; | |
321 | |
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 | 324 return FALSE; |
325 } | |
326 | |
327 /* create_child doesn't know what emacs' file handle will be for waiting | |
328 on output from the child, so we need to make this additional call | |
329 to register the handle with the process | |
330 This way the select emulator knows how to match file handles with | |
331 entries in child_procs. */ | |
332 void | |
333 register_child (int pid, int fd) | |
334 { | |
335 child_process *cp; | |
336 | |
337 cp = find_child_pid (pid); | |
338 if (cp == NULL) | |
339 { | |
340 DebPrint (("register_child unable to find pid %lu\n", pid)); | |
341 return; | |
342 } | |
343 | |
344 #ifdef FULL_DEBUG | |
345 DebPrint (("register_child registered fd %d with pid %lu\n", fd, pid)); | |
346 #endif | |
347 | |
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 | 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 | 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 | 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 | 362 } |
363 | |
364 /* When a process dies its pipe will break so the reader thread will | |
365 signal failure to the select emulator. | |
366 The select emulator then calls this routine to clean up. | |
367 Since the thread signaled failure we can assume it is exiting. */ | |
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 | 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 | 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 | 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 | 394 } |
395 | |
396 /* Wait for any of our existing child processes to die | |
397 When it does, close its handle | |
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 | 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 | 402 { |
403 DWORD active, retval; | |
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 | 406 child_process *cp, *cps[MAX_CHILDREN]; |
407 HANDLE wait_hnd[MAX_CHILDREN]; | |
408 | |
409 nh = 0; | |
410 if (dead_child != NULL) | |
411 { | |
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 | 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 | 416 nh++; |
417 } | |
418 else | |
419 { | |
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 | 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 | 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 | 427 nh++; |
428 } | |
429 } | |
430 | |
431 if (nh == 0) | |
432 { | |
433 /* Nothing to wait on, so fail */ | |
434 errno = ECHILD; | |
435 return -1; | |
436 } | |
437 | |
438 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, INFINITE); | |
439 if (active == WAIT_FAILED) | |
440 { | |
441 errno = EBADF; | |
442 return -1; | |
443 } | |
444 else if (active == WAIT_TIMEOUT) | |
445 { | |
446 /* Should never happen */ | |
447 errno = EINVAL; | |
448 return -1; | |
449 } | |
450 else if (active >= WAIT_OBJECT_0 && | |
451 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) | |
452 { | |
453 active -= WAIT_OBJECT_0; | |
454 } | |
455 else if (active >= WAIT_ABANDONED_0 && | |
456 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS) | |
457 { | |
458 active -= WAIT_ABANDONED_0; | |
459 } | |
460 | |
461 if (!GetExitCodeProcess (wait_hnd[active], &retval)) | |
462 { | |
463 DebPrint (("Wait.GetExitCodeProcess failed with %lu\n", | |
464 GetLastError ())); | |
465 retval = 1; | |
466 } | |
467 if (retval == STILL_ACTIVE) | |
468 { | |
469 /* Should never happen */ | |
470 DebPrint (("Wait.WaitForMultipleObjects returned an active process\n")); | |
471 errno = EINVAL; | |
472 return -1; | |
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 | 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 | 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 | 490 if (status) |
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 | 518 } |
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 | 521 } |
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 | 571 /* We pass our process ID to our children by setting up an environment |
572 variable in their environment. */ | |
573 char ppid_env_var_buffer[64]; | |
574 | |
575 /* When a new child process is created we need to register it in our list, | |
576 so intercept spawn requests. */ | |
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 | 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 | 581 char *cmdline, *env, *parg, **targ; |
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 | 626 |
627 /* we have to do some conjuring here to put argv and envp into the | |
628 form CreateProcess wants... argv needs to be a space separated/null | |
629 terminated list of parameters, and envp is a null | |
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 | 640 |
641 Since I have no idea how large argv and envp are likely to be | |
642 we figure out list lengths on the fly and allocate them. */ | |
643 | |
644 /* do argv... */ | |
645 arglen = 0; | |
646 targ = argv; | |
647 while (*targ) | |
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 | 666 arglen += strlen (*targ++) + 1; |
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 | 669 targ = argv; |
670 parg = cmdline; | |
671 while (*targ) | |
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 | 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 | 714 } |
715 *--parg = '\0'; | |
716 | |
717 /* and envp... */ | |
718 arglen = 1; | |
719 targ = envp; | |
720 while (*targ) | |
721 { | |
722 arglen += strlen (*targ++) + 1; | |
723 } | |
724 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d", | |
725 GetCurrentProcessId ()); | |
726 arglen += strlen (ppid_env_var_buffer) + 1; | |
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 | 729 targ = envp; |
730 parg = env; | |
731 while (*targ) | |
732 { | |
733 strcpy (parg, *targ); | |
734 parg += strlen (*targ++); | |
735 *parg++ = '\0'; | |
736 } | |
737 strcpy (parg, ppid_env_var_buffer); | |
738 parg += strlen (ppid_env_var_buffer); | |
739 *parg++ = '\0'; | |
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 | 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 | 747 } |
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 | 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 | 764 } |
765 | |
766 /* Emulate the select call | |
767 Wait for available input on any of the given rfds, or timeout if | |
768 a timeout is given and no input is detected | |
769 wfds and efds are not supported and must be NULL. */ | |
770 | |
771 /* From ntterm.c */ | |
772 extern HANDLE keyboard_handle; | |
773 /* From process.c */ | |
774 extern int proc_buffered_char[]; | |
775 | |
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 | 779 { |
780 SELECT_TYPE orfds; | |
781 DWORD timeout_ms; | |
782 int i, nh, nr; | |
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 | 787 |
788 /* If the descriptor sets are NULL but timeout isn't, then just Sleep. */ | |
789 if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL) | |
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 | 792 return 0; |
793 } | |
794 | |
795 /* Otherwise, we only handle rfds, so fail otherwise. */ | |
796 if (rfds == NULL || wfds != NULL || efds != NULL) | |
797 { | |
798 errno = EINVAL; | |
799 return -1; | |
800 } | |
801 | |
802 orfds = *rfds; | |
803 FD_ZERO (rfds); | |
804 nr = 0; | |
805 | |
806 /* Build a list of handles to wait on. */ | |
807 nh = 0; | |
808 for (i = 0; i < nfds; i++) | |
809 if (FD_ISSET (i, &orfds)) | |
810 { | |
811 if (i == 0) | |
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 | 820 |
821 /* Check for any emacs-generated input in the queue since | |
822 it won't be detected in the wait */ | |
823 if (detect_input_pending ()) | |
824 { | |
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 | 827 } |
828 } | |
829 else | |
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 | 833 if (cp) |
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 | 882 #ifdef FULL_DEBUG |
883 DebPrint (("select waiting on child %d fd %d\n", | |
884 cp-child_procs, i)); | |
885 #endif | |
886 } | |
887 else | |
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 | 892 } |
893 } | |
894 } | |
895 | |
896 /* Nothing to look for, so we didn't find anything */ | |
897 if (nh == 0) | |
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 | 901 return 0; |
902 } | |
903 | |
904 /* | |
905 Wait for input | |
906 If a child process dies while this is waiting, its pipe will break | |
907 so the reader thread will signal an error condition, thus, the wait | |
908 will wake up | |
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 | 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 | 914 if (active == WAIT_FAILED) |
915 { | |
916 DebPrint (("select.WaitForMultipleObjects (%d, %lu) failed with %lu\n", | |
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 | 923 return -1; |
924 } | |
925 else if (active == WAIT_TIMEOUT) | |
926 { | |
927 return 0; | |
928 } | |
929 else if (active >= WAIT_OBJECT_0 && | |
930 active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) | |
931 { | |
932 active -= WAIT_OBJECT_0; | |
933 } | |
934 else if (active >= WAIT_ABANDONED_0 && | |
935 active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS) | |
936 { | |
937 active -= WAIT_ABANDONED_0; | |
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 | 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 | 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 | 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 | 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 | 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 | 1004 return nr; |
1005 } | |
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 | 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 | 1010 { |
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 | 1015 |
1016 /* Only handle signals that will result in the process dying */ | |
1017 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP) | |
1018 { | |
1019 errno = EINVAL; | |
1020 return -1; | |
1021 } | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1022 |
9907 | 1023 cp = find_child_pid (pid); |
1024 if (cp == NULL) | |
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 | 1038 } |
1039 | |
1040 if (sig == SIGINT) | |
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 | 1043 if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid)) |
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 | 1046 "for pid %lu\n", GetLastError (), pid)); |
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 | 1049 } |
1050 } | |
1051 else | |
1052 { | |
1053 /* Kill the process. On Win32 this doesn't kill child processes | |
1054 so it doesn't work very well for shells which is why it's | |
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 | 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 | 1059 "for pid %lu\n", GetLastError (), pid)); |
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 | 1062 } |
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 | 1069 } |
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 | 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 | 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 | 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 | 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 */ |