comparison src/ntproc.c @ 308:33bdb3d4b97f r21-0b52

Import from CVS: tag r21-0b52
author cvs
date Mon, 13 Aug 2007 10:42:44 +0200
parents c9fe270a4101
children 7c94d56991e1
comparison
equal deleted inserted replaced
307:42d630fd9bd8 308:33bdb3d4b97f
130 130
131 Initialize: 131 Initialize:
132 xzero (*cp); 132 xzero (*cp);
133 cp->fd = -1; 133 cp->fd = -1;
134 cp->pid = -1; 134 cp->pid = -1;
135 if (cp->procinfo.hProcess)
136 CloseHandle(cp->procinfo.hProcess);
135 cp->procinfo.hProcess = NULL; 137 cp->procinfo.hProcess = NULL;
136 cp->status = STATUS_READ_ERROR; 138 cp->status = STATUS_READ_ERROR;
137 139
138 /* use manual reset event so that select() will function properly */ 140 /* use manual reset event so that select() will function properly */
139 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL); 141 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL);
232 child_process *cp; 234 child_process *cp;
233 235
234 /* Our identity */ 236 /* Our identity */
235 cp = (child_process *)arg; 237 cp = (child_process *)arg;
236 238
237 /* We have to wait for the go-ahead before we can start */ 239 /* <matts@tibco.com> - I think the test below is wrong - we don't
240 want to wait for someone to signal char_consumed, as we haven't
241 read anything for them to consume yet! */
242
243 /*
238 if (cp == NULL || 244 if (cp == NULL ||
239 WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) 245 WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
240 return 1; 246 */
247
248 if (cp == NULL)
249 {
250 return 1;
251 }
241 252
242 for (;;) 253 for (;;)
243 { 254 {
244 int rc; 255 int rc;
245 256
253 GetLastError (), cp->fd)); 264 GetLastError (), cp->fd));
254 return 1; 265 return 1;
255 } 266 }
256 267
257 if (rc == STATUS_READ_ERROR) 268 if (rc == STATUS_READ_ERROR)
258 return 1; 269 {
270 /* We are finished, so clean up handles and set to NULL so
271 that CHILD_ACTIVE will see what is going on */
272 if (cp->char_avail) {
273 CloseHandle (cp->char_avail);
274 cp->char_avail = NULL;
275 }
276 if (cp->thrd) {
277 CloseHandle (cp->thrd);
278 cp->thrd = NULL;
279 }
280 if (cp->char_consumed) {
281 CloseHandle(cp->char_consumed);
282 cp->char_consumed = NULL;
283 }
284 if (cp->procinfo.hProcess)
285 {
286 CloseHandle (cp->procinfo.hProcess);
287 cp->procinfo.hProcess=NULL;
288 }
289 return 1;
290 }
259 291
260 /* If the read died, the child has died so let the thread die */ 292 /* If the read died, the child has died so let the thread die */
261 if (rc == STATUS_READ_FAILED) 293 if (rc == STATUS_READ_FAILED)
262 break; 294 break;
263 295
267 DebPrint (("reader_thread.WaitForSingleObject failed with " 299 DebPrint (("reader_thread.WaitForSingleObject failed with "
268 "%lu for fd %ld\n", GetLastError (), cp->fd)); 300 "%lu for fd %ld\n", GetLastError (), cp->fd));
269 break; 301 break;
270 } 302 }
271 } 303 }
304 /* We are finished, so clean up handles and set to NULL so that
305 CHILD_ACTIVE will see what is going on */
306 if (cp->char_avail) {
307 CloseHandle (cp->char_avail);
308 cp->char_avail = NULL;
309 }
310 if (cp->thrd) {
311 CloseHandle (cp->thrd);
312 cp->thrd = NULL;
313 }
314 if (cp->char_consumed) {
315 CloseHandle(cp->char_consumed);
316 cp->char_consumed = NULL;
317 }
318 if (cp->procinfo.hProcess)
319 {
320 CloseHandle (cp->procinfo.hProcess);
321 cp->procinfo.hProcess=NULL;
322 }
323
272 return 0; 324 return 0;
273 } 325 }
274 326
275 /* To avoid Emacs changing directory, we just record here the directory 327 /* To avoid Emacs changing directory, we just record here the directory
276 the new process should start in. This is set just before calling 328 the new process should start in. This is set just before calling
322 env, dir, 374 env, dir,
323 &start, &cp->procinfo)) 375 &start, &cp->procinfo))
324 goto EH_Fail; 376 goto EH_Fail;
325 377
326 cp->pid = (int) cp->procinfo.dwProcessId; 378 cp->pid = (int) cp->procinfo.dwProcessId;
379
380 CloseHandle (cp->procinfo.hThread);
381 CloseHandle (cp->procinfo.hProcess);
382 cp->procinfo.hThread=NULL;
383 cp->procinfo.hProcess=NULL;
327 384
328 /* Hack for Windows 95, which assigns large (ie negative) pids */ 385 /* Hack for Windows 95, which assigns large (ie negative) pids */
329 if (cp->pid < 0) 386 if (cp->pid < 0)
330 cp->pid = -cp->pid; 387 cp->pid = -cp->pid;
331 388