rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit ba2b5321c58c1a7420c7d9d31c1226584537bcaa
parent 8293905f58f0cea00a03ca9bec122de84887a2be
Author: tjg <tjg>
Date:   Thu, 25 May 2000 14:31:27 +0000

  Portability: need special runes for read() returning EIO under job
  control systems.

Diffstat:
MChangeLog | 5+++++
Minput.c | 10+++++++++-
Mopen.c | 18++++++++++++++++++
Mproto.h | 2++
Mrc.h | 1+
5 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog @@ -674,3 +674,8 @@ Changes since rc-1.5b2 Bug: fn sigexit wasn't always cleared in child shells. Bug: `~ () '*'' dumped core. + +2000-05-25 + + Portability: need special runes for read() returning EIO under job + control systems. diff --git a/input.c b/input.c @@ -117,10 +117,18 @@ static int fdgchar() { do { r = rc_read(istack->fd, inbuf + 2, BUFSIZE); sigchk(); - if (errno == EAGAIN) { + switch (errno) { + case EAGAIN: if (!makeblocking(istack->fd)) panic("not O_NONBLOCK"); errno = EINTR; + break; + case EIO: + if (makesamepgrp(istack->fd)) + errno = EINTR; + else + errno = EIO; + break; } } while (r < 0 && errno == EINTR); if (r < 0) { diff --git a/open.c b/open.c @@ -43,3 +43,21 @@ extern bool makeblocking(int fd) { } return TRUE; } + +/* make a file descriptor the same pgrp as us. Returns TRUE if +it changes anything. */ + +extern bool makesamepgrp(int fd) { + pid_t grp; + + grp = getpgrp(); + + if (tcgetpgrp(fd) == grp) + return FALSE; + + if (tcsetpgrp(fd, grp) < 0) { + uerror("tcsetgrp"); + return FALSE; + } + return TRUE; +} diff --git a/proto.h b/proto.h @@ -79,6 +79,7 @@ extern char *sys_errlist[]; #else /* BSD: fake it. */ #define setpgid(pid, pgrp) setpgrp(pid, pgrp) +#define tcgetpgrp(fd, pgrp) ioctl((fd), TIOCGPGRP) #define tcsetpgrp(fd, pgrp) ioctl((fd), TIOCSPGRP, &(pgrp)) #endif @@ -86,6 +87,7 @@ extern char *sys_errlist[]; /* Nothing doing. */ #define setpgid() +#define tcgetpgrp() #define tcsetpgrp() #endif /*HAVE_SETPGRP */ diff --git a/rc.h b/rc.h @@ -305,6 +305,7 @@ extern void restoreblock(Block *); /* open.c */ extern int rc_open(const char *, redirtype); extern bool makeblocking(int); +extern bool makesamepgrp(int); /* print.c */ /*