comparison src/sysdep.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents cc15677e0335
children 064ab7fed2e0
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
210 int one = 1; 210 int one = 1;
211 ioctl (fd, FIONBIO, &one); 211 ioctl (fd, FIONBIO, &one);
212 } 212 }
213 #endif 213 #endif
214 214
215 #ifdef O_NONBLOCK /* The POSIX way */
216 fcntl (fd, F_SETFL, O_NONBLOCK); 215 fcntl (fd, F_SETFL, O_NONBLOCK);
217 #elif defined (O_NDELAY)
218 fcntl (fd, F_SETFL, O_NDELAY);
219 #endif /* O_NONBLOCK */
220 } 216 }
221 217
222 #if defined (NO_SUBPROCESSES) 218 #if defined (NO_SUBPROCESSES)
223 219
224 #ifdef BSD 220 #ifdef BSD
454 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */ 450 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
455 #endif /* 0 */ 451 #endif /* 0 */
456 452
457 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */ 453 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
458 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */ 454 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
459 s.main.c_cc[VERASE] = CDISABLE; /* disable erase processing */ 455 s.main.c_cc[VERASE] = _POSIX_VDISABLE; /* disable erase processing */
460 s.main.c_cc[VKILL] = CDISABLE; /* disable kill processing */ 456 s.main.c_cc[VKILL] = _POSIX_VDISABLE; /* disable kill processing */
461 457
462 #ifdef HPUX 458 #ifdef HPUX
463 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ 459 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
464 #endif /* HPUX */ 460 #endif /* HPUX */
465 461
483 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */ 479 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
484 s.main.c_cc[VSUSP] = 'Z' &037; /* Control-Z */ 480 s.main.c_cc[VSUSP] = 'Z' &037; /* Control-Z */
485 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ 481 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
486 /* TTY `special characters' work better as signals, so disable 482 /* TTY `special characters' work better as signals, so disable
487 character forms */ 483 character forms */
488 s.main.c_cc[VQUIT] = CDISABLE; 484 s.main.c_cc[VQUIT] = _POSIX_VDISABLE;
489 s.main.c_cc[VINTR] = CDISABLE; 485 s.main.c_cc[VINTR] = _POSIX_VDISABLE;
490 s.main.c_cc[VSUSP] = CDISABLE; 486 s.main.c_cc[VSUSP] = _POSIX_VDISABLE;
491 s.main.c_lflag &= ~ISIG; 487 s.main.c_lflag &= ~ISIG;
492 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ 488 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
493 s.main.c_cc[VEOL] = CDISABLE; 489 s.main.c_cc[VEOL] = _POSIX_VDISABLE;
494 #if defined (CBAUD) 490 #if defined (CBAUD)
495 /* <mdiers> ### This is not portable. ### 491 /* <mdiers> ### This is not portable. ###
496 POSIX does not specify CBAUD, and 4.4BSD does not have it. 492 POSIX does not specify CBAUD, and 4.4BSD does not have it.
497 Instead, POSIX suggests to use cfset{i,o}speed(). 493 Instead, POSIX suggests to use cfset{i,o}speed().
498 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal 494 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
747 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1)) 743 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
748 return ctrl_d; 744 return ctrl_d;
749 else 745 else
750 return (Bufbyte) t.c_cc[VEOF]; 746 return (Bufbyte) t.c_cc[VEOF];
751 #endif 747 #endif
752 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF]; 748 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
753 } 749 }
754 #else /* ! HAVE_TERMIOS */ 750 #else /* ! HAVE_TERMIOS */
755 /* On Berkeley descendants, the following IOCTL's retrieve the 751 /* On Berkeley descendants, the following IOCTL's retrieve the
756 current control characters. */ 752 current control characters. */
757 #if defined (TIOCGETC) 753 #if defined (TIOCGETC)
1532 so which one it really gives us does not matter. */ 1528 so which one it really gives us does not matter. */
1533 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con); 1529 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con);
1534 } 1530 }
1535 else 1531 else
1536 { 1532 {
1537 tty.main.c_cc[VINTR] = CDISABLE; 1533 tty.main.c_cc[VINTR] = _POSIX_VDISABLE;
1538 tty.main.c_cc[VQUIT] = CDISABLE; 1534 tty.main.c_cc[VQUIT] = _POSIX_VDISABLE;
1539 } 1535 }
1540 tty.main.c_cc[VMIN] = 1; /* Input should wait for at 1536 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
1541 least 1 char */ 1537 least 1 char */
1542 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ 1538 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
1543 #ifdef VSWTCH 1539 #ifdef VSWTCH
1544 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use 1540 tty.main.c_cc[VSWTCH] = _POSIX_VDISABLE; /* Turn off shell layering use
1545 of C-z */ 1541 of C-z */
1546 #endif /* VSWTCH */ 1542 #endif /* VSWTCH */
1547 /* There was some conditionalizing here on (mips or TCATTR), but 1543 /* There was some conditionalizing here on (mips or TCATTR), but
1548 I think that's wrong. There was one report of C-y (DSUSP) not being 1544 I think that's wrong. There was one report of C-y (DSUSP) not being
1549 disabled on HP9000s700 systems, and this might fix it. */ 1545 disabled on HP9000s700 systems, and this might fix it. */
1550 #ifdef VSUSP 1546 #ifdef VSUSP
1551 tty.main.c_cc[VSUSP] = CDISABLE;/* Turn off mips handling of C-z. */ 1547 tty.main.c_cc[VSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-z. */
1552 #endif /* VSUSP */ 1548 #endif /* VSUSP */
1553 #ifdef V_DSUSP 1549 #ifdef V_DSUSP
1554 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ 1550 tty.main.c_cc[V_DSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-y. */
1555 #endif /* V_DSUSP */ 1551 #endif /* V_DSUSP */
1556 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */ 1552 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1557 tty.main.c_cc[VDSUSP] = CDISABLE; 1553 tty.main.c_cc[VDSUSP] = _POSIX_VDISABLE;
1558 #endif /* VDSUSP */ 1554 #endif /* VDSUSP */
1559 #ifdef VLNEXT 1555 #ifdef VLNEXT
1560 tty.main.c_cc[VLNEXT] = CDISABLE; 1556 tty.main.c_cc[VLNEXT] = _POSIX_VDISABLE;
1561 #endif /* VLNEXT */ 1557 #endif /* VLNEXT */
1562 #ifdef VREPRINT 1558 #ifdef VREPRINT
1563 tty.main.c_cc[VREPRINT] = CDISABLE; 1559 tty.main.c_cc[VREPRINT] = _POSIX_VDISABLE;
1564 #endif /* VREPRINT */ 1560 #endif /* VREPRINT */
1565 #ifdef VWERASE 1561 #ifdef VWERASE
1566 tty.main.c_cc[VWERASE] = CDISABLE; 1562 tty.main.c_cc[VWERASE] = _POSIX_VDISABLE;
1567 #endif /* VWERASE */ 1563 #endif /* VWERASE */
1568 #ifdef VDISCARD 1564 #ifdef VDISCARD
1569 tty.main.c_cc[VDISCARD] = CDISABLE; 1565 tty.main.c_cc[VDISCARD] = _POSIX_VDISABLE;
1570 #endif /* VDISCARD */ 1566 #endif /* VDISCARD */
1571 #ifdef VSTART 1567 #ifdef VSTART
1572 tty.main.c_cc[VSTART] = CDISABLE; 1568 tty.main.c_cc[VSTART] = _POSIX_VDISABLE;
1573 #endif /* VSTART */ 1569 #endif /* VSTART */
1574 #ifdef VSTRT 1570 #ifdef VSTRT
1575 tty.main.c_cc[VSTRT] = CDISABLE; /* called VSTRT on some systems */ 1571 tty.main.c_cc[VSTRT] = _POSIX_VDISABLE; /* called VSTRT on some systems */
1576 #endif /* VSTART */ 1572 #endif /* VSTART */
1577 #ifdef VSTOP 1573 #ifdef VSTOP
1578 tty.main.c_cc[VSTOP] = CDISABLE; 1574 tty.main.c_cc[VSTOP] = _POSIX_VDISABLE;
1579 #endif /* VSTOP */ 1575 #endif /* VSTOP */
1580 #ifdef SET_LINE_DISCIPLINE 1576 #ifdef SET_LINE_DISCIPLINE
1581 /* Need to explicitely request TERMIODISC line discipline or 1577 /* Need to explicitly request TERMIODISC line discipline or
1582 Ultrix's termios does not work correctly. */ 1578 Ultrix's termios does not work correctly. */
1583 tty.main.c_line = SET_LINE_DISCIPLINE; 1579 tty.main.c_line = SET_LINE_DISCIPLINE;
1584 #endif 1580 #endif
1585 1581
1586 #ifdef AIX 1582 #ifdef AIX
2070 2066
2071 /************************************************************************/ 2067 /************************************************************************/
2072 /* limits of text/data segments */ 2068 /* limits of text/data segments */
2073 /************************************************************************/ 2069 /************************************************************************/
2074 2070
2075 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2076 #ifndef CANNOT_DUMP 2071 #ifndef CANNOT_DUMP
2077 #define NEED_STARTS 2072 #define NEED_STARTS
2078 #endif 2073 #endif
2079 2074
2080 #ifndef SYSTEM_MALLOC 2075 #ifndef SYSTEM_MALLOC
2135 * 2130 *
2136 * Probably what will have to happen when a USG unexec is available, 2131 * Probably what will have to happen when a USG unexec is available,
2137 * at least on UniPlus, is temacs will have to be made unshared so 2132 * at least on UniPlus, is temacs will have to be made unshared so
2138 * that text and data are contiguous. Then once loadup is complete, 2133 * that text and data are contiguous. Then once loadup is complete,
2139 * unexec will produce a shared executable where the data can be 2134 * unexec will produce a shared executable where the data can be
2140 * at the normal shared text boundry and the startofdata variable 2135 * at the normal shared text boundary and the startofdata variable
2141 * will be patched by unexec to the correct value. 2136 * will be patched by unexec to the correct value.
2142 * 2137 *
2143 */ 2138 */
2144 2139
2145 #ifdef ORDINARY_LINK 2140 #ifdef ORDINARY_LINK
2592 return open (path, oflag | _O_NOINHERIT, mode); 2587 return open (path, oflag | _O_NOINHERIT, mode);
2593 #elif defined (INTERRUPTIBLE_OPEN) 2588 #elif defined (INTERRUPTIBLE_OPEN)
2594 { 2589 {
2595 int rtnval; 2590 int rtnval;
2596 while ((rtnval = open (path, oflag, mode)) == -1 2591 while ((rtnval = open (path, oflag, mode)) == -1
2597 && (errno == EINTR)); 2592 && (errno == EINTR))
2593 DO_NOTHING;
2598 return rtnval; 2594 return rtnval;
2599 } 2595 }
2600 #else 2596 #else
2601 return open (path, oflag, mode); 2597 return open (path, oflag, mode);
2602 #endif 2598 #endif
2777 return _fdopen (fd, type_save); 2773 return _fdopen (fd, type_save);
2778 } 2774 }
2779 #elif defined (INTERRUPTIBLE_OPEN) 2775 #elif defined (INTERRUPTIBLE_OPEN)
2780 { 2776 {
2781 FILE *rtnval; 2777 FILE *rtnval;
2782 while (!(rtnval = fopen (path, type)) && (errno == EINTR)); 2778 while (!(rtnval = fopen (path, type)) && (errno == EINTR))
2779 DO_NOTHING;
2783 return rtnval; 2780 return rtnval;
2784 } 2781 }
2785 #else 2782 #else
2786 return fopen (path, type); 2783 return fopen (path, type);
2787 #endif 2784 #endif
3680 { 3677 {
3681 DIR *dirp; /* -> malloc'ed storage */ 3678 DIR *dirp; /* -> malloc'ed storage */
3682 int fd; /* file descriptor for read */ 3679 int fd; /* file descriptor for read */
3683 struct stat sbuf; /* result of fstat */ 3680 struct stat sbuf; /* result of fstat */
3684 3681
3685 fd = sys_open (filename, 0); 3682 fd = sys_open (filename, O_RDONLY);
3686 if (fd < 0) 3683 if (fd < 0)
3687 return 0; 3684 return 0;
3688 3685
3689 if (fstat (fd, &sbuf) < 0 3686 if (fstat (fd, &sbuf) < 0
3690 || (sbuf.st_mode & S_IFMT) != S_IFDIR 3687 || (sbuf.st_mode & S_IFMT) != S_IFDIR
3797 synch_process_alive = 1; 3794 synch_process_alive = 1;
3798 switch (cpid = fork ()) 3795 switch (cpid = fork ())
3799 { 3796 {
3800 3797
3801 case -1: /* Error in fork() */ 3798 case -1: /* Error in fork() */
3802 return (-1); /* Errno is set already */ 3799 return -1; /* Errno is set already */
3803 3800
3804 case 0: /* Child process */ 3801 case 0: /* Child process */
3805 { 3802 {
3806 /* 3803 /*
3807 * Cheap hack to set mode of new directory. Since this 3804 * Cheap hack to set mode of new directory. Since this
3808 * child process is going away anyway, we zap its umask. 3805 * child process is going away anyway, we zap its umask.
3809 * ####, this won't suffice to set SUID, SGID, etc. on this 3806 * ####, this won't suffice to set SUID, SGID, etc. on this
3810 * directory. Does anybody care? 3807 * directory. Does anybody care?
3811 */ 3808 */
3812 status = umask (0); /* Get current umask */ 3809 status = umask (0); /* Get current umask */
3813 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */ 3810 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
3814 fd = sys_open ("/dev/null", 2); 3811 fd = sys_open ("/dev/null", O_RDWR);
3815 if (fd >= 0) 3812 if (fd >= 0)
3816 { 3813 {
3817 dup2 (fd, 0); 3814 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
3818 dup2 (fd, 1); 3815 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
3819 dup2 (fd, 2); 3816 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
3820 } 3817 }
3821 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0); 3818 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
3822 _exit (-1); /* Can't exec /bin/mkdir */ 3819 _exit (-1); /* Can't exec /bin/mkdir */
3823 } 3820 }
3824 3821
3855 3852
3856 case -1: /* Error in fork() */ 3853 case -1: /* Error in fork() */
3857 return (-1); /* Errno is set already */ 3854 return (-1); /* Errno is set already */
3858 3855
3859 case 0: /* Child process */ 3856 case 0: /* Child process */
3860 fd = sys_open("/dev/null", 2); 3857 fd = sys_open("/dev/null", O_RDWR);
3861 if (fd >= 0) 3858 if (fd >= 0)
3862 { 3859 {
3863 dup2 (fd, 0); 3860 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
3864 dup2 (fd, 1); 3861 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
3865 dup2 (fd, 2); 3862 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
3866 } 3863 }
3867 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0); 3864 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
3868 _exit (-1); /* Can't exec /bin/mkdir */ 3865 _exit (-1); /* Can't exec /bin/mkdir */
3869 3866
3870 default: /* Parent process */ 3867 default: /* Parent process */
3871 wait_for_termination (cpid); 3868 wait_for_termination (cpid);
3872 } 3869 }
3873 3870
3874 if (synch_process_death != 0 || synch_process_retcode != 0) 3871 if (synch_process_death != 0 ||
3872 synch_process_retcode != 0)
3875 { 3873 {
3876 errno = EIO; /* We don't know why, but */ 3874 errno = EIO; /* We don't know why, but */
3877 return -1; /* /bin/rmdir failed */ 3875 return -1; /* /bin/rmdir failed */
3878 } 3876 }
3879 3877