diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-23 00:30:12 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-23 00:30:12 +0000 |
| commit | 6e425a9de8c003b5a733621a6b6730ec3cc902b8 (patch) | |
| tree | 314123bcab78ff295f38f85f31dc141e5fe22d15 /emu/Plan9 | |
| parent | 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (diff) | |
20061220
Diffstat (limited to 'emu/Plan9')
| -rw-r--r-- | emu/Plan9/cmd.c | 29 | ||||
| -rw-r--r-- | emu/Plan9/win.c | 69 |
2 files changed, 43 insertions, 55 deletions
diff --git a/emu/Plan9/cmd.c b/emu/Plan9/cmd.c index d3822f50..8d311f2a 100644 --- a/emu/Plan9/cmd.c +++ b/emu/Plan9/cmd.c @@ -12,7 +12,7 @@ extern void vstack(void*); typedef struct Targ Targ; struct Targ { - int fd[2]; + int fd[3]; /* standard input, output and error */ int wfd; int* spin; char** args; @@ -41,18 +41,21 @@ exectramp(Targ *t) nfd = MAXNFD; /* TO DO: should read from /fd */ for(i = 0; i < nfd; i++) - if(i != fd[0] && i != fd[1] && i != t->wfd) + if(i != fd[0] && i != fd[1] && i != fd[2] && i != t->wfd) close(i); if(fd[0] != 0){ dup(fd[0], 0); close(fd[0]); } - if(fd[0] != 1){ + if(fd[1] != 1){ dup(fd[1], 1); close(fd[1]); } - dup(1, 2); + if(fd[2] != 2){ + dup(fd[2], 2); + close(fd[2]); + } if(t->dir != nil && chdir(t->dir) < 0){ if(t->wfd > 0) @@ -79,10 +82,10 @@ exectramp(Targ *t) } void* -oscmd(char **args, int nice, char *dir, int *rfd, int *sfd) +oscmd(char **args, int nice, char *dir, int *fd) { Targ *t; - int spin, *spinptr, fd0[2], fd1[2], wfd[2], n; + int spin, *spinptr, fd0[2], fd1[2], fd2[2], wfd[2], n; Dir *d; up->genbuf[0] = 0; @@ -94,6 +97,7 @@ oscmd(char **args, int nice, char *dir, int *rfd, int *sfd) t->nice = nice; fd0[0] = fd0[1] = -1; fd1[0] = fd1[1] = -1; + fd2[0] = fd2[1] = -1; wfd[0] = wfd[1] = -1; if(dir != nil){ d = dirstat(dir); @@ -101,7 +105,7 @@ oscmd(char **args, int nice, char *dir, int *rfd, int *sfd) goto Error; free(d); } - if(pipe(fd0) < 0 || pipe(fd1) < 0 || pipe(wfd) < 0) + if(pipe(fd0) < 0 || pipe(fd1) < 0 || pipe(fd2) < 0 || pipe(wfd) < 0) goto Error; spinptr = &spin; @@ -109,6 +113,7 @@ oscmd(char **args, int nice, char *dir, int *rfd, int *sfd) t->fd[0] = fd0[0]; t->fd[1] = fd1[1]; + t->fd[2] = fd2[1]; t->wfd = wfd[1]; t->spin = spinptr; switch(rfork(RFPROC|RFMEM|RFREND|RFNOTEG|RFFDG|RFNAMEG|RFENVG)) { @@ -128,20 +133,24 @@ oscmd(char **args, int nice, char *dir, int *rfd, int *sfd) close(fd0[0]); close(fd1[1]); + close(fd2[1]); close(wfd[1]); + n = read(wfd[0], up->genbuf, sizeof(up->genbuf)-1); close(wfd[0]); if(n > 0){ close(fd0[1]); close(fd1[0]); + close(fd2[0]); up->genbuf[n] = 0; errstr(up->genbuf, sizeof(up->genbuf)); free(t); return nil; } - *sfd = fd0[1]; - *rfd = fd1[0]; + fd[0] = fd0[1]; + fd[1] = fd1[0]; + fd[2] = fd2[0]; return t; Error: @@ -150,6 +159,8 @@ Error: close(fd0[1]); close(fd1[0]); close(fd1[1]); + close(fd2[0]); + close(fd2[1]); close(wfd[0]); close(wfd[1]); free(t); diff --git a/emu/Plan9/win.c b/emu/Plan9/win.c index d86eea15..2f280853 100644 --- a/emu/Plan9/win.c +++ b/emu/Plan9/win.c @@ -16,14 +16,14 @@ enum extern Memimage *screenimage; -ulong* attachwindow(Rectangle*, ulong*, int*, int*); +static ulong* attachwindow(Rectangle*, ulong*, int*, int*); static void plan9readmouse(void*); static void plan9readkeybd(void*); static int mapspecials(char *s1, char *s2, int *n); -int pixels = 1; int usenewwin = 1; +int kbdiscons; static int truedepth; static int datafd; @@ -84,31 +84,35 @@ attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen) fprint(2, "attachscreen: can't mount window manager: %r\n"); return nil; } + if(bind("/mnt/wsys", "/dev", MBEFORE) < 0){ + fprint(2, "attachscreen: can't bind /mnt/wsys before /dev: %r\n"); + return nil; + } } - cursfd = open("/mnt/wsys/cursor", OWRITE); + cursfd = open("/dev/cursor", OWRITE); if(cursfd < 0) { fprint(2, "attachscreen: open cursor: %r\n"); return nil; } /* Set up graphics window console (chars->gkbdq) */ - keybdfd = open("/mnt/wsys/cons", OREAD); + keybdfd = open("/dev/cons", OREAD); if(keybdfd < 0) { fprint(2, "attachscreen: open keyboard: %r\n"); return nil; } - mousefd = open("/mnt/wsys/mouse", ORDWR); + mousefd = open("/dev/mouse", ORDWR); if(mousefd < 0){ fprint(2, "attachscreen: can't open mouse: %r\n"); return nil; } - if(usenewwin){ - fd = open("/mnt/wsys/consctl", OWRITE); + if(usenewwin || 1){ + fd = open("/dev/consctl", OWRITE); if(fd < 0) - fprint(2, "attachscreen: open /mnt/wsys/consctl: %r\n"); + fprint(2, "attachscreen: open /dev/consctl: %r\n"); if(write(fd, "rawon", 5) != 5) - fprint(2, "attachscreen: write /mnt/wsys/consctl: %r\n"); + fprint(2, "attachscreen: write /dev/consctl: %r\n"); } /* Set up graphics files */ @@ -148,11 +152,11 @@ attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen) mousepid = kproc("readmouse", plan9readmouse, nil, 0); keybdpid = kproc("readkbd", plan9readkeybd, nil, 0); - bind("/mnt/wsys", "/dev", MBEFORE); fd = open("/dev/label", OWRITE); - if (fd >= 0) { - write(fd, "inferno", 7); + if(fd >= 0){ + snprint(buf, sizeof(buf), "inferno %d", getpid()); + write(fd, buf, strlen(buf)); close(fd); } @@ -160,35 +164,7 @@ attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen) return (uchar*)data; } -static int -depthof(char *s) -{ - char *es; - int n, c, d; - - es = s+12; - while(s<es && *s==' ') - s++; - if(s == es) - return -1; - if('0'<=*s && *s<='9'){ - truedepth = 1<<atoi(s); - return truedepth; - } - - d = 0; - while(s<es && *s!=' '){ - c = *s++; /* skip letter */ - n = strtoul(s, &s, 10); - d += n; - if(c != 'r' && c != 'g' && c != 'b' && c != 'k' && c != 'm') - return -1; - } - truedepth = d; - return d; -} - -ulong* +static ulong* attachwindow(Rectangle *r, ulong *chan, int *d, int *width) { int n, fd, nb; @@ -231,7 +207,8 @@ attachwindow(Rectangle *r, ulong *chan, int *d, int *width) return nil; } imagechan = strtochan(buf+2*12); - if(depthof(buf+2*12) < 0){ + truedepth = chantodepth(imagechan); + if(truedepth == 0){ fprint(2, "attachwindow: cannot handle window depth specifier %.12s\n", buf+2*12); return nil; } @@ -272,7 +249,7 @@ attachwindow(Rectangle *r, ulong *chan, int *d, int *width) return data; } -int +static int plan9loadimage(Rectangle r, uchar *data, int ndata) { long dy; @@ -396,7 +373,7 @@ drawcursor(Drawcursor *c) write(cursfd, curs, sizeof curs); } -int +static int checkmouse(char *buf, int n) { int x, y, tick, b; @@ -453,12 +430,12 @@ plan9readmouse(void *v) } static void -plan9readkeybd(void *v) +plan9readkeybd(void*) { int n, partial; char buf[32]; char dbuf[32 * 3]; /* overestimate but safe */ - USED(v); + partial = 0; for(;;){ n = read(keybdfd, buf + partial, sizeof(buf) - partial); |
