Mercurial > hg > xemacs-beta
comparison src/sysdep.c @ 357:4711e16a8e49 r21-1-8
Import from CVS: tag r21-1-8
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:57:04 +0200 |
parents | 7c94d56991e1 |
children | 8e84bee8ddd0 |
comparison
equal
deleted
inserted
replaced
356:e85f639a32f3 | 357:4711e16a8e49 |
---|---|
231 #endif /* BSD */ | 231 #endif /* BSD */ |
232 | 232 |
233 #endif /* NO_SUBPROCESSES */ | 233 #endif /* NO_SUBPROCESSES */ |
234 | 234 |
235 | 235 |
236 void | 236 #ifdef WINDOWSNT |
237 wait_for_termination (int pid) | 237 void wait_for_termination (HANDLE pHandle) |
238 #else | |
239 void wait_for_termination (int pid) | |
240 #endif | |
238 { | 241 { |
239 /* #### With the new improved SIGCHLD handling stuff, there is much | 242 /* #### With the new improved SIGCHLD handling stuff, there is much |
240 less danger of race conditions and some of the comments below | 243 less danger of race conditions and some of the comments below |
241 don't apply. This should be updated. */ | 244 don't apply. This should be updated. */ |
242 | 245 |
342 - EINVAL (incorrect arguments), | 345 - EINVAL (incorrect arguments), |
343 which are both program bugs. | 346 which are both program bugs. |
344 | 347 |
345 Since implementations may add their own error indicators on top, | 348 Since implementations may add their own error indicators on top, |
346 we ignore it by default. */ | 349 we ignore it by default. */ |
350 #elif defined (WINDOWSNT) | |
351 int ret = 0, status = 0; | |
352 if (pHandle == NULL) | |
353 { | |
354 stderr_out ("wait_for_termination: pHandle == NULL, GetLastError () = %d, (int)pHandle = %d\n", GetLastError (), (int)pHandle); | |
355 return; | |
356 } | |
357 do | |
358 { | |
359 QUIT; | |
360 ret = WaitForSingleObject(pHandle, 100); | |
361 } | |
362 while (ret == WAIT_TIMEOUT); | |
363 if (ret == WAIT_FAILED) | |
364 { | |
365 stderr_out ("wait_for_termination.WaitForSingleObject returns %d (WAIT_FAILED) GetLastError () %d for (int)pHandle %d\n", ret, GetLastError (), (int)pHandle); | |
366 } | |
367 if (ret == WAIT_ABANDONED) | |
368 { | |
369 stderr_out ("wait_for_termination.WaitForSingleObject returns %d (WAIT_ABANDONED) GetLastError () %d for (int)pHandle %d\n", ret, GetLastError (), (int)pHandle); | |
370 } | |
371 if (ret == WAIT_OBJECT_0) | |
372 { | |
373 ret = GetExitCodeProcess(pHandle, &status); | |
374 if (ret) | |
375 { | |
376 synch_process_alive = 0; | |
377 synch_process_retcode = status; | |
378 } | |
379 else | |
380 { | |
381 /* GetExitCodeProcess() didn't return a valid exit status, | |
382 nothing to do. APA */ | |
383 stderr_out ("wait_for_termination.GetExitCodeProcess status %d GetLastError () %d for (int)pHandle %d\n", status, GetLastError (), (int)pHandle); | |
384 } | |
385 } | |
386 if (pHandle != NULL && !CloseHandle(pHandle)) | |
387 { | |
388 stderr_out ("wait_for_termination.CloseHandle GetLastError () %d for (int)pHandle %d\n", | |
389 GetLastError (), (int)pHandle); | |
390 } | |
347 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) | 391 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) |
348 while (1) | 392 while (1) |
349 { | 393 { |
350 static int wait_debugging = 0; /* Set nonzero to make following | 394 static int wait_debugging = 0; /* Set nonzero to make following |
351 function work under dbx (at least for bsd). */ | 395 function work under dbx (at least for bsd). */ |
373 sigpause()/sigsuspend(), then your OS doesn't implement | 417 sigpause()/sigsuspend(), then your OS doesn't implement |
374 this properly (this applies under hpux9, for example). | 418 this properly (this applies under hpux9, for example). |
375 Try defining BROKEN_WAIT_FOR_SIGNAL. */ | 419 Try defining BROKEN_WAIT_FOR_SIGNAL. */ |
376 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); | 420 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); |
377 } | 421 } |
378 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ | 422 #else /* not HAVE_WAITPID and not WINDOWSNT and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ |
379 /* This approach is kind of cheesy but is guaranteed(?!) to work | 423 /* This approach is kind of cheesy but is guaranteed(?!) to work |
380 for all systems. */ | 424 for all systems. */ |
381 while (1) | 425 while (1) |
382 { | 426 { |
383 QUIT; | 427 QUIT; |
575 | 619 |
576 /* Fork a subshell. */ | 620 /* Fork a subshell. */ |
577 static void | 621 static void |
578 sys_subshell (void) | 622 sys_subshell (void) |
579 { | 623 { |
624 #ifdef WINDOWSNT | |
625 HANDLE pid; | |
626 #else | |
580 int pid; | 627 int pid; |
628 #endif | |
581 struct save_signal saved_handlers[5]; | 629 struct save_signal saved_handlers[5]; |
582 Lisp_Object dir; | 630 Lisp_Object dir; |
583 unsigned char *str = 0; | 631 unsigned char *str = 0; |
584 int len; | 632 int len; |
585 struct gcpro gcpro1; | 633 struct gcpro gcpro1; |
614 if (str[len - 1] != '/') str[len++] = '/'; | 662 if (str[len - 1] != '/') str[len++] = '/'; |
615 str[len] = 0; | 663 str[len] = 0; |
616 xyzzy: | 664 xyzzy: |
617 | 665 |
618 #ifdef WINDOWSNT | 666 #ifdef WINDOWSNT |
619 pid = -1; | 667 pid = NULL; |
620 #else /* not WINDOWSNT */ | 668 #else /* not WINDOWSNT */ |
621 | 669 |
622 pid = fork (); | 670 pid = fork (); |
623 | 671 |
624 if (pid == -1) | 672 if (pid == -1) |
648 #endif | 696 #endif |
649 | 697 |
650 #ifdef WINDOWSNT | 698 #ifdef WINDOWSNT |
651 /* Waits for process completion */ | 699 /* Waits for process completion */ |
652 pid = _spawnlp (_P_WAIT, sh, sh, NULL); | 700 pid = _spawnlp (_P_WAIT, sh, sh, NULL); |
653 if (pid == -1) | 701 if (pid == NULL) |
654 write (1, "Can't execute subshell", 22); | 702 write (1, "Can't execute subshell", 22); |
655 | 703 |
656 #else /* not WINDOWSNT */ | 704 #else /* not WINDOWSNT */ |
657 execlp (sh, sh, 0); | 705 execlp (sh, sh, 0); |
658 write (1, "Can't execute subshell", 22); | 706 write (1, "Can't execute subshell", 22); |