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