comparison src/sysdep.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents a4f53d9b3154
children 8626e4521993
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
231 #endif /* BSD */ 231 #endif /* BSD */
232 232
233 #endif /* NO_SUBPROCESSES */ 233 #endif /* NO_SUBPROCESSES */
234 234
235 235
236 #ifdef WINDOWSNT 236 void
237 void wait_for_termination (HANDLE pHandle) 237 wait_for_termination (int pid)
238 #else
239 void wait_for_termination (int pid)
240 #endif
241 { 238 {
242 /* #### With the new improved SIGCHLD handling stuff, there is much 239 /* #### With the new improved SIGCHLD handling stuff, there is much
243 less danger of race conditions and some of the comments below 240 less danger of race conditions and some of the comments below
244 don't apply. This should be updated. */ 241 don't apply. This should be updated. */
245 242
345 - EINVAL (incorrect arguments), 342 - EINVAL (incorrect arguments),
346 which are both program bugs. 343 which are both program bugs.
347 344
348 Since implementations may add their own error indicators on top, 345 Since implementations may add their own error indicators on top,
349 we ignore it by default. */ 346 we ignore it by default. */
350 #elif defined (WINDOWSNT)
351 int ret = 0, status = 0;
352 if (pHandle == NULL)
353 {
354 warn_when_safe (Qprocess, Qerror, "Cannot wait for NULL process handle.");
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 warn_when_safe (Qprocess, Qerror,
366 "WaitForSingleObject returns WAIT_FAILED for process handle %p.",
367 pHandle);
368 }
369 if (ret == WAIT_ABANDONED)
370 {
371 warn_when_safe (Qprocess, Qerror,
372 "WaitForSingleObject returns WAIT_ABANDONED for process handle %p.",
373 pHandle);
374 }
375 if (ret == WAIT_OBJECT_0)
376 {
377 ret = GetExitCodeProcess(pHandle, &status);
378 if (ret)
379 {
380 synch_process_alive = 0;
381 synch_process_retcode = status;
382 }
383 else
384 {
385 /* GetExitCodeProcess() didn't return a valid exit status,
386 nothing to do. APA */
387 warn_when_safe (Qprocess, Qerror,
388 "GetExitCodeProcess fails for process handle %p.",
389 pHandle);
390 }
391 }
392 if (pHandle != NULL && !CloseHandle(pHandle))
393 {
394 warn_when_safe (Qprocess, Qerror,
395 "CloseHandle fails for process handle %p.", pHandle);
396 }
397 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD) 347 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
398 while (1) 348 while (1)
399 { 349 {
400 static int wait_debugging = 0; /* Set nonzero to make following 350 static int wait_debugging = 0; /* Set nonzero to make following
401 function work under dbx (at least for bsd). */ 351 function work under dbx (at least for bsd). */
423 sigpause()/sigsuspend(), then your OS doesn't implement 373 sigpause()/sigsuspend(), then your OS doesn't implement
424 this properly (this applies under hpux9, for example). 374 this properly (this applies under hpux9, for example).
425 Try defining BROKEN_WAIT_FOR_SIGNAL. */ 375 Try defining BROKEN_WAIT_FOR_SIGNAL. */
426 EMACS_WAIT_FOR_SIGNAL (SIGCHLD); 376 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
427 } 377 }
428 #else /* not HAVE_WAITPID and not WINDOWSNT and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */ 378 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
429 /* This approach is kind of cheesy but is guaranteed(?!) to work 379 /* This approach is kind of cheesy but is guaranteed(?!) to work
430 for all systems. */ 380 for all systems. */
431 while (1) 381 while (1)
432 { 382 {
433 QUIT; 383 QUIT;
625 575
626 /* Fork a subshell. */ 576 /* Fork a subshell. */
627 static void 577 static void
628 sys_subshell (void) 578 sys_subshell (void)
629 { 579 {
630 #ifdef WINDOWSNT
631 HANDLE pid;
632 #else
633 int pid; 580 int pid;
634 #endif
635 struct save_signal saved_handlers[5]; 581 struct save_signal saved_handlers[5];
636 Lisp_Object dir; 582 Lisp_Object dir;
637 unsigned char *str = 0; 583 unsigned char *str = 0;
638 int len; 584 int len;
639 struct gcpro gcpro1; 585 struct gcpro gcpro1;
668 if (str[len - 1] != '/') str[len++] = '/'; 614 if (str[len - 1] != '/') str[len++] = '/';
669 str[len] = 0; 615 str[len] = 0;
670 xyzzy: 616 xyzzy:
671 617
672 #ifdef WINDOWSNT 618 #ifdef WINDOWSNT
673 pid = NULL; 619 pid = -1;
674 #else /* not WINDOWSNT */ 620 #else /* not WINDOWSNT */
675 621
676 pid = fork (); 622 pid = fork ();
677 623
678 if (pid == -1) 624 if (pid == -1)
702 #endif 648 #endif
703 649
704 #ifdef WINDOWSNT 650 #ifdef WINDOWSNT
705 /* Waits for process completion */ 651 /* Waits for process completion */
706 pid = _spawnlp (_P_WAIT, sh, sh, NULL); 652 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
707 if (pid == NULL) 653 if (pid == -1)
708 write (1, "Can't execute subshell", 22); 654 write (1, "Can't execute subshell", 22);
709 655
710 #else /* not WINDOWSNT */ 656 #else /* not WINDOWSNT */
711 execlp (sh, sh, 0); 657 execlp (sh, sh, 0);
712 write (1, "Can't execute subshell", 22); 658 write (1, "Can't execute subshell", 22);
767 so that the function works even fd is not a pty. */ 713 so that the function works even fd is not a pty. */
768 714
769 int 715 int
770 get_pty_max_bytes (int fd) 716 get_pty_max_bytes (int fd)
771 { 717 {
772 /* DEC OSF fpathconf returns 255, but xemacs hangs on long shell 718 int pty_max_bytes;
773 input lines if we return 253. 252 is OK!. So let's leave a bit 719
774 of slack for the newline that xemacs will insert, and for those
775 inevitable vendor off-by-one-or-two-or-three bugs. */
776 #define MAX_CANON_SLACK 10
777 #define SAFE_MAX_CANON 120
778 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON) 720 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
779 { 721 pty_max_bytes = fpathconf (fd, _PC_MAX_CANON);
780 int max_canon = fpathconf (fd, _PC_MAX_CANON); 722 if (pty_max_bytes < 0)
781 #ifdef __hpux__ 723 #endif
782 /* HP-UX 10.20 fpathconf returns 768, but this results in 724 pty_max_bytes = 250;
783 truncated input lines, while 255 works. */ 725
784 if (max_canon > 255) max_canon = 255; 726 /* Deduct one, to leave space for the eof. */
785 #endif 727 pty_max_bytes--;
786 return (max_canon < 0 ? SAFE_MAX_CANON : 728
787 max_canon > SAFE_MAX_CANON ? max_canon - MAX_CANON_SLACK : 729 return pty_max_bytes;
788 max_canon);
789 }
790 #elif defined (_POSIX_MAX_CANON)
791 return (_POSIX_MAX_CANON > SAFE_MAX_CANON ?
792 _POSIX_MAX_CANON - MAX_CANON_SLACK :
793 _POSIX_MAX_CANON);
794 #else
795 return SAFE_MAX_CANON;
796 #endif
797 } 730 }
798 731
799 /* Figure out the eof character for the FD. */ 732 /* Figure out the eof character for the FD. */
800 733
801 Bufbyte 734 Bufbyte
1082 static void 1015 static void
1083 request_sigio_on_device (struct device *d) 1016 request_sigio_on_device (struct device *d)
1084 { 1017 {
1085 int filedesc = DEVICE_INFD (d); 1018 int filedesc = DEVICE_INFD (d);
1086 1019
1087 #if defined (I_SETSIG) && !defined(HPUX10) && !defined(LINUX) 1020 #if defined (I_SETSIG) && !defined(HPUX10)
1088 { 1021 {
1089 int events=0; 1022 int events=0;
1090 ioctl (filedesc, I_GETSIG, &events); 1023 ioctl (filedesc, I_GETSIG, &events);
1091 ioctl (filedesc, I_SETSIG, events | S_INPUT); 1024 ioctl (filedesc, I_SETSIG, events | S_INPUT);
1092 } 1025 }
1127 static void 1060 static void
1128 unrequest_sigio_on_device (struct device *d) 1061 unrequest_sigio_on_device (struct device *d)
1129 { 1062 {
1130 int filedesc = DEVICE_INFD (d); 1063 int filedesc = DEVICE_INFD (d);
1131 1064
1132 #if defined (I_SETSIG) && !defined(HPUX10) && !defined(LINUX) 1065 #if defined (I_SETSIG) && !defined(HPUX10)
1133 { 1066 {
1134 int events=0; 1067 int events=0;
1135 ioctl (filedesc, I_GETSIG, &events); 1068 ioctl (filedesc, I_GETSIG, &events);
1136 ioctl (filedesc, I_SETSIG, events & ~S_INPUT); 1069 ioctl (filedesc, I_SETSIG, events & ~S_INPUT);
1137 } 1070 }
3098 PATHNAME_CONVERT_OUT (path); 3031 PATHNAME_CONVERT_OUT (path);
3099 /* #### currently we don't do conversions on the incoming data */ 3032 /* #### currently we don't do conversions on the incoming data */
3100 return readlink (path, buf, bufsiz); 3033 return readlink (path, buf, bufsiz);
3101 } 3034 }
3102 #endif /* ENCAPSULATE_READLINK */ 3035 #endif /* ENCAPSULATE_READLINK */
3103
3104
3105 #ifdef ENCAPSULATE_FSTAT
3106 int
3107 sys_fstat (int fd, struct stat *buf)
3108 {
3109 return fstat (fd, buf);
3110 }
3111 #endif /* ENCAPSULATE_FSTAT */
3112 3036
3113 3037
3114 #ifdef ENCAPSULATE_STAT 3038 #ifdef ENCAPSULATE_STAT
3115 int 3039 int
3116 sys_stat (CONST char *path, struct stat *buf) 3040 sys_stat (CONST char *path, struct stat *buf)