| tVarious fixes. - plan9port - [fork] Plan 9 from user space | |
| git clone git://src.adamsgaard.dk/plan9port | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| commit 669250d159e93a6933afa4cd25f410af801515ec | |
| parent 5a82f26e50fbfbb3090b4cf839decf012637a00e | |
| Author: rsc <devnull@localhost> | |
| Date: Wed, 3 Dec 2003 22:50:48 +0000 | |
| Various fixes. | |
| B - fixed usage, DISPLAY :0 vs :0.0 | |
| 9term - fixed various terminal things | |
| rc - notice traps in Read | |
| _p9dir - only run disk code for disks | |
| dirread - getdirentries on FreeBSD and Linux | |
| are different w.r.t. meaning of off. | |
| notify - set up so signals interrupt system calls | |
| bprint - use bfmt. | |
| Diffstat: | |
| M bin/B | 6 +++++- | |
| M include/bio.h | 4 +++- | |
| M src/cmd/9term/9term.c | 67 ++++++++++++++++++++++-------… | |
| M src/cmd/9term/FreeBSD.c | 3 +-- | |
| M src/cmd/rc/plan9ish.c | 16 +++++++++++----- | |
| M src/lib9/_p9dir.c | 32 +++++++++++++++++++++++++++++… | |
| M src/lib9/dirread.c | 11 ++--------- | |
| M src/lib9/notify.c | 11 ++++++----- | |
| M src/libbio/bcat.c | 4 ++++ | |
| M src/libbio/bprint.c | 28 ++++++++++------------------ | |
| M src/libbio/mkfile | 5 +++-- | |
| 11 files changed, 124 insertions(+), 63 deletions(-) | |
| --- | |
| diff --git a/bin/B b/bin/B | |
| t@@ -2,7 +2,7 @@ | |
| if [ $# -eq 0 ] | |
| then | |
| - echo 'usage: B cmd...' 2>&1 | |
| + echo 'usage: B file...' 2>&1 | |
| exit 1 | |
| fi | |
| t@@ -10,6 +10,10 @@ if [ "x$DISPLAY" = "x" ] | |
| then | |
| sam="/tmp/.sam.$USER" | |
| else | |
| + if [ "$DISPLAY" = ":0" ] | |
| + then | |
| + DISPLAY=:0.0 | |
| + fi | |
| sam="/tmp/.sam.$USER.$DISPLAY" | |
| fi | |
| diff --git a/include/bio.h b/include/bio.h | |
| t@@ -30,7 +30,7 @@ struct Biobuf | |
| int icount; /* neg num of bytes at eob */ | |
| int ocount; /* num of bytes at bob */ | |
| int rdline; /* num of bytes after rdline */ | |
| - int runesize; /* num of bytes of last getrune */ | |
| + int runesize; /* num of bytes of last getrune */ | |
| int state; /* r/w/inactive */ | |
| int fid; /* open file */ | |
| int flag; /* magic if malloc'ed */ | |
| t@@ -59,6 +59,8 @@ struct Biobuf | |
| int Bbuffered(Biobuf*); | |
| Biobuf* Bfdopen(int, int); | |
| +int Bfmtinit(Fmt*, Biobuf*); | |
| +int Bfmtflush(Fmt*); | |
| int Bfildes(Biobuf*); | |
| int Bflush(Biobuf*); | |
| int Bgetc(Biobuf*); | |
| diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c | |
| t@@ -108,7 +108,6 @@ threadmain(int argc, char *argv[]) | |
| draw(screen, screen->r, cols[BACK], nil, ZP); | |
| geom(); | |
| - | |
| loop(); | |
| } | |
| t@@ -118,7 +117,7 @@ hangupnote(void *a, char *msg) | |
| if(getpid() != mainpid) | |
| noted(NDFLT); | |
| if(strcmp(msg, "hangup") == 0 && rcpid != 0){ | |
| - postnote(PNPROC, rcpid, "hangup"); | |
| + postnote(PNGROUP, rcpid, "hangup"); | |
| noted(NDFLT); | |
| } | |
| noted(NDFLT); | |
| t@@ -206,9 +205,13 @@ doreshape(void) | |
| scrdraw(); | |
| } | |
| +struct winsize ows; | |
| + | |
| void | |
| geom(void) | |
| { | |
| + struct winsize ws; | |
| + Point p; | |
| Rectangle r; | |
| r = screen->r; | |
| t@@ -223,6 +226,18 @@ geom(void) | |
| t.f->maxtab = maxtab*stringwidth(font, "0"); | |
| fill(); | |
| updatesel(); | |
| + | |
| + p = stringsize(font, "0"); | |
| + if(p.x == 0 || p.y == 0) | |
| + return; | |
| + | |
| + ws.ws_row = Dy(r)/p.y; | |
| + ws.ws_col = Dx(r)/p.x; | |
| + ws.ws_xpixel = Dx(r); | |
| + ws.ws_ypixel = Dy(r); | |
| + if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col) | |
| + if(ioctl(rcfd[0], TIOCSWINSZ, &ws) < 0) | |
| + fprint(2, "ioctl: %r\n"); | |
| } | |
| void | |
| t@@ -422,6 +437,7 @@ void | |
| key(Rune r) | |
| { | |
| char buf[1]; | |
| + uint sig; | |
| if(r == 0) | |
| return; | |
| t@@ -472,12 +488,9 @@ key(Rune r) | |
| case 0x7F: /* DEL: send interrupt */ | |
| t.qh = t.q0 = t.q1 = t.nr; | |
| show(t.q0); | |
| - buf[0] = 0x7f; | |
| - if(write(rcfd[1], buf, 1) < 0) | |
| - exits(0); | |
| - /* get rc to print prompt */ | |
| -// r = '\n'; | |
| -// paste(&r, 1, 1); | |
| + sig = 2; /* SIGINT */ | |
| + if(ioctl(rcfd[0], TIOCSIG, &sig) < 0) | |
| + fprint(2, "sending interrupt: %r\n"); | |
| break; | |
| case 0x08: /* ^H: erase character */ | |
| case 0x15: /* ^U: erase line */ | |
| t@@ -543,7 +556,10 @@ consready(void) | |
| for(i=t.qh; i<t.nr; i++){ | |
| c = t.r[i]; | |
| if(c=='\n' || c=='\004') | |
| +{ | |
| +fprint(2, "ready %d\n", c); | |
| return 1; | |
| +} | |
| } | |
| return 0; | |
| } | |
| t@@ -561,6 +577,7 @@ consread(void) | |
| n = sizeof(buf); | |
| p = buf; | |
| + c = 0; | |
| while(n >= UTFmax && (t.qh<t.nr || t.nraw > 0)) { | |
| if(t.qh == t.nr){ | |
| width = runetochar(p, &t.raw[0]); | |
| t@@ -571,18 +588,17 @@ consread(void) | |
| c = *p; | |
| p += width; | |
| n -= width; | |
| - if(!rawon && (c == '\n' || c == '\004')) { | |
| - if(c == '\004') | |
| - p--; | |
| + if(!rawon && (c == '\n' || c == '\004')) | |
| break; | |
| - } | |
| } | |
| - if(n < UTFmax && t.qh<t.nr && t.r[t.qh]=='\004') | |
| - t.qh++; | |
| - /* put in control-d when doing a zero length write */ | |
| - if(p == buf) | |
| - *p++ = '\004'; | |
| - if(write(rcfd[1], buf, p-buf) < 0) | |
| + /* take out control-d when not doing a zero length write */ | |
| + n = p-buf; | |
| + if(n > 1 && c == '\004') | |
| +{ | |
| +fprint(2, "remove 004\n"); | |
| + n--; | |
| +} | |
| + if(write(rcfd[1], buf, n) < 0) | |
| exits(0); | |
| /* mallocstats(); */ | |
| } | |
| t@@ -1138,19 +1154,32 @@ rcstart(int fd[2]) | |
| argv[1] = "-i"; | |
| argv[2] = 0; | |
| - getpts(fd, slave); | |
| + /* | |
| + * fd0 is slave (tty), fd1 is master (pty) | |
| + */ | |
| + fd[0] = fd[1] = -1; | |
| + if(getpts(fd, slave) < 0) | |
| + fprint(2, "getpts: %r\n"); | |
| + | |
| switch(pid = fork()) { | |
| case 0: | |
| putenv("TERM=9term"); | |
| close(fd[1]); | |
| setsid(); | |
| + // tcsetpgrp(0, pid); | |
| sfd = open(slave, ORDWR); | |
| + fprint(2, "slave %s\n", slave); | |
| + if(sfd < 0) | |
| + fprint(2, "open %s: %r\n", slave); | |
| + if(ioctl(sfd, TIOCSCTTY, 0) < 0) | |
| + fprint(2, "ioctl TIOCSCTTY: %r\n"); | |
| // ioctl(sfd, I_PUSH, "ptem"); | |
| // ioctl(sfd, I_PUSH, "ldterm"); | |
| dup(sfd, 0); | |
| dup(sfd, 1); | |
| dup(sfd, 2); | |
| execvp(argv[0], argv); | |
| + _exits("oops"); | |
| break; | |
| case -1: | |
| fatal("proc failed: %r"); | |
| diff --git a/src/cmd/9term/FreeBSD.c b/src/cmd/9term/FreeBSD.c | |
| t@@ -13,6 +13,5 @@ getchildwd(int pid, char *wdir, int bufn) | |
| int | |
| getpts(int fd[], char *slave) | |
| { | |
| - openpty(&fd[1], &fd[0], slave, 0, 0); | |
| - return 0; | |
| + return openpty(&fd[1], &fd[0], slave, 0, 0); | |
| } | |
| diff --git a/src/cmd/rc/plan9ish.c b/src/cmd/rc/plan9ish.c | |
| t@@ -392,10 +392,12 @@ void | |
| notifyf(void *unused0, char *s) | |
| { | |
| int i; | |
| - for(i=0;syssigname[i];i++) if(strncmp(s, syssigname[i], strlen(syssign… | |
| - if(strncmp(s, "sys: ", 5)!=0) interrupted=1; | |
| - goto Out; | |
| - } | |
| + for(i=0;syssigname[i];i++) | |
| + if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){ | |
| + if(strncmp(s, "sys: ", 5)!=0) interrupted=1; | |
| + goto Out; | |
| + } | |
| + | |
| pfmt(err, "rc: note: %s\n", s); | |
| noted(NDFLT); | |
| return; | |
| t@@ -423,7 +425,11 @@ long Write(int fd, char *buf, long cnt) | |
| } | |
| long Read(int fd, char *buf, long cnt) | |
| { | |
| - return read(fd, buf, cnt); | |
| + int i; | |
| + | |
| + i = read(fd, buf, cnt); | |
| + if(ntrap) dotrap(); | |
| + return i; | |
| } | |
| long Seek(int fd, long cnt, long whence) | |
| { | |
| diff --git a/src/lib9/_p9dir.c b/src/lib9/_p9dir.c | |
| t@@ -10,6 +10,36 @@ | |
| #if defined(__FreeBSD__) | |
| #include <sys/disklabel.h> | |
| +static int diskdev[] = { | |
| + 151, /* aacd */ | |
| + 116, /* ad */ | |
| + 157, /* ar */ | |
| + 118, /* afd */ | |
| + 133, /* amrd */ | |
| + 13, /* da */ | |
| + 102, /* fla */ | |
| + 109, /* idad */ | |
| + 95, /* md */ | |
| + 131, /* mlxd */ | |
| + 168, /* pst */ | |
| + 147, /* twed */ | |
| + 43, /* vn */ | |
| + 3, /* wd */ | |
| + 87, /* wfd */ | |
| +}; | |
| +static int | |
| +isdisk(struct stat *st) | |
| +{ | |
| + int i, dev; | |
| + | |
| + if(!S_ISCHR(st->st_mode)) | |
| + return 0; | |
| + dev = major(st->st_rdev); | |
| + for(i=0; i<nelem(diskdev); i++) | |
| + if(diskdev[i] == dev) | |
| + return 1; | |
| + return 0; | |
| +} | |
| #define _HAVEDISKLABEL | |
| #endif | |
| t@@ -108,7 +138,7 @@ _p9dir(struct stat *st, char *name, Dir *d, char **str, ch… | |
| /* fetch real size for disks */ | |
| #ifdef _HAVEDISKLABEL | |
| - if(S_ISCHR(st->st_mode)){ | |
| + if(isdisk(st)){ | |
| int fd, n; | |
| struct disklabel lab; | |
| diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c | |
| t@@ -10,7 +10,6 @@ extern int _p9dir(struct stat*, char*, Dir*, char**, char*); | |
| static int | |
| mygetdents(int fd, struct dirent *buf, int n) | |
| { | |
| - ssize_t nn; | |
| off_t off; | |
| off = p9seek(fd, 0, 1); | |
| t@@ -23,14 +22,8 @@ mygetdents(int fd, struct dirent *buf, int n) | |
| static int | |
| mygetdents(int fd, struct dirent *buf, int n) | |
| { | |
| - ssize_t nn; | |
| long off; | |
| - | |
| - off = p9seek(fd, 0, 1); | |
| - nn = getdirentries(fd, (void*)buf, n, &off); | |
| - if(nn > 0) | |
| - p9seek(fd, off, 0); | |
| - return nn; | |
| + return getdirentries(fd, (void*)buf, n, &off); | |
| } | |
| #elif defined(__sun__) | |
| static int | |
| t@@ -38,7 +31,7 @@ mygetdents(int fd, struct dirent *buf, int n) | |
| { | |
| return getdents(fd, (void*)buf, n); | |
| } | |
| -#endif | |
| +#endif | |
| static int | |
| countde(char *p, int n) | |
| diff --git a/src/lib9/notify.c b/src/lib9/notify.c | |
| t@@ -13,7 +13,7 @@ static int sigs[] = { | |
| SIGQUIT, | |
| SIGILL, | |
| SIGTRAP, | |
| - SIGABRT, | |
| +/* SIGABRT, */ | |
| #ifdef SIGEMT | |
| SIGEMT, | |
| #endif | |
| t@@ -63,16 +63,17 @@ int | |
| notify(void (*f)(void*, char*)) | |
| { | |
| int i; | |
| - void (*sf)(int); | |
| + struct sigaction sa; | |
| + memset(&sa, 0, sizeof sa); | |
| if(f == nil) | |
| - sf = SIG_DFL; | |
| + sa.sa_handler = SIG_DFL; | |
| else{ | |
| notifyf = f; | |
| - sf = notifysigf; | |
| + sa.sa_handler = notifysigf; | |
| } | |
| for(i=0; i<nelem(sigs); i++) | |
| - signal(sigs[i], sf); | |
| + sigaction(sigs[i], &sa, 0); | |
| return 0; | |
| } | |
| diff --git a/src/libbio/bcat.c b/src/libbio/bcat.c | |
| t@@ -22,8 +22,12 @@ main(int argc, char **argv) | |
| { | |
| int i; | |
| Biobuf b, *bp; | |
| + Fmt fmt; | |
| Binit(&bout, 1, O_WRONLY); | |
| + Bfmtinit(&fmt, &bout); | |
| + fmtprint(&fmt, "hello, world\n"); | |
| + Bfmtflush(&fmt); | |
| if(argc == 1){ | |
| Binit(&b, 0, O_RDONLY); | |
| diff --git a/src/libbio/bprint.c b/src/libbio/bprint.c | |
| t@@ -4,25 +4,17 @@ | |
| int | |
| Bprint(Biobuf *bp, char *fmt, ...) | |
| { | |
| - va_list ap; | |
| - char *ip, *ep, *out; | |
| + va_list args; | |
| + Fmt f; | |
| int n; | |
| - ep = (char*)bp->ebuf; | |
| - ip = ep + bp->ocount; | |
| - va_start(ap, fmt); | |
| - out = vseprint(ip, ep, fmt, ap); | |
| - va_end(ap); | |
| - if(out == 0 || out >= ep-5) { | |
| - Bflush(bp); | |
| - ip = ep + bp->ocount; | |
| - va_start(ap, fmt); | |
| - out = vseprint(ip, ep, fmt, ap); | |
| - va_end(ap); | |
| - if(out >= ep-5) | |
| - return Beof; | |
| - } | |
| - n = out-ip; | |
| - bp->ocount += n; | |
| + if(Bfmtinit(&f, bp) < 0) | |
| + return -1; | |
| + va_start(args, fmt); | |
| + f.args = args; | |
| + n = dofmt(&f, fmt); | |
| + va_end(args); | |
| + if(n > 0 && Bfmtflush(&f) < 0) | |
| + return -1; | |
| return n; | |
| } | |
| diff --git a/src/libbio/mkfile b/src/libbio/mkfile | |
| t@@ -7,6 +7,7 @@ OFILES=\ | |
| bbuffered.$O\ | |
| bfildes.$O\ | |
| bflush.$O\ | |
| + bfmt.$O\ | |
| bgetc.$O\ | |
| bgetd.$O\ | |
| binit.$O\ | |
| t@@ -26,6 +27,6 @@ HFILES=\ | |
| <$PLAN9/src/mksyslib | |
| -bcat: bcat.$O $LIB | |
| - $CC -o bcat bcat.$O -L$PLAN9/lib -lbio -lfmt -lutf | |
| +bcat: bcat.$O $PLAN9/lib/$LIB | |
| + $LD -o bcat bcat.$O -lbio -lfmt -lutf | |