Mercurial > hg > xemacs-beta
comparison src/sysdep.c @ 432:3a7e78e1142d r21-2-24
Import from CVS: tag r21-2-24
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:29:58 +0200 |
parents | a5df635868b2 |
children | 84b14dcb0985 |
comparison
equal
deleted
inserted
replaced
431:a97165e56215 | 432:3a7e78e1142d |
---|---|
232 #endif /* BSD */ | 232 #endif /* BSD */ |
233 | 233 |
234 #endif /* NO_SUBPROCESSES */ | 234 #endif /* NO_SUBPROCESSES */ |
235 | 235 |
236 | 236 |
237 void | 237 #ifdef WINDOWSNT |
238 wait_for_termination (int pid) | 238 void wait_for_termination (HANDLE pHandle) |
239 #else | |
240 void wait_for_termination (int pid) | |
241 #endif | |
239 { | 242 { |
240 /* #### With the new improved SIGCHLD handling stuff, there is much | 243 /* #### With the new improved SIGCHLD handling stuff, there is much |
241 less danger of race conditions and some of the comments below | 244 less danger of race conditions and some of the comments below |
242 don't apply. This should be updated. */ | 245 don't apply. This should be updated. */ |
243 | 246 |
343 - EINVAL (incorrect arguments), | 346 - EINVAL (incorrect arguments), |
344 which are both program bugs. | 347 which are both program bugs. |
345 | 348 |
346 Since implementations may add their own error indicators on top, | 349 Since implementations may add their own error indicators on top, |
347 we ignore it by default. */ | 350 we ignore it by default. */ |
351 #elif defined (WINDOWSNT) | |
352 int ret = 0, status = 0; | |
353 if (pHandle == NULL) | |
354 { | |
355 warn_when_safe (Qprocess, Qwarning, "Cannot wait for unknown process to terminate"); | |
356 return; | |
357 } | |
358 do | |
359 { | |
360 QUIT; | |
361 ret = WaitForSingleObject(pHandle, 100); | |
362 } | |
363 while (ret == WAIT_TIMEOUT); | |
364 if (ret == WAIT_FAILED) | |
365 { | |
366 warn_when_safe (Qprocess, Qwarning, "waiting for process failed"); | |
367 } | |
368 if (ret == WAIT_ABANDONED) | |
369 { | |
370 warn_when_safe (Qprocess, Qwarning, | |
371 "process to wait for has been abandoned"); | |
372 } | |
373 if (ret == WAIT_OBJECT_0) | |
374 { | |
375 ret = GetExitCodeProcess(pHandle, &status); | |
376 if (ret) | |
377 { | |
378 synch_process_alive = 0; | |
379 synch_process_retcode = status; | |
380 } | |
381 else | |
382 { | |
383 /* GetExitCodeProcess() didn't return a valid exit status, | |
384 nothing to do. APA */ | |
385 warn_when_safe (Qprocess, Qwarning, | |
386 "failure to obtain process exit value"); | |
387 } | |
388 } | |
389 if (pHandle != NULL && !CloseHandle(pHandle)) | |
390 { | |
391 warn_when_safe (Qprocess, Qwarning, | |
392 "failure to close unknown process"); | |
393 } | |
348 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) | 394 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) |
349 while (1) | 395 while (1) |
350 { | 396 { |
351 static int wait_debugging = 0; /* Set nonzero to make following | 397 static int wait_debugging = 0; /* Set nonzero to make following |
352 function work under dbx (at least for bsd). */ | 398 function work under dbx (at least for bsd). */ |
374 sigpause()/sigsuspend(), then your OS doesn't implement | 420 sigpause()/sigsuspend(), then your OS doesn't implement |
375 this properly (this applies under hpux9, for example). | 421 this properly (this applies under hpux9, for example). |
376 Try defining BROKEN_WAIT_FOR_SIGNAL. */ | 422 Try defining BROKEN_WAIT_FOR_SIGNAL. */ |
377 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); | 423 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); |
378 } | 424 } |
379 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ | 425 #else /* not HAVE_WAITPID and not WINDOWSNT and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ |
380 /* This approach is kind of cheesy but is guaranteed(?!) to work | 426 /* This approach is kind of cheesy but is guaranteed(?!) to work |
381 for all systems. */ | 427 for all systems. */ |
382 while (1) | 428 while (1) |
383 { | 429 { |
384 QUIT; | 430 QUIT; |
576 | 622 |
577 /* Fork a subshell. */ | 623 /* Fork a subshell. */ |
578 static void | 624 static void |
579 sys_subshell (void) | 625 sys_subshell (void) |
580 { | 626 { |
627 #ifdef WINDOWSNT | |
628 HANDLE pid; | |
629 #else | |
581 int pid; | 630 int pid; |
631 #endif | |
582 struct save_signal saved_handlers[5]; | 632 struct save_signal saved_handlers[5]; |
583 Lisp_Object dir; | 633 Lisp_Object dir; |
584 unsigned char *str = 0; | 634 unsigned char *str = 0; |
585 int len; | 635 int len; |
586 struct gcpro gcpro1; | 636 struct gcpro gcpro1; |
615 if (str[len - 1] != '/') str[len++] = '/'; | 665 if (str[len - 1] != '/') str[len++] = '/'; |
616 str[len] = 0; | 666 str[len] = 0; |
617 xyzzy: | 667 xyzzy: |
618 | 668 |
619 #ifdef WINDOWSNT | 669 #ifdef WINDOWSNT |
620 pid = -1; | 670 pid = NULL; |
621 #else /* not WINDOWSNT */ | 671 #else /* not WINDOWSNT */ |
622 | 672 |
623 pid = fork (); | 673 pid = fork (); |
624 | 674 |
625 if (pid == -1) | 675 if (pid == -1) |
649 #endif | 699 #endif |
650 | 700 |
651 #ifdef WINDOWSNT | 701 #ifdef WINDOWSNT |
652 /* Waits for process completion */ | 702 /* Waits for process completion */ |
653 pid = _spawnlp (_P_WAIT, sh, sh, NULL); | 703 pid = _spawnlp (_P_WAIT, sh, sh, NULL); |
654 if (pid == -1) | 704 if (pid == NULL) |
655 write (1, "Can't execute subshell", 22); | 705 write (1, "Can't execute subshell", 22); |
656 | 706 |
657 #else /* not WINDOWSNT */ | 707 #else /* not WINDOWSNT */ |
658 execlp (sh, sh, 0); | 708 execlp (sh, sh, 0); |
659 write (1, "Can't execute subshell", 22); | 709 write (1, "Can't execute subshell", 22); |
3034 PATHNAME_CONVERT_OUT (path); | 3084 PATHNAME_CONVERT_OUT (path); |
3035 /* #### currently we don't do conversions on the incoming data */ | 3085 /* #### currently we don't do conversions on the incoming data */ |
3036 return readlink (path, buf, bufsiz); | 3086 return readlink (path, buf, bufsiz); |
3037 } | 3087 } |
3038 #endif /* ENCAPSULATE_READLINK */ | 3088 #endif /* ENCAPSULATE_READLINK */ |
3089 | |
3090 | |
3091 #ifdef ENCAPSULATE_FSTAT | |
3092 int | |
3093 sys_fstat (int fd, struct stat *buf) | |
3094 { | |
3095 return fstat (fd, buf); | |
3096 } | |
3097 #endif /* ENCAPSULATE_FSTAT */ | |
3039 | 3098 |
3040 | 3099 |
3041 #ifdef ENCAPSULATE_STAT | 3100 #ifdef ENCAPSULATE_STAT |
3042 int | 3101 int |
3043 sys_stat (CONST char *path, struct stat *buf) | 3102 sys_stat (CONST char *path, struct stat *buf) |