From 5ac6088b96c67e9799bc8009d46b72819521da87 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Mon, 6 May 2013 19:35:03 -0400 Subject: [PATCH 01/42] access: unused variable --- sys/src/ape/lib/ap/plan9/access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/ape/lib/ap/plan9/access.c b/sys/src/ape/lib/ap/plan9/access.c index 527af63ee..971accb17 100644 --- a/sys/src/ape/lib/ap/plan9/access.c +++ b/sys/src/ape/lib/ap/plan9/access.c @@ -11,7 +11,7 @@ int access(const char *name, int mode) { - int fd, n; + int fd; Dir *db; struct stat st; static char omode[] = { From 517c0feacaede7dcba7dea95aef49d78c94e8c7c Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Mon, 6 May 2013 20:24:19 -0400 Subject: [PATCH 02/42] ape: fix uninitialized variable bug in getfields() --- sys/src/ape/lib/ap/plan9/9iounit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/src/ape/lib/ap/plan9/9iounit.c b/sys/src/ape/lib/ap/plan9/9iounit.c index 7117a9fe0..cf6a497e3 100644 --- a/sys/src/ape/lib/ap/plan9/9iounit.c +++ b/sys/src/ape/lib/ap/plan9/9iounit.c @@ -14,7 +14,7 @@ static int getfields(char *str, char **args, int max, int mflag) { char r; - int nr, intok, narg; + int intok, narg; if(max <= 0) return 0; @@ -24,8 +24,8 @@ getfields(char *str, char **args, int max, int mflag) if(!mflag) narg++; intok = 0; - for(;;) { - r = *str++; + for(;; str++) { + r = *str; if(r == 0) break; if(r == ' ' || r == '\t'){ @@ -33,7 +33,7 @@ getfields(char *str, char **args, int max, int mflag) break; *str = 0; intok = 0; - args[narg] = str + nr; + args[narg] = str + 1; if(!mflag) narg++; } else { From 36287edc888c537b9ee37ae8530bd9c5b35227a1 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Mon, 6 May 2013 20:51:18 -0400 Subject: [PATCH 03/42] ape: remove unused variables --- sys/src/ape/lib/ap/plan9/_buf.c | 2 +- sys/src/ape/lib/ap/plan9/_envsetup.c | 3 +-- sys/src/ape/lib/ap/plan9/_exit.c | 1 - sys/src/ape/lib/ap/plan9/_fdinfo.c | 2 -- sys/src/ape/lib/ap/plan9/ctime.c | 2 +- sys/src/ape/lib/ap/plan9/dup.c | 2 -- sys/src/ape/lib/ap/plan9/isatty.c | 1 - sys/src/ape/lib/ap/plan9/open.c | 1 - sys/src/ape/lib/ap/plan9/opendir.c | 2 +- sys/src/ape/lib/ap/plan9/rename.c | 1 - 10 files changed, 4 insertions(+), 13 deletions(-) diff --git a/sys/src/ape/lib/ap/plan9/_buf.c b/sys/src/ape/lib/ap/plan9/_buf.c index 6a375672b..9836886d7 100644 --- a/sys/src/ape/lib/ap/plan9/_buf.c +++ b/sys/src/ape/lib/ap/plan9/_buf.c @@ -49,7 +49,7 @@ static int copynotehandler(void *, char *); int _startbuf(int fd) { - int i, pid, sid; + int i, pid; Fdinfo *f; Muxbuf *b; diff --git a/sys/src/ape/lib/ap/plan9/_envsetup.c b/sys/src/ape/lib/ap/plan9/_envsetup.c index 083a75d17..6d76da87e 100644 --- a/sys/src/ape/lib/ap/plan9/_envsetup.c +++ b/sys/src/ape/lib/ap/plan9/_envsetup.c @@ -32,7 +32,6 @@ void _envsetup(void) { int dfd; - struct dirent *de; int n, nd, m, i, j, f; int psize, cnt; int nohandle; @@ -107,7 +106,7 @@ done: static void sigsetup(char *s, char *se) { - int i, sig; + int sig; char *e; while(s < se){ diff --git a/sys/src/ape/lib/ap/plan9/_exit.c b/sys/src/ape/lib/ap/plan9/_exit.c index e3886ff18..51a19f96b 100644 --- a/sys/src/ape/lib/ap/plan9/_exit.c +++ b/sys/src/ape/lib/ap/plan9/_exit.c @@ -19,7 +19,6 @@ _exit(int status) void _finish(int status, char *term) { - int i, nalive; char *cp; if(_finishing) diff --git a/sys/src/ape/lib/ap/plan9/_fdinfo.c b/sys/src/ape/lib/ap/plan9/_fdinfo.c index 7a3415c93..0bfb8299a 100644 --- a/sys/src/ape/lib/ap/plan9/_fdinfo.c +++ b/sys/src/ape/lib/ap/plan9/_fdinfo.c @@ -97,11 +97,9 @@ readprocfdinit(void) static void sfdinit(int usedproc, char *s, char *se) { - int i; Fdinfo *fi; unsigned long fd, fl, ofl; char *e; - struct stat sbuf; while(s < se){ fd = strtoul(s, &e, 10); diff --git a/sys/src/ape/lib/ap/plan9/ctime.c b/sys/src/ape/lib/ap/plan9/ctime.c index ce56c2d0f..e736140cf 100644 --- a/sys/src/ape/lib/ap/plan9/ctime.c +++ b/sys/src/ape/lib/ap/plan9/ctime.c @@ -148,7 +148,7 @@ localtime_r(const time_t *timp, struct tm *result) struct tm *ct; time_t t, tim; long *p; - int i, dlflag; + int dlflag; tim = *timp; if(tz.stname[0] == 0) diff --git a/sys/src/ape/lib/ap/plan9/dup.c b/sys/src/ape/lib/ap/plan9/dup.c index 37883be52..50842524f 100644 --- a/sys/src/ape/lib/ap/plan9/dup.c +++ b/sys/src/ape/lib/ap/plan9/dup.c @@ -11,8 +11,6 @@ dup(int oldd) int dup2(int oldd, int newd) { - int n; - if(newd < 0 || newd >= OPEN_MAX){ errno = EBADF; return -1; diff --git a/sys/src/ape/lib/ap/plan9/isatty.c b/sys/src/ape/lib/ap/plan9/isatty.c index e04cd891d..b0ccb54bf 100644 --- a/sys/src/ape/lib/ap/plan9/isatty.c +++ b/sys/src/ape/lib/ap/plan9/isatty.c @@ -8,7 +8,6 @@ int _isatty(int fd) { - int t; char buf[64]; if(_FD2PATH(fd, buf, sizeof buf) < 0) diff --git a/sys/src/ape/lib/ap/plan9/open.c b/sys/src/ape/lib/ap/plan9/open.c index bc088f197..fa45ea098 100644 --- a/sys/src/ape/lib/ap/plan9/open.c +++ b/sys/src/ape/lib/ap/plan9/open.c @@ -18,7 +18,6 @@ open(const char *path, int flags, ...) int mode; Fdinfo *fi; va_list va; - struct stat sbuf; f = flags&O_ACCMODE; if(flags&O_CREAT){ diff --git a/sys/src/ape/lib/ap/plan9/opendir.c b/sys/src/ape/lib/ap/plan9/opendir.c index ebc22dbf6..a007ba608 100644 --- a/sys/src/ape/lib/ap/plan9/opendir.c +++ b/sys/src/ape/lib/ap/plan9/opendir.c @@ -84,7 +84,7 @@ rewinddir(DIR *d) struct dirent * readdir(DIR *d) { - int i, n; + int i; struct dirent *dr; Dir *dirs; diff --git a/sys/src/ape/lib/ap/plan9/rename.c b/sys/src/ape/lib/ap/plan9/rename.c index 73d051b11..182f49ce2 100644 --- a/sys/src/ape/lib/ap/plan9/rename.c +++ b/sys/src/ape/lib/ap/plan9/rename.c @@ -13,7 +13,6 @@ rename(const char *from, const char *to) int n, i; char *f, *t; Dir *d, nd; - long mode; if(access(to, 0) >= 0){ if(_REMOVE(to) < 0){ From 6a2b5055f5c2827d66c18f2c6e5aed284956f980 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Wed, 8 May 2013 17:47:48 -0400 Subject: [PATCH 04/42] samterm: move cursor to next tabstop or non-space character before backspacing in spaces mode. this makes it less annoying to backspace (it's more like tabs). --- sys/src/cmd/samterm/main.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sys/src/cmd/samterm/main.c b/sys/src/cmd/samterm/main.c index 6ee72c94a..c20091acb 100644 --- a/sys/src/cmd/samterm/main.c +++ b/sys/src/cmd/samterm/main.c @@ -359,19 +359,29 @@ getcol(Rasp *r, long p) return col; } +int +sptotab(Rasp *r, long p) +{ + int i, col, n; + + col = getcol(r, p); + if((n = maxtab - col % maxtab) == maxtab) + n = 0; + for(i = 0; p < r->nrunes && raspc(r, p)==' ' && i=o && raspc(r, p-1)==' ' && i=o && raspc(r, p-1)==' ' && i=o? p : o; } @@ -622,6 +632,8 @@ type(Flayer *l, int res) /* what a bloody mess this is */ switch(c){ case '\b': case 0x7F: /* del */ + if(spacesindent) + a += sptotab(&t->rasp, a); l->p0 = del(&t->rasp, l->origin, a); break; case 0x15: /* ctrl-u */ From c24a442ae2e86da88df506cf8cafcf59eaf2f770 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Wed, 8 May 2013 20:34:50 -0400 Subject: [PATCH 05/42] samterm: revert previous changes. --- sys/src/cmd/samterm/main.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/sys/src/cmd/samterm/main.c b/sys/src/cmd/samterm/main.c index c20091acb..6ee72c94a 100644 --- a/sys/src/cmd/samterm/main.c +++ b/sys/src/cmd/samterm/main.c @@ -359,29 +359,19 @@ getcol(Rasp *r, long p) return col; } -int -sptotab(Rasp *r, long p) -{ - int i, col, n; - - col = getcol(r, p); - if((n = maxtab - col % maxtab) == maxtab) - n = 0; - for(i = 0; p < r->nrunes && raspc(r, p)==' ' && i=o && raspc(r, p-1)==' ' && i=o && raspc(r, p-1)==' ' && i=o? p : o; } @@ -632,8 +622,6 @@ type(Flayer *l, int res) /* what a bloody mess this is */ switch(c){ case '\b': case 0x7F: /* del */ - if(spacesindent) - a += sptotab(&t->rasp, a); l->p0 = del(&t->rasp, l->origin, a); break; case 0x15: /* ctrl-u */ From 03cf6cae57040e7cbb4627858789bf93b0b686bc Mon Sep 17 00:00:00 2001 From: khm Date: Wed, 8 May 2013 21:07:02 -0400 Subject: [PATCH 06/42] fortunes: all the world's a social vax cloud --- sys/games/lib/fortunes | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/games/lib/fortunes b/sys/games/lib/fortunes index 15e36dcde..e2bc9e204 100644 --- a/sys/games/lib/fortunes +++ b/sys/games/lib/fortunes @@ -4843,3 +4843,4 @@ BurnZeZ → I'm constantly dealing with scrolling text The development effort for 5ESS required 5000 employees, producing 100 million lines of code, with 100 million lines of header and makefiles. Don't forget the colon when referring to keyboards or printers. A Font For Supporters Of Marriage Equality +< mveety> im on facebook on my vax right now From 9bb703e2cf87d220caf709ecde7935b239ab7cc8 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 10 May 2013 01:24:11 +0200 Subject: [PATCH 07/42] srv: be nice, close the previously duped pipe filedescriptor --- sys/src/cmd/srv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/src/cmd/srv.c b/sys/src/cmd/srv.c index f4186f56c..9dd328e35 100644 --- a/sys/src/cmd/srv.c +++ b/sys/src/cmd/srv.c @@ -51,6 +51,7 @@ connectcmd(char *cmd) rfork(RFNOTEG); dup(p[0], 0); dup(p[0], 1); + close(p[0]); close(p[1]); execl("/bin/rc", "rc", "-c", cmd, nil); fprint(2, "exec failed: %r\n"); From 9af0b2c68377c321475ec0c2e5a0af85b4965709 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Thu, 9 May 2013 20:48:23 -0400 Subject: [PATCH 08/42] awk: proctab.c is always regenerated from maketab, so it is unnecessary to keep it --- sys/src/cmd/awk/mkfile | 2 +- sys/src/cmd/awk/proctab.c | 205 -------------------------------------- 2 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 sys/src/cmd/awk/proctab.c diff --git a/sys/src/cmd/awk/mkfile b/sys/src/cmd/awk/mkfile index 1314ca560..35ee78d7c 100644 --- a/sys/src/cmd/awk/mkfile +++ b/sys/src/cmd/awk/mkfile @@ -41,7 +41,7 @@ clean:V: rm -f *.[$OS] [$OS].out [$OS].maketab y.tab.? y.debug y.output $TARG nuke:V: - rm -f *.[$OS] [$OS].out [$OS].maketab y.tab.? y.debug y.output awkgram.c $TARG + rm -f *.[$OS] [$OS].out [$OS].maketab y.tab.? y.debug y.output awkgram.c proctab.c $TARG proctab.c: $cpuobjtype.maketab ./$cpuobjtype.maketab >proctab.c diff --git a/sys/src/cmd/awk/proctab.c b/sys/src/cmd/awk/proctab.c deleted file mode 100644 index 7b19d2383..000000000 --- a/sys/src/cmd/awk/proctab.c +++ /dev/null @@ -1,205 +0,0 @@ -#include -#include "awk.h" -#include "y.tab.h" - -static char *printname[92] = { - (char *) "FIRSTTOKEN", /* 57346 */ - (char *) "PROGRAM", /* 57347 */ - (char *) "PASTAT", /* 57348 */ - (char *) "PASTAT2", /* 57349 */ - (char *) "XBEGIN", /* 57350 */ - (char *) "XEND", /* 57351 */ - (char *) "NL", /* 57352 */ - (char *) "ARRAY", /* 57353 */ - (char *) "MATCH", /* 57354 */ - (char *) "NOTMATCH", /* 57355 */ - (char *) "MATCHOP", /* 57356 */ - (char *) "FINAL", /* 57357 */ - (char *) "DOT", /* 57358 */ - (char *) "ALL", /* 57359 */ - (char *) "CCL", /* 57360 */ - (char *) "NCCL", /* 57361 */ - (char *) "CHAR", /* 57362 */ - (char *) "OR", /* 57363 */ - (char *) "STAR", /* 57364 */ - (char *) "QUEST", /* 57365 */ - (char *) "PLUS", /* 57366 */ - (char *) "AND", /* 57367 */ - (char *) "BOR", /* 57368 */ - (char *) "APPEND", /* 57369 */ - (char *) "EQ", /* 57370 */ - (char *) "GE", /* 57371 */ - (char *) "GT", /* 57372 */ - (char *) "LE", /* 57373 */ - (char *) "LT", /* 57374 */ - (char *) "NE", /* 57375 */ - (char *) "IN", /* 57376 */ - (char *) "ARG", /* 57377 */ - (char *) "BLTIN", /* 57378 */ - (char *) "BREAK", /* 57379 */ - (char *) "CLOSE", /* 57380 */ - (char *) "CONTINUE", /* 57381 */ - (char *) "DELETE", /* 57382 */ - (char *) "DO", /* 57383 */ - (char *) "EXIT", /* 57384 */ - (char *) "FOR", /* 57385 */ - (char *) "FUNC", /* 57386 */ - (char *) "SUB", /* 57387 */ - (char *) "GSUB", /* 57388 */ - (char *) "IF", /* 57389 */ - (char *) "INDEX", /* 57390 */ - (char *) "LSUBSTR", /* 57391 */ - (char *) "MATCHFCN", /* 57392 */ - (char *) "NEXT", /* 57393 */ - (char *) "NEXTFILE", /* 57394 */ - (char *) "ADD", /* 57395 */ - (char *) "MINUS", /* 57396 */ - (char *) "MULT", /* 57397 */ - (char *) "DIVIDE", /* 57398 */ - (char *) "MOD", /* 57399 */ - (char *) "ASSIGN", /* 57400 */ - (char *) "ASGNOP", /* 57401 */ - (char *) "ADDEQ", /* 57402 */ - (char *) "SUBEQ", /* 57403 */ - (char *) "MULTEQ", /* 57404 */ - (char *) "DIVEQ", /* 57405 */ - (char *) "MODEQ", /* 57406 */ - (char *) "POWEQ", /* 57407 */ - (char *) "PRINT", /* 57408 */ - (char *) "PRINTF", /* 57409 */ - (char *) "SPRINTF", /* 57410 */ - (char *) "ELSE", /* 57411 */ - (char *) "INTEST", /* 57412 */ - (char *) "CONDEXPR", /* 57413 */ - (char *) "POSTINCR", /* 57414 */ - (char *) "PREINCR", /* 57415 */ - (char *) "POSTDECR", /* 57416 */ - (char *) "PREDECR", /* 57417 */ - (char *) "VAR", /* 57418 */ - (char *) "IVAR", /* 57419 */ - (char *) "VARNF", /* 57420 */ - (char *) "CALL", /* 57421 */ - (char *) "NUMBER", /* 57422 */ - (char *) "STRING", /* 57423 */ - (char *) "REGEXPR", /* 57424 */ - (char *) "GETLINE", /* 57425 */ - (char *) "RETURN", /* 57426 */ - (char *) "SPLIT", /* 57427 */ - (char *) "SUBSTR", /* 57428 */ - (char *) "WHILE", /* 57429 */ - (char *) "CAT", /* 57430 */ - (char *) "NOT", /* 57431 */ - (char *) "UMINUS", /* 57432 */ - (char *) "POWER", /* 57433 */ - (char *) "DECR", /* 57434 */ - (char *) "INCR", /* 57435 */ - (char *) "INDIRECT", /* 57436 */ - (char *) "LASTTOKEN", /* 57437 */ -}; - - -Cell *(*proctab[92])(Node **, int) = { - nullproc, /* FIRSTTOKEN */ - program, /* PROGRAM */ - pastat, /* PASTAT */ - dopa2, /* PASTAT2 */ - nullproc, /* XBEGIN */ - nullproc, /* XEND */ - nullproc, /* NL */ - array, /* ARRAY */ - matchop, /* MATCH */ - matchop, /* NOTMATCH */ - nullproc, /* MATCHOP */ - nullproc, /* FINAL */ - nullproc, /* DOT */ - nullproc, /* ALL */ - nullproc, /* CCL */ - nullproc, /* NCCL */ - nullproc, /* CHAR */ - nullproc, /* OR */ - nullproc, /* STAR */ - nullproc, /* QUEST */ - nullproc, /* PLUS */ - boolop, /* AND */ - boolop, /* BOR */ - nullproc, /* APPEND */ - relop, /* EQ */ - relop, /* GE */ - relop, /* GT */ - relop, /* LE */ - relop, /* LT */ - relop, /* NE */ - instat, /* IN */ - arg, /* ARG */ - bltin, /* BLTIN */ - jump, /* BREAK */ - closefile, /* CLOSE */ - jump, /* CONTINUE */ - awkdelete, /* DELETE */ - dostat, /* DO */ - jump, /* EXIT */ - forstat, /* FOR */ - nullproc, /* FUNC */ - sub, /* SUB */ - gsub, /* GSUB */ - ifstat, /* IF */ - sindex, /* INDEX */ - nullproc, /* LSUBSTR */ - matchop, /* MATCHFCN */ - jump, /* NEXT */ - jump, /* NEXTFILE */ - arith, /* ADD */ - arith, /* MINUS */ - arith, /* MULT */ - arith, /* DIVIDE */ - arith, /* MOD */ - assign, /* ASSIGN */ - nullproc, /* ASGNOP */ - assign, /* ADDEQ */ - assign, /* SUBEQ */ - assign, /* MULTEQ */ - assign, /* DIVEQ */ - assign, /* MODEQ */ - assign, /* POWEQ */ - printstat, /* PRINT */ - awkprintf, /* PRINTF */ - awksprintf, /* SPRINTF */ - nullproc, /* ELSE */ - intest, /* INTEST */ - condexpr, /* CONDEXPR */ - incrdecr, /* POSTINCR */ - incrdecr, /* PREINCR */ - incrdecr, /* POSTDECR */ - incrdecr, /* PREDECR */ - nullproc, /* VAR */ - nullproc, /* IVAR */ - getnf, /* VARNF */ - call, /* CALL */ - nullproc, /* NUMBER */ - nullproc, /* STRING */ - nullproc, /* REGEXPR */ - getline, /* GETLINE */ - jump, /* RETURN */ - split, /* SPLIT */ - substr, /* SUBSTR */ - whilestat, /* WHILE */ - cat, /* CAT */ - boolop, /* NOT */ - arith, /* UMINUS */ - arith, /* POWER */ - nullproc, /* DECR */ - nullproc, /* INCR */ - indirect, /* INDIRECT */ - nullproc, /* LASTTOKEN */ -}; - -char *tokname(int n) -{ - static char buf[100]; - - if (n < FIRSTTOKEN || n > LASTTOKEN) { - sprintf(buf, "token %d", n); - return buf; - } - return printname[n-FIRSTTOKEN]; -} From 389d6a1054cbf6734499a81c7de2dbc8251fa65c Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 11 May 2013 18:34:40 +0200 Subject: [PATCH 09/42] ape: change types from unsigned long to void* for rendezvous() and segattach()/segbrk() (erik), use uniqueue rendezvous tags for _buf and listen --- sys/include/ape/lib9.h | 6 ++--- sys/src/ape/lib/9/rendezvous.c | 6 ++--- sys/src/ape/lib/9/segattach.c | 4 ++-- sys/src/ape/lib/9/segbrk.c | 4 ++-- sys/src/ape/lib/ap/mips/lock.c | 3 +-- sys/src/ape/lib/ap/plan9/_buf.c | 41 +++++++++++++++++++------------- sys/src/ape/lib/ap/plan9/qlock.c | 18 +++++++------- sys/src/ape/lib/ap/plan9/sys9.h | 6 ++--- sys/src/ape/lib/bsd/listen.c | 18 +++++++------- sys/src/ape/lib/draw/libc.h | 6 ++--- 10 files changed, 60 insertions(+), 52 deletions(-) diff --git a/sys/include/ape/lib9.h b/sys/include/ape/lib9.h index 84b7c3253..1d788ea04 100644 --- a/sys/include/ape/lib9.h +++ b/sys/include/ape/lib9.h @@ -64,12 +64,12 @@ extern int bind(char*, char*, int); extern int mount(int, int, char*, int, char*); extern int unmount(char*, char*); extern int rfork(int); -extern int segattach(int, char*, void*, unsigned long); -extern int segbrk(void*, void*); +extern void* segattach(int, char*, void*, unsigned long); +extern void* segbrk(void*, void*); extern int segdetach(void*); extern int segflush(void*, unsigned long); extern int segfree(void*, unsigned long); -extern unsigned long rendezvous(unsigned long, unsigned long); +extern void* rendezvous(void*, void*); extern unsigned long getfcr(void); extern unsigned long getfsr(void); extern void setfcr(unsigned long); diff --git a/sys/src/ape/lib/9/rendezvous.c b/sys/src/ape/lib/9/rendezvous.c index 0e184c2f6..ab788cd55 100644 --- a/sys/src/ape/lib/9/rendezvous.c +++ b/sys/src/ape/lib/9/rendezvous.c @@ -1,9 +1,9 @@ #include -extern unsigned long _RENDEZVOUS(unsigned long, unsigned long); +extern void* _RENDEZVOUS(void*, void*); -unsigned long -rendezvous(unsigned long tag, unsigned long value) +void* +rendezvous(void *tag, void *value) { return _RENDEZVOUS(tag, value); } diff --git a/sys/src/ape/lib/9/segattach.c b/sys/src/ape/lib/9/segattach.c index f99f4877d..98178550e 100644 --- a/sys/src/ape/lib/9/segattach.c +++ b/sys/src/ape/lib/9/segattach.c @@ -1,8 +1,8 @@ #include -extern int _SEGATTACH(int, char*, void*, unsigned long); +extern void* _SEGATTACH(int, char*, void*, unsigned long); -int +void* segattach(int attr, char *class, void *va, unsigned long len) { return _SEGATTACH(attr, class, va, len); diff --git a/sys/src/ape/lib/9/segbrk.c b/sys/src/ape/lib/9/segbrk.c index 9e8d10eae..2b664aced 100644 --- a/sys/src/ape/lib/9/segbrk.c +++ b/sys/src/ape/lib/9/segbrk.c @@ -1,8 +1,8 @@ #include -extern int _SEGBRK(void*, void*); +extern void* _SEGBRK(void*, void*); -int +void* segbrk(void *saddr, void *addr) { return _SEGBRK(saddr, addr); diff --git a/sys/src/ape/lib/ap/mips/lock.c b/sys/src/ape/lib/ap/mips/lock.c index f0ecbe22a..866d074e9 100644 --- a/sys/src/ape/lib/ap/mips/lock.c +++ b/sys/src/ape/lib/ap/mips/lock.c @@ -31,8 +31,7 @@ lockinit(void) arch = C_fcr0(); switch(arch) { case POWER: - n = _SEGATTACH(0, "lock", (void*)Lockaddr, Pagesize); - if(n < 0) { + if(_SEGATTACH(0, "lock", (void*)Lockaddr, Pagesize) == (void*)-1) { arch = MAGNUM; break; } diff --git a/sys/src/ape/lib/ap/plan9/_buf.c b/sys/src/ape/lib/ap/plan9/_buf.c index 9836886d7..906c2335d 100644 --- a/sys/src/ape/lib/ap/plan9/_buf.c +++ b/sys/src/ape/lib/ap/plan9/_buf.c @@ -52,6 +52,7 @@ _startbuf(int fd) int i, pid; Fdinfo *f; Muxbuf *b; + void *v; if(mux == 0){ _RFORK(RFREND); @@ -111,16 +112,20 @@ Found: for(i=0; icopypid, (void*)_muxsid) == (void*)~0) + ; _copyproc(fd, b); } - /* parent process continues ... */ b->copypid = pid; f->buf = b; f->flags |= FD_BUFFERED; unlock(&mux->lock); - _muxsid = _RENDEZVOUS(0, 0); + + while((v = _RENDEZVOUS(&b->copypid, 0)) == (void*)~0) + ; + _muxsid = (int)v; + /* leave fd open in parent so system doesn't reuse it */ return 0; } @@ -168,7 +173,7 @@ _copyproc(int fd, Muxbuf *b) /* sleep until there's room */ b->roomwait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS(&b->roomwait, 0); } } else unlock(&mux->lock); @@ -193,15 +198,15 @@ _copyproc(int fd, Muxbuf *b) if(mux->selwait && FD_ISSET(fd, &mux->ewant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else if(b->datawait) { b->datawait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else unlock(&mux->lock); _exit(0); @@ -214,12 +219,12 @@ _copyproc(int fd, Muxbuf *b) b->datawait = 0; unlock(&mux->lock); /* wake up _bufreading process */ - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); } else if(mux->selwait && FD_ISSET(fd, &mux->rwant)) { mux->selwait = 0; unlock(&mux->lock); /* wake up selecting process */ - _RENDEZVOUS((unsigned long)&mux->selwait, fd); + _RENDEZVOUS(&mux->selwait, (void*)fd); } else unlock(&mux->lock); } else @@ -265,7 +270,7 @@ goteof: /* sleep until there's data */ b->datawait = 1; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&b->datawait, 0); + _RENDEZVOUS(&b->datawait, 0); lock(&mux->lock); if(b->fd != fd){ unlock(&mux->lock); @@ -287,7 +292,7 @@ goteof: b->roomwait = 0; unlock(&mux->lock); /* wake up copy process */ - _RENDEZVOUS((unsigned long)&b->roomwait, 0); + _RENDEZVOUS(&b->roomwait, 0); } else unlock(&mux->lock); return ngot; @@ -390,7 +395,7 @@ select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeo } mux->selwait = 1; unlock(&mux->lock); - fd = _RENDEZVOUS((unsigned long)&mux->selwait, 0); + fd = (int)_RENDEZVOUS(&mux->selwait, 0); if(fd >= 0 && fd < nfds) { b = _fdinfo[fd].buf; if(b == 0 || b->fd != fd) { @@ -435,7 +440,8 @@ _timerproc(void) signal(SIGALRM, alarmed); for(i=0; iwaittime); if(timerreset) { @@ -446,7 +452,7 @@ _timerproc(void) mux->selwait = 0; mux->waittime = LONGWAIT; unlock(&mux->lock); - _RENDEZVOUS((unsigned long)&mux->selwait, -2); + _RENDEZVOUS(&mux->selwait, (void*)-2); } else { mux->waittime = LONGWAIT; unlock(&mux->lock); @@ -454,9 +460,12 @@ _timerproc(void) } } } - atexit(_killtimerproc); /* parent process continues */ - _RENDEZVOUS(1, 0); + if(timerpid > 0){ + atexit(_killtimerproc); + while(_RENDEZVOUS(&timerpid, 0) == (void*)~0) + ; + } } static void diff --git a/sys/src/ape/lib/ap/plan9/qlock.c b/sys/src/ape/lib/ap/plan9/qlock.c index b0882f789..3be8dae25 100644 --- a/sys/src/ape/lib/ap/plan9/qlock.c +++ b/sys/src/ape/lib/ap/plan9/qlock.c @@ -73,7 +73,7 @@ qlock(QLock *q) unlock(&q->lock); /* wait */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -91,7 +91,7 @@ qunlock(QLock *q) if(q->head == nil) q->tail = nil; unlock(&q->lock); - while((*_rendezvousp)((ulong)p, 0x12345) == ~0) + while((*_rendezvousp)(p, (void*)0x12345) == (void*)~0) ; return; } @@ -140,7 +140,7 @@ rlock(RWLock *q) unlock(&q->lock); /* wait in kernel */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -183,7 +183,7 @@ runlock(RWLock *q) unlock(&q->lock); /* wakeup waiter */ - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, (void*)0) == (void*)~0) ; } @@ -213,7 +213,7 @@ wlock(RWLock *q) unlock(&q->lock); /* wait in kernel */ - while((*_rendezvousp)((ulong)mp, 1) == ~0) + while((*_rendezvousp)(mp, (void*)1) == (void*)~0) ; mp->inuse = 0; } @@ -252,7 +252,7 @@ wunlock(RWLock *q) if(q->head == nil) q->tail = nil; unlock(&q->lock); - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, (void*)0) == (void*)~0) ; return; } @@ -265,7 +265,7 @@ wunlock(RWLock *q) p = q->head; q->head = p->next; q->readers++; - while((*_rendezvousp)((ulong)p, 0) == ~0) + while((*_rendezvousp)(p, (void*)0) == (void*)~0) ; } if(q->head == nil) @@ -303,7 +303,7 @@ rsleep(Rendez *r) if(r->l->head == nil) r->l->tail = nil; unlock(&r->l->lock); - while((*_rendezvousp)((ulong)t, 0x12345) == ~0) + while((*_rendezvousp)(t, (void*)0x12345) == (void*)~0) ; }else{ r->l->locked = 0; @@ -311,7 +311,7 @@ rsleep(Rendez *r) } /* wait for a wakeup */ - while((*_rendezvousp)((ulong)me, 1) == ~0) + while((*_rendezvousp)(me, (void*)1) == (void*)~0) ; me->inuse = 0; } diff --git a/sys/src/ape/lib/ap/plan9/sys9.h b/sys/src/ape/lib/ap/plan9/sys9.h index b289273cb..b9e5bbc04 100644 --- a/sys/src/ape/lib/ap/plan9/sys9.h +++ b/sys/src/ape/lib/ap/plan9/sys9.h @@ -98,10 +98,10 @@ extern long _PREAD(int, void*, long, long long); extern long _PWRITE(int, void*, long, long long); extern long _READ(int, void*, long); extern int _REMOVE(const char*); -extern int _RENDEZVOUS(unsigned long, unsigned long); +extern void* _RENDEZVOUS(void*, void*); extern int _RFORK(int); -extern int _SEGATTACH(int, char*, void*, unsigned long); -extern int _SEGBRK(void*, void*); +extern void* _SEGATTACH(int, char*, void*, unsigned long); +extern void* _SEGBRK(void*, void*); extern int _SEGDETACH(void*); extern int _SEGFLUSH(void*, unsigned long); extern int _SEGFREE(void*, unsigned long); diff --git a/sys/src/ape/lib/bsd/listen.c b/sys/src/ape/lib/bsd/listen.c index b0408cd19..045ff3a91 100644 --- a/sys/src/ape/lib/bsd/listen.c +++ b/sys/src/ape/lib/bsd/listen.c @@ -31,14 +31,11 @@ extern void _killmuxsid(void); static int listenproc(Rock *r, int fd) { - Rock *nr; - char *net; - int cfd, nfd, dfd; - int pfd[2]; + char listen[Ctlsize], name[Ctlsize], *net, *p; + int cfd, nfd, dfd, pfd[2]; struct stat d; - char *p; - char listen[Ctlsize]; - char name[Ctlsize]; + Rock *nr; + void *v; switch(r->stype){ case SOCK_DGRAM: @@ -81,11 +78,14 @@ listenproc(Rock *r, int fd) _muxsid = getpgrp(); } else setpgid(getpid(), _muxsid); - _RENDEZVOUS(2, _muxsid); + while(_RENDEZVOUS(r, (void*)_muxsid) == (void*)~0) + ; break; default: + while((v = _RENDEZVOUS(r, 0)) == (void*)~0) + ; + _muxsid = (int)v; atexit(_killmuxsid); - _muxsid = _RENDEZVOUS(2, 0); close(pfd[1]); close(nfd); return 0; diff --git a/sys/src/ape/lib/draw/libc.h b/sys/src/ape/lib/draw/libc.h index 97e3deacb..f6c5e97a2 100644 --- a/sys/src/ape/lib/draw/libc.h +++ b/sys/src/ape/lib/draw/libc.h @@ -84,10 +84,10 @@ extern long _PREAD(int, void*, long, long long); extern long _PWRITE(int, void*, long, long long); extern long _READ(int, void*, long); extern int _REMOVE(const char*); -extern int _RENDEZVOUS(unsigned long, unsigned long); +extern void* _RENDEZVOUS(void*, void*); extern int _RFORK(int); -extern int _SEGATTACH(int, char*, void*, unsigned long); -extern int _SEGBRK(void*, void*); +extern void* _SEGATTACH(int, char*, void*, unsigned long); +extern void* _SEGBRK(void*, void*); extern int _SEGDETACH(void*); extern int _SEGFLUSH(void*, unsigned long); extern int _SEGFREE(void*, unsigned long); From 3174ffc971c3f48a41e9717eae564c1019c82bf8 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 11 May 2013 18:43:03 +0200 Subject: [PATCH 10/42] acme: apply nemos acmediskread patch (from sources) pread does not guarantee that it would read all the data asked for. But acme usage of disk assumes that. This issues as many reads as needed to make acme work when read returns less data than it wanted. --- sys/src/cmd/acme/disk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/src/cmd/acme/disk.c b/sys/src/cmd/acme/disk.c index 4c22d0a8c..9b76a5582 100644 --- a/sys/src/cmd/acme/disk.c +++ b/sys/src/cmd/acme/disk.c @@ -120,10 +120,20 @@ diskwrite(Disk *d, Block **bp, Rune *r, uint n) void diskread(Disk *d, Block *b, Rune *r, uint n) { + int tot, nr; + char *p; + if(n > b->n) error("internal error: diskread"); ntosize(b->n, nil); - if(pread(d->fd, r, n*sizeof(Rune), b->addr) != n*sizeof(Rune)) + n *= sizeof(Rune); + p = (char*)r; + for(tot = 0; tot < n; tot += nr){ + nr = pread(d->fd, p+tot, n-tot, b->addr+tot); + if(nr <= 0) + error("read error from temp file"); + } + if(tot != n) error("read error from temp file"); } From fe073f852a0c085c99545b361e948d29023531c8 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 11 May 2013 18:45:46 +0200 Subject: [PATCH 11/42] sdide: add Intel SERIES 6 SATA controller pci ids --- sys/src/9/pc/sdide.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/src/9/pc/sdide.c b/sys/src/9/pc/sdide.c index 583bde63c..48a160538 100644 --- a/sys/src/9/pc/sdide.c +++ b/sys/src/9/pc/sdide.c @@ -2079,6 +2079,10 @@ atapnp(void) case (0x7111<<16)|0x8086: /* 82371[AE]B (PIIX4[E]) */ maxdma = 0x20000; break; + case (0x1c00<<16)|0x8086: /* SERIES6 SATA */ + case (0x1c01<<16)|0x8086: /* SERIES6 SATA */ + case (0x1c08<<16)|0x8086: /* SERIES6 SATA */ + case (0x1c09<<16)|0x8086: /* SERIES6 SATA */ case (0x2411<<16)|0x8086: /* 82801AA (ICH) */ case (0x2421<<16)|0x8086: /* 82801AB (ICH0) */ case (0x244A<<16)|0x8086: /* 82801BA (ICH2, Mobile) */ From 25bc4e84e9ef8df694937b107111160e707e0299 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 11 May 2013 20:54:50 +0200 Subject: [PATCH 12/42] devmnt: fix mount device leak and allocation error handling in mntversion() the fist problem is that qopen() might return nil and that kstrdup() will sleep, so we should try to avoid holding the mntalloc lock. so we move the kstrdup() and qopen() calls before the Mnt allocation, and properly recover the memory if we fail later. the second problem was that we error(Eshort) after we already created the Mnt when returnlen < sizeof(f.version). this check has to happen *before* we even attempt to allocate the Mnt structures. note that we only copy the version string once everything is in the clear, so the semantics of the user buffer not being modified in case of error is not changed. a little cleanup in muxclose(), getting rid of mntptfree()... --- sys/src/9/port/devmnt.c | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sys/src/9/port/devmnt.c b/sys/src/9/port/devmnt.c index 5f46b9467..da51d0366 100644 --- a/sys/src/9/port/devmnt.c +++ b/sys/src/9/port/devmnt.c @@ -61,7 +61,6 @@ Mntrpc* mntflushalloc(Mntrpc*, ulong); void mntflushfree(Mnt*, Mntrpc*); void mntfree(Mntrpc*); void mntgate(Mnt*); -void mntpntfree(Mnt*); void mntqrm(Mnt*, Mntrpc*); Mntrpc* mntralloc(Chan*, ulong); long mntrdwr(int, Chan*, void*, long, vlong); @@ -101,6 +100,7 @@ mntversion(Chan *c, char *version, int msize, int returnlen) uchar *msg; Mnt *m; char *v; + Queue *q; long k, l; uvlong oo; char buf[128]; @@ -199,6 +199,16 @@ mntversion(Chan *c, char *version, int msize, int returnlen) k = strlen(f.version); if(strncmp(f.version, v, k) != 0) error("bad 9P version returned from server"); + if(returnlen > 0 && returnlen < k) + error(Eshort); + + v = nil; + kstrdup(&v, f.version); + q = qopen(10*MAXRPC, 0, nil, nil); + if(q == nil){ + free(v); + exhausted("mount queues"); + } /* now build Mnt associated with this connection */ lock(&mntalloc); @@ -208,24 +218,22 @@ mntversion(Chan *c, char *version, int msize, int returnlen) else { m = malloc(sizeof(Mnt)); if(m == 0) { + qfree(q); + free(v); unlock(&mntalloc); exhausted("mount devices"); } } m->list = mntalloc.list; mntalloc.list = m; - m->version = nil; - kstrdup(&m->version, f.version); + m->version = v; m->id = mntalloc.id++; - m->q = qopen(10*MAXRPC, 0, nil, nil); + m->q = q; m->msize = f.msize; unlock(&mntalloc); - if(returnlen > 0){ - if(returnlen < k) - error(Eshort); - memmove(version, f.version, k); - } + if(returnlen > 0) + memmove(version, f.version, k); /* length was checked above */ poperror(); /* msg */ free(msg); @@ -564,23 +572,18 @@ mntclunk(Chan *c, int t) void muxclose(Mnt *m) { - Mntrpc *q, *r; + Mnt *f, **l; + Mntrpc *r; - for(q = m->queue; q; q = r) { - r = q->list; - mntfree(q); + while((r = m->queue) != nil){ + m->queue = r->list; + mntfree(r); } m->id = 0; free(m->version); m->version = nil; - mntpntfree(m); -} - -void -mntpntfree(Mnt *m) -{ - Mnt *f, **l; - Queue *q; + qfree(m->q); + m->q = nil; lock(&mntalloc); l = &mntalloc.list; @@ -593,10 +596,7 @@ mntpntfree(Mnt *m) } m->list = mntalloc.mntfree; mntalloc.mntfree = m; - q = m->q; unlock(&mntalloc); - - qfree(q); } static void From 29ece7fda4a8e4eea62eabcfbd8fd04bef613742 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 12 May 2013 02:58:02 +0200 Subject: [PATCH 13/42] ether8169: and phy wakeup and reset phy before enabling auto negotiation this brings up the 8198B on BurnZeZ's ASRock Z68 Professional Gen3 board. --- sys/src/9/pc/ether8169.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/src/9/pc/ether8169.c b/sys/src/9/pc/ether8169.c index 6c9a610ec..51377f454 100644 --- a/sys/src/9/pc/ether8169.c +++ b/sys/src/9/pc/ether8169.c @@ -50,6 +50,8 @@ enum { /* registers */ Tbianar = 0x68, /* TBI Auto-Negotiation Advertisment */ Tbilpar = 0x6A, /* TBI Auto-Negotiation Link Partner */ Phystatus = 0x6C, /* PHY Status */ + Pmch = 0x6F, /* power management */ + Ldps = 0x82, /* link down power saving */ Rms = 0xDA, /* Receive Packet Maximum Size */ Cplusc = 0xE0, /* C+ Command */ @@ -387,13 +389,20 @@ rtl8169mii(Ctlr* ctlr) ctlr->mii->miw = rtl8169miimiw; ctlr->mii->ctlr = ctlr; + /* + * PHY wakeup + */ + csr8w(ctlr, Pmch, csr8r(ctlr, Pmch) | 0x80); + rtl8169miimiw(ctlr->mii, 1, 0x1f, 0); + rtl8169miimiw(ctlr->mii, 1, 0x0e, 0); + /* * Get rev number out of Phyidr2 so can config properly. * There's probably more special stuff for Macv0[234] needed here. */ ctlr->phyv = rtl8169miimir(ctlr->mii, 1, Phyidr2) & 0x0F; if(ctlr->macv == Macv02){ - csr8w(ctlr, 0x82, 1); /* magic */ + csr8w(ctlr, Ldps, 1); /* magic */ rtl8169miimiw(ctlr->mii, 1, 0x0B, 0x0000); /* magic */ } @@ -405,6 +414,10 @@ rtl8169mii(Ctlr* ctlr) print("rtl8169: oui %#ux phyno %d, macv = %#8.8ux phyv = %#4.4ux\n", phy->oui, phy->phyno, ctlr->macv, ctlr->phyv); + miireset(ctlr->mii); + + microdelay(100); + miiane(ctlr->mii, ~0, ~0, ~0); return 0; From 8020743579ed7398bf0c61e5723d827d41d70475 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 12 May 2013 18:25:24 +0200 Subject: [PATCH 14/42] ether8169: do phywakeup magic only for specific mac versions (from openbsd) --- sys/src/9/pc/ether8169.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/src/9/pc/ether8169.c b/sys/src/9/pc/ether8169.c index 51377f454..cf9ebdf08 100644 --- a/sys/src/9/pc/ether8169.c +++ b/sys/src/9/pc/ether8169.c @@ -119,6 +119,7 @@ enum { /* Tcr */ Macv27 = 0x2c800000, /* RTL8111e */ Macv28 = 0x2c000000, /* RTL8111/8168B */ Macv29 = 0x40800000, /* RTL8101/8102E */ + Macv30 = 0x24000000, /* RTL8101E? (untested) */ Ifg0 = 0x01000000, /* Interframe Gap 0 */ Ifg1 = 0x02000000, /* Interframe Gap 1 */ }; @@ -392,7 +393,14 @@ rtl8169mii(Ctlr* ctlr) /* * PHY wakeup */ - csr8w(ctlr, Pmch, csr8r(ctlr, Pmch) | 0x80); + switch(ctlr->macv){ + case Macv25: + case Macv28: + case Macv29: + case Macv30: + csr8w(ctlr, Pmch, csr8r(ctlr, Pmch) | 0x80); + break; + } rtl8169miimiw(ctlr->mii, 1, 0x1f, 0); rtl8169miimiw(ctlr->mii, 1, 0x0e, 0); @@ -1031,6 +1039,7 @@ vetmacv(Ctlr *ctlr, uint *macv) case Macv27: case Macv28: case Macv29: + case Macv30: break; } return 0; From 1d760c9b3ea8eb5d7d0484cb66527c6a9d4eb5ea Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 12:53:43 -0400 Subject: [PATCH 15/42] file: recognize bitmap and graymap ppm images writeppm: do not print extra space after each pixel for graymap formats to save space --- sys/src/cmd/file.c | 4 ++++ sys/src/cmd/jpg/writeppm.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/file.c b/sys/src/cmd/file.c index b92f088ad..ee6db10b4 100644 --- a/sys/src/cmd/file.c +++ b/sys/src/cmd/file.c @@ -828,7 +828,11 @@ struct FILE_STRING "OggS", "ogg audio", 4, "audio/ogg", ".snd", "sun audio", 4, "audio/basic", "\211PNG", "PNG image", 4, "image/png", + "P1\n", "ppm", 3, "image/ppm", + "P2\n", "ppm", 3, "image/ppm", "P3\n", "ppm", 3, "image/ppm", + "P4\n", "ppm", 3, "image/ppm", + "P5\n", "ppm", 3, "image/ppm", "P6\n", "ppm", 3, "image/ppm", "/* XPM */\n", "xbm", 10, "image/xbm", ".HTML ", "troff -ms input", 6, "text/troff", diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index bf32f0d25..9d4c92d07 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -70,7 +70,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) pix = (data[i]>>depth*((xmask-x)&xmask))&pmask; if(((x+1)&xmask) == 0) i++; - col += Bprint(fd, "%d ", pix); + col += Bprint(fd, "%d", pix); if(col >= MAXLINE-(2+1)){ Bprint(fd, "\n"); col = 0; @@ -81,7 +81,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) break; case GREY8: for(i=0; i= MAXLINE-(4+1)){ Bprint(fd, "\n"); col = 0; From 3cccb8fb124b3dffd9124551d74c13b4531dc3f2 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 12 May 2013 19:04:07 +0200 Subject: [PATCH 16/42] devaoe: avoid panic on malloc() error by using smalloc() instead. --- sys/src/9/port/devaoe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/src/9/port/devaoe.c b/sys/src/9/port/devaoe.c index 85ce88494..0512f7016 100644 --- a/sys/src/9/port/devaoe.c +++ b/sys/src/9/port/devaoe.c @@ -1362,7 +1362,7 @@ devlinkread(Chan *c, void *db, int len, int off) return 0; l = d->dl + i; - s = p = malloc(READSTR); + s = p = smalloc(READSTR); e = s + READSTR; p = seprint(p, e, "addr: "); @@ -1398,7 +1398,7 @@ topctlread(Chan *, void *db, int len, int off) char *s, *p, *e; Netlink *n; - s = p = malloc(READSTR); + s = p = smalloc(READSTR); e = s + READSTR; p = seprint(p, e, "debug: %d\n", debug); @@ -1463,7 +1463,7 @@ configwrite(Aoedev *d, void *db, long len) if(len > sizeof d->config) error(Etoobig); srb = srballoc(len); - s = malloc(len); + s = smalloc(len); memmove(s, db, len); if(waserror()){ srbfree(srb); @@ -1679,7 +1679,7 @@ unitwrite(Chan *c, void *db, long n, vlong off) case Qconfig: if(off + n > sizeof d->config) error(Etoobig); - buf = malloc(sizeof d->config); + buf = smalloc(sizeof d->config); if(waserror()){ free(buf); nexterror(); From b78e9525cf41f99ed845c5d3d878c0936cba6e7f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 12 May 2013 19:12:21 +0200 Subject: [PATCH 17/42] writeppm: fix tab/spaces --- sys/src/cmd/jpg/writeppm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index 9d4c92d07..296df53a7 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -79,7 +79,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) } } break; - case GREY8: + case GREY8: for(i=0; i= MAXLINE-(4+1)){ @@ -118,7 +118,7 @@ writeppm0(Biobuf *fd, Image *image, Memimage *memimage, Rectangle r, int chan, c break; case GREY2: case GREY4: - case GREY8: + case GREY8: Bprint(fd, "P2\n"); break; case RGB24: @@ -143,7 +143,7 @@ writeppm0(Biobuf *fd, Image *image, Memimage *memimage, Rectangle r, int chan, c case GREY4: Bprint(fd, "%d\n", 15); break; - case GREY8: + case GREY8: case RGB24: Bprint(fd, "%d\n", 255); break; From d5e3e4326cf24190d11c6f33e1c2c8c563b736b6 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 16:11:43 -0400 Subject: [PATCH 18/42] toppm: add -r flag for raw ppm --- sys/man/1/jpg | 11 +++++-- sys/src/cmd/jpg/imagefile.h | 4 +-- sys/src/cmd/jpg/toppm.c | 14 ++++++--- sys/src/cmd/jpg/writeppm.c | 62 ++++++++++++++++++++++++++++++------- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/sys/man/1/jpg b/sys/man/1/jpg index 6ffc79e87..e3583d4bb 100644 --- a/sys/man/1/jpg +++ b/sys/man/1/jpg @@ -85,6 +85,8 @@ jpg, gif, png, ppm, bmp, v210, yuv, ico, tga, togif, toppm, topng, toico \- view .B -c .I comment ] [ +.B -r +] [ .I file ] .br @@ -93,7 +95,6 @@ jpg, gif, png, ppm, bmp, v210, yuv, ico, tga, togif, toppm, topng, toico \- view .B -c .I comment ] [ -[ .B -g .I gamma ] [ @@ -126,7 +127,7 @@ read files in the corresponding formats and, by default, display them in the current window; options cause them instead to convert the images to Plan 9 image format and write them to standard output. .IR Togif , -.IR Toppm , +.IR toppm , and .I topng read Plan 9 images files, convert them to GIF, PPM, or PNG, and write them to standard output. @@ -212,6 +213,12 @@ and have no display capability. Both accept an option .B -c to set the comment field of the resulting file. +The +.B -r +option makes +.I toppm +output raw PPM. +The default is to output plain PPM. If there is only one input picture, .I togif converts the image to GIF format. diff --git a/sys/src/cmd/jpg/imagefile.h b/sys/src/cmd/jpg/imagefile.h index 2dbc461f2..d9ab871b9 100644 --- a/sys/src/cmd/jpg/imagefile.h +++ b/sys/src/cmd/jpg/imagefile.h @@ -71,8 +71,8 @@ void memendgif(Biobuf*); Image* onechan(Image*); Memimage* memonechan(Memimage*); -char* writeppm(Biobuf*, Image*, char*); -char* memwriteppm(Biobuf*, Memimage*, char*); +char* writeppm(Biobuf*, Image*, char*, int); +char* memwriteppm(Biobuf*, Memimage*, char*, int); Image* multichan(Image*); Memimage* memmultichan(Memimage*); diff --git a/sys/src/cmd/jpg/toppm.c b/sys/src/cmd/jpg/toppm.c index e30946555..cdb8be261 100644 --- a/sys/src/cmd/jpg/toppm.c +++ b/sys/src/cmd/jpg/toppm.c @@ -9,7 +9,7 @@ void usage(void) { - fprint(2, "usage: toppm [-c 'comment'] [file]\n"); + fprint(2, "usage: toppm [-c 'comment'] [-r] [file]\n"); exits("usage"); } @@ -18,10 +18,11 @@ main(int argc, char *argv[]) { Biobuf bout; Memimage *i, *ni; - int fd; + int fd, rflag; char buf[256]; char *err, *comment; + rflag = 0; comment = nil; ARGBEGIN{ case 'c': @@ -33,6 +34,9 @@ main(int argc, char *argv[]) usage(); } break; + case 'r': + rflag = 1; + break; default: usage(); }ARGEND @@ -59,7 +63,7 @@ main(int argc, char *argv[]) i = ni; } if(err == nil) - err = memwriteppm(&bout, i, comment); + err = memwriteppm(&bout, i, comment, rflag); }else{ fd = open(argv[0], OREAD); if(fd < 0) @@ -76,10 +80,10 @@ main(int argc, char *argv[]) i = ni; } if(comment) - err = memwriteppm(&bout, i, comment); + err = memwriteppm(&bout, i, comment, rflag); else{ snprint(buf, sizeof buf, "Converted by Plan 9 from %s", argv[0]); - err = memwriteppm(&bout, i, buf); + err = memwriteppm(&bout, i, buf, rflag); } freememimage(i); } diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index 296df53a7..040196823 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -12,12 +12,32 @@ static int log2[] = { -1, -1, -1, -1, -1, -1, -1, 4 /* BUG */, -1, -1, -1, -1, -1, -1, -1, 5 }; +static int bitc = 0; +static int nbit = 0; + +static +void +Bputbit(Biobufhdr *b, int c) +{ + if(c >= 0x0) { + bitc = (bitc << 1) | (c & 0x1); + nbit++; + } else if(nbit > 0) { + for(; nbit < 8; nbit++) + bitc <<= 1; + } + if(nbit == 8) { + Bputc(b, bitc); + bitc = nbit = 0; + } +} + /* * Write data */ static char* -writedata(Biobuf *fd, Image *image, Memimage *memimage) +writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) { char *err; uchar *data; @@ -70,6 +90,13 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) pix = (data[i]>>depth*((xmask-x)&xmask))&pmask; if(((x+1)&xmask) == 0) i++; + if(rflag) { + if(chan == GREY1) + Bputbit(fd, pix); + else + Bputc(fd, pix); + continue; + } col += Bprint(fd, "%d", pix); if(col >= MAXLINE-(2+1)){ Bprint(fd, "\n"); @@ -77,10 +104,16 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) }else col += Bprint(fd, " "); } + if(rflag) + Bputbit(fd, -1); } break; case GREY8: for(i=0; i= MAXLINE-(4+1)){ Bprint(fd, "\n"); @@ -91,6 +124,12 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) break; case RGB24: for(i=0; i= MAXLINE-(4+4+4+1)){ Bprint(fd, "\n"); @@ -108,21 +147,21 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage) static char* -writeppm0(Biobuf *fd, Image *image, Memimage *memimage, Rectangle r, int chan, char *comment) +writeppm0(Biobuf *fd, Image *image, Memimage *memimage, Rectangle r, int chan, char *comment, int rflag) { char *err; switch(chan){ case GREY1: - Bprint(fd, "P1\n"); + Bprint(fd, "%s\n", rflag? "P4": "P1"); break; case GREY2: case GREY4: case GREY8: - Bprint(fd, "P2\n"); + Bprint(fd, "%s\n", rflag? "P5": "P2"); break; case RGB24: - Bprint(fd, "P3\n"); + Bprint(fd, "%s\n", rflag? "P6": "P3"); break; default: return "WritePPM: can't handle channel type"; @@ -149,21 +188,22 @@ writeppm0(Biobuf *fd, Image *image, Memimage *memimage, Rectangle r, int chan, c break; } - err = writedata(fd, image, memimage); + err = writedata(fd, image, memimage, rflag); - Bprint(fd, "\n"); + if(!rflag) + Bprint(fd, "\n"); Bflush(fd); return err; } char* -writeppm(Biobuf *fd, Image *image, char *comment) +writeppm(Biobuf *fd, Image *image, char *comment, int rflag) { - return writeppm0(fd, image, nil, image->r, image->chan, comment); + return writeppm0(fd, image, nil, image->r, image->chan, comment, rflag); } char* -memwriteppm(Biobuf *fd, Memimage *memimage, char *comment) +memwriteppm(Biobuf *fd, Memimage *memimage, char *comment, int rflag) { - return writeppm0(fd, nil, memimage, memimage->r, memimage->chan, comment); + return writeppm0(fd, nil, memimage, memimage->r, memimage->chan, comment, rflag); } From a1130d843d51baeca46081930cc1476381c0b891 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 16:17:09 -0400 Subject: [PATCH 19/42] toppm: fix style --- sys/src/cmd/jpg/writeppm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index 040196823..bc18ecee8 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -19,14 +19,14 @@ static void Bputbit(Biobufhdr *b, int c) { - if(c >= 0x0) { + if(c >= 0x0){ bitc = (bitc << 1) | (c & 0x1); nbit++; - } else if(nbit > 0) { + }else if(nbit > 0){ for(; nbit < 8; nbit++) bitc <<= 1; } - if(nbit == 8) { + if(nbit == 8){ Bputc(b, bitc); bitc = nbit = 0; } @@ -90,7 +90,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) pix = (data[i]>>depth*((xmask-x)&xmask))&pmask; if(((x+1)&xmask) == 0) i++; - if(rflag) { + if(rflag){ if(chan == GREY1) Bputbit(fd, pix); else @@ -110,7 +110,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) break; case GREY8: for(i=0; i Date: Sun, 12 May 2013 16:36:29 -0400 Subject: [PATCH 20/42] writeppm: for bitmaps, 1 is black, 0 is white --- sys/src/cmd/jpg/writeppm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index bc18ecee8..9c96f538e 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -90,6 +90,8 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) pix = (data[i]>>depth*((xmask-x)&xmask))&pmask; if(((x+1)&xmask) == 0) i++; + if(chan == GREY1) + pix = pix == 1? 0: 1; if(rflag){ if(chan == GREY1) Bputbit(fd, pix); From 6bcc1eb399d794facd5b2a8678e5b9fc21bd7ea0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 13 May 2013 23:03:23 +0200 Subject: [PATCH 21/42] writeppm: simplify --- sys/src/cmd/jpg/writeppm.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index 9c96f538e..6064dff30 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -90,14 +90,17 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) pix = (data[i]>>depth*((xmask-x)&xmask))&pmask; if(((x+1)&xmask) == 0) i++; - if(chan == GREY1) - pix = pix == 1? 0: 1; - if(rflag){ - if(chan == GREY1) + if(chan == GREY1){ + pix ^= 1; + if(rflag){ Bputbit(fd, pix); - else + continue; + } + } else { + if(rflag){ Bputc(fd, pix); - continue; + continue; + } } col += Bprint(fd, "%d", pix); if(col >= MAXLINE-(2+1)){ From eee014146506d9bd66b0e316e463a55a53d9e6e0 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 17:08:52 -0400 Subject: [PATCH 22/42] writeppm: replace WriteGIF by WritePPM --- sys/src/cmd/jpg/writeppm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index 6064dff30..dd716cf46 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -71,7 +71,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) err = malloc(ERRMAX); if(err == nil) return "WritePPM: malloc failed"; - snprint(err, ERRMAX, "WriteGIF: %r"); + snprint(err, ERRMAX, "WritePPM: %r"); free(data); return err; } From df25791b3394ad62a81c2f1efd413ffc673f6765 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 17:46:39 -0400 Subject: [PATCH 23/42] toppm: multichan converts to RGB24, not RGBV --- sys/src/cmd/jpg/toppm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/cmd/jpg/toppm.c b/sys/src/cmd/jpg/toppm.c index cdb8be261..3a967d2fa 100644 --- a/sys/src/cmd/jpg/toppm.c +++ b/sys/src/cmd/jpg/toppm.c @@ -74,7 +74,7 @@ main(int argc, char *argv[]) close(fd); ni = memmultichan(i); if(ni == nil) - sysfatal("converting image to RGBV: %r"); + sysfatal("converting image to RGB24: %r"); if(i != ni){ freememimage(i); i = ni; From 03d1d83debec8a4f002b1ea809fd1cc2974cfef8 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 17:52:35 -0400 Subject: [PATCH 24/42] toppm: checking for err is useless; it was initialized to nil earlier --- sys/src/cmd/jpg/toppm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sys/src/cmd/jpg/toppm.c b/sys/src/cmd/jpg/toppm.c index 3a967d2fa..6fac8f3b3 100644 --- a/sys/src/cmd/jpg/toppm.c +++ b/sys/src/cmd/jpg/toppm.c @@ -62,8 +62,7 @@ main(int argc, char *argv[]) freememimage(i); i = ni; } - if(err == nil) - err = memwriteppm(&bout, i, comment, rflag); + err = memwriteppm(&bout, i, comment, rflag); }else{ fd = open(argv[0], OREAD); if(fd < 0) From 7b4c8aac930b440ca2f4a877f0459f75c8f2fe70 Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Sun, 12 May 2013 18:00:47 -0400 Subject: [PATCH 25/42] toppm: no need to initialize err --- sys/src/cmd/jpg/toppm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/src/cmd/jpg/toppm.c b/sys/src/cmd/jpg/toppm.c index 6fac8f3b3..724854e63 100644 --- a/sys/src/cmd/jpg/toppm.c +++ b/sys/src/cmd/jpg/toppm.c @@ -49,8 +49,6 @@ main(int argc, char *argv[]) memimageinit(); - err = nil; - if(argc == 0){ i = readmemimage(0); if(i == nil) From 303394314aa041cf52cbb02441aca04f12aafddf Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 13 May 2013 04:19:10 +0200 Subject: [PATCH 26/42] rio: fix completion and readback and make it possible to complete history --- sys/src/cmd/rio/wind.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sys/src/cmd/rio/wind.c b/sys/src/cmd/rio/wind.c index 8752090c7..b96f8b986 100644 --- a/sys/src/cmd/rio/wind.c +++ b/sys/src/cmd/rio/wind.c @@ -471,7 +471,7 @@ showcandidates(Window *w, Completion *c) int i; Fmt f; Rune *rp; - uint nr, qline, q0; + uint nr, qline; char *s; runefmtstrinit(&f); @@ -490,20 +490,21 @@ showcandidates(Window *w, Completion *c) } fmtprint(&f, "]\n"); } - /* place text at beginning of line before host point */ - qline = w->qh; - while(qline>0 && w->r[qline-1] != '\n') - qline--; - rp = runefmtstrflush(&f); nr = runestrlen(rp); - q0 = w->q0; - q0 += winsert(w, rp, nr, qline) - qline; - if(q0 >= w->qh) - w->qh += nr; + /* place text at beginning of line before cursor */ + qline = w->q0; + while(qline>0 && w->r[qline-1] != '\n') + qline--; + + if(qline == w->qh){ + /* advance host point to avoid readback */ + w->qh = winsert(w, rp, nr, qline)+nr; + } else { + winsert(w, rp, nr, qline); + } free(rp); - wsetselect(w, q0+nr, q0+nr); } Rune* From f990a6d30abe4a50d3120f513f8a6b3f6c531b2a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 13 May 2013 04:40:02 +0200 Subject: [PATCH 27/42] rio: place text at beginning of line before cursor and host point --- sys/src/cmd/rio/wind.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/rio/wind.c b/sys/src/cmd/rio/wind.c index b96f8b986..6fd67a559 100644 --- a/sys/src/cmd/rio/wind.c +++ b/sys/src/cmd/rio/wind.c @@ -493,8 +493,8 @@ showcandidates(Window *w, Completion *c) rp = runefmtstrflush(&f); nr = runestrlen(rp); - /* place text at beginning of line before cursor */ - qline = w->q0; + /* place text at beginning of line before cursor and host point */ + qline = min(w->qh, w->q0); while(qline>0 && w->r[qline-1] != '\n') qline--; From 9e9521140d86e93b870e87b6344d95e21770b72b Mon Sep 17 00:00:00 2001 From: stanley lieber Date: Tue, 14 May 2013 10:18:49 -0400 Subject: [PATCH 28/42] fortunes: Subject: [9fans] [gsoc] Dart9P --- lib/troll | 2 ++ sys/games/lib/fortunes | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/troll b/lib/troll index 42da69dbb..3c3d2ee32 100644 --- a/lib/troll +++ b/lib/troll @@ -120,3 +120,5 @@ Subject: [nix] servers down I have an IDE HD with fossil (no venti) partition on it. It contains some data precious to me. Would it be possible to support file:// in acme ? i would not be at all surprised if the nix kernel (with or without the AC stuff) ends up being the basis for continuing evolution of plan9. +Subject: [9fans] Go tip build fails +FWIW may be it would make more sense to install Plan 9 (9front) then? diff --git a/sys/games/lib/fortunes b/sys/games/lib/fortunes index e2bc9e204..f7ce9d59d 100644 --- a/sys/games/lib/fortunes +++ b/sys/games/lib/fortunes @@ -4844,3 +4844,17 @@ The development effort for 5ESS required 5000 employees, producing 100 million l Don't forget the colon when referring to keyboards or printers. A Font For Supporters Of Marriage Equality < mveety> im on facebook on my vax right now +(#cat-v) aiju → fiddling with russian machines is so not worth it +Subject: [9fans] Invitation to connect on LinkedIn +Subject: [9fans] [gsoc] Dart9P +The problem is that there aren't any decent languages where you can just sit down and write code, because you have to know so much about the language itself. +China's cyber forces are said to be around 400,000 including militia, and the US has 20,000. +readfile(): nonblocking read blocked +(#cat-v) lf94 → this is linux +no. -- Erik Quanstrom +But if you'll insert it carefull, and will take it out not often, it really will campatible +They look ugly and the fanbase is terrible. +Rio, the Plan 9 windowing system, looks and feels like a step back to the old Amiga and Atari ST days, as the façade is nearly the same. +But really, you need a CRT to be lagless. +is there any real reason for hating modern thinkpads besides the keyboard and screen resolution? +No. -- 20h From 4c6fa55456e8825fa32a5dc7f96944439426b2c7 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 14 May 2013 18:31:24 +0200 Subject: [PATCH 29/42] make clear that the "ipgw" attribute has to be an ip address --- sys/man/6/ndb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/man/6/ndb b/sys/man/6/ndb index 339572c69..da1af6fc9 100644 --- a/sys/man/6/ndb +++ b/sys/man/6/ndb @@ -199,7 +199,7 @@ Internet network name Internet network mask .TP .B ipgw -Internet gateway +Internet gateway (ip address) .TP .B auth authentication server to be used From 172b290e0535ad43ff7d783cbafaf77dadf1073e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 14 May 2013 18:54:42 +0200 Subject: [PATCH 30/42] netaudit: check if ipgw= is an ip address --- rc/bin/netaudit | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rc/bin/netaudit b/rc/bin/netaudit index 075e73a07..f043df988 100755 --- a/rc/bin/netaudit +++ b/rc/bin/netaudit @@ -38,6 +38,16 @@ fn checknet { } if not echo ' we are in ipnet='^$ipnet + ipgw=`{ndb/ipquery sys $sysname ipgw | sed 's/^ipgw=//'} + if(~ $ipgw '' '::'){ + echo ' we do not have an internet gateway, no ipgw= entry' + } + if not { + if(! ~ $ipgw *.*.*.* *:*:*:*:*:*:*:* *::*) + echo ' ipgw='$ipgw 'does not look like an ip address' + if not + echo ' ipgw='$ipgw 'looks ok' + } dns=`{ndb/ipquery sys $sysname dns | sed 's/^dns=//'} if(~ $dns '') echo ' no dns= entry' From d50ca72774732c059c34286e2a74919c16a17c20 Mon Sep 17 00:00:00 2001 From: stanley lieber Date: Wed, 15 May 2013 15:38:42 -0400 Subject: [PATCH 31/42] faces: just say no to dejavu --- sys/src/cmd/faces/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/cmd/faces/main.c b/sys/src/cmd/faces/main.c index e5eee9e42..7d5c38481 100644 --- a/sys/src/cmd/faces/main.c +++ b/sys/src/cmd/faces/main.c @@ -113,7 +113,7 @@ init(void) tinyfont = openfont(display, "/lib/font/bit/misc/ascii.5x7.font"); if(tinyfont == nil) tinyfont = font; - mediumfont = openfont(display, "/lib/font/bit/dejavusans/dejavusans.12.font"); + mediumfont = openfont(display, "/lib/font/bit/misc/unicode.6x13.font"); if(mediumfont == nil) mediumfont = font; datefont = font; From 811c3e8d7806adb1bfc766d9963021934ecef84c Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Sat, 18 May 2013 01:01:34 +0200 Subject: [PATCH 32/42] nusb/kb: use a flag to indicate extended code; fix the most unix-friendly key on se/fi kbd layout --- sys/src/cmd/nusb/kb/kb.c | 58 +++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/sys/src/cmd/nusb/kb/kb.c b/sys/src/cmd/nusb/kb/kb.c index 708ff05c3..2f20645b8 100644 --- a/sys/src/cmd/nusb/kb/kb.c +++ b/sys/src/cmd/nusb/kb/kb.c @@ -56,6 +56,11 @@ struct KDev * besides wheel and regular up/down report the 4th byte as 1/-1 */ +/* + * scan codes >= 0x80 are extended (E0 XX) + */ +#define isext(sc) ((sc) >= 0x80) + /* * key code to scan code; for the page table used by * the logitech bluetooth keyboard. @@ -70,15 +75,15 @@ static char sctab[256] = [0x28] 0x1c, 0x1, 0xe, 0xf, 0x39, 0xc, 0xd, 0x1a, [0x30] 0x1b, 0x2b, 0x2b, 0x27, 0x28, 0x29, 0x33, 0x34, [0x38] 0x35, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, -[0x40] 0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0x63, 0x46, -[0x48] 0x77, 0x52, 0x47, 0x49, 0x53, 0x4f, 0x51, 0x4d, -[0x50] 0x4b, 0x50, 0x48, 0x45, 0x35, 0x37, 0x4a, 0x4e, -[0x58] 0x1c, 0x4f, 0x50, 0x51, 0x4b, 0x4c, 0x4d, 0x47, -[0x60] 0x48, 0x49, 0x52, 0x53, 0x56, 0x7f, 0x74, 0x75, -[0x68] 0x55, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, -[0x70] 0x78, 0x79, 0x7a, 0x7b, 0x0, 0x0, 0x0, 0x0, -[0x78] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x71, -[0x80] 0x73, 0x72, 0x0, 0x0, 0x0, 0x7c, 0x0, 0x0, +[0x40] 0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0xe3, 0x46, +[0x48] 0xf7, 0xd2, 0xc7, 0xc9, 0xd3, 0xcf, 0xd1, 0xcd, +[0x50] 0xcb, 0xd0, 0xc8, 0x45, 0x35, 0x37, 0x4a, 0x4e, +[0x58] 0x1c, 0xcf, 0xd0, 0xd1, 0xcb, 0xcc, 0xcd, 0xc7, +[0x60] 0xc8, 0xc9, 0xd2, 0xd3, 0x56, 0xff, 0xf4, 0xf5, +[0x68] 0xd5, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, +[0x70] 0xf8, 0xf9, 0xfa, 0xfb, 0x0, 0x0, 0x0, 0x0, +[0x78] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf1, +[0x80] 0xf3, 0xf2, 0x0, 0x0, 0x0, 0xfc, 0x0, 0x0, [0x88] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0x90] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0x98] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -90,8 +95,8 @@ static char sctab[256] = [0xc8] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0xd0] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0xd8] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, -[0xe0] 0x1d, 0x2a, 0x38, 0x7d, 0x61, 0x36, 0x64, 0x7e, -[0xe8] 0x0, 0x0, 0x0, 0x0, 0x0, 0x73, 0x72, 0x71, +[0xe0] 0x1d, 0x2a, 0xb8, 0xfd, 0xe1, 0x36, 0xe4, 0xfe, +[0xe8] 0x0, 0x0, 0x0, 0x0, 0x0, 0xf3, 0xf2, 0xf1, [0xf0] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0xf8] 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, }; @@ -513,14 +518,18 @@ ptrwork(void* a) } static void -putscan(int fd, uchar esc, uchar sc) +putscan(int fd, uchar sc, uchar up) { uchar s[2] = {SCesc1, 0}; - s[1] = sc; - if(esc && sc != 0) + s[1] = sc&Keymask; + if(s[1] == 0) + return; + + s[1] |= up; + if(isext(sc)) write(fd, s, 2); - else if(sc != 0) + else write(fd, s+1, 1); } @@ -563,7 +572,7 @@ repeatproc(void* arg) Channel *repeatc, *sleepc; int kbdinfd; ulong l, t; - uchar esc1, sc; + uchar sc; Alt a[3]; repeatc = f->repeatc; @@ -590,13 +599,14 @@ repeatproc(void* arg) l = recvul(repeatc); continue; } - esc1 = l >> 8; sc = l; + if((l>>8) != 0) + sc |= 0x80; t = Kbdelay; if(alt(a) == 1){ t = Kbrepeat; while(alt(a) == 1) - putscan(kbdinfd, esc1, sc); + putscan(kbdinfd, sc, 0); } } if(sleepc != nil) @@ -612,19 +622,17 @@ stoprepeat(KDev *f) } static void -startrepeat(KDev *f, uchar esc1, uchar sc) +startrepeat(KDev *f, uchar sc) { ulong c; - if(esc1) + if(isext(sc)) c = SCesc1 << 8 | (sc & 0xff); else c = sc; sendul(f->repeatc, c); } -#define hasesc1(sc) (((sc) >= 0x47) || ((sc) == 0x38)) - /* * This routine diffs the state with the last known state * and invents the scan codes that would have been sent @@ -654,8 +662,8 @@ putkeys(KDev *f, uchar buf[], uchar obuf[], int n, uchar dk) break; if(j == n && buf[i] != 0){ dk = sctab[buf[i]]; - putscan(fd, hasesc1(dk), dk); - startrepeat(f, hasesc1(dk), dk); + putscan(fd, dk, 0); + startrepeat(f, dk); } } @@ -667,7 +675,7 @@ putkeys(KDev *f, uchar buf[], uchar obuf[], int n, uchar dk) break; if(j == n && obuf[i] != 0){ uk = sctab[obuf[i]]; - putscan(fd, hasesc1(uk), uk|Keyup); + putscan(fd, uk, Keyup); } } if(uk && (dk == 0 || dk == uk)){ From 506cae05df31f3e54992c99ab25ba53c72af49ad Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Sat, 18 May 2013 01:03:13 +0200 Subject: [PATCH 33/42] nusb/kb: oops, fixup --- sys/src/cmd/nusb/kb/kb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sys/src/cmd/nusb/kb/kb.c b/sys/src/cmd/nusb/kb/kb.c index 2f20645b8..987b3942b 100644 --- a/sys/src/cmd/nusb/kb/kb.c +++ b/sys/src/cmd/nusb/kb/kb.c @@ -522,11 +522,9 @@ putscan(int fd, uchar sc, uchar up) { uchar s[2] = {SCesc1, 0}; - s[1] = sc&Keymask; - if(s[1] == 0) + if(sc == 0) return; - - s[1] |= up; + s[1] = up | sc&Keymask; if(isext(sc)) write(fd, s, 2); else From 4c6c7be688eb2d74a28d3b9f4d1e1b487830ce78 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 18 May 2013 01:46:25 +0200 Subject: [PATCH 34/42] nusb/kb: simplify repeat logic as scancode now contains the info about esc1 extension --- sys/src/cmd/nusb/kb/kb.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/sys/src/cmd/nusb/kb/kb.c b/sys/src/cmd/nusb/kb/kb.c index 987b3942b..0313a465e 100644 --- a/sys/src/cmd/nusb/kb/kb.c +++ b/sys/src/cmd/nusb/kb/kb.c @@ -597,9 +597,7 @@ repeatproc(void* arg) l = recvul(repeatc); continue; } - sc = l; - if((l>>8) != 0) - sc |= 0x80; + sc = l & 0xff; t = Kbdelay; if(alt(a) == 1){ t = Kbrepeat; @@ -622,13 +620,7 @@ stoprepeat(KDev *f) static void startrepeat(KDev *f, uchar sc) { - ulong c; - - if(isext(sc)) - c = SCesc1 << 8 | (sc & 0xff); - else - c = sc; - sendul(f->repeatc, c); + sendul(f->repeatc, sc); } /* From 318cd6fbde65ee5c7a4bd513d185fa57cc61c4cd Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Sun, 19 May 2013 17:50:51 +0200 Subject: [PATCH 35/42] =?UTF-8?q?kbmap/ru:=20fix=20uppercase=20=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys/lib/kbmap/ru | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/lib/kbmap/ru b/sys/lib/kbmap/ru index b6f22458f..a8ac25ffb 100644 --- a/sys/lib/kbmap/ru +++ b/sys/lib/kbmap/ru @@ -176,7 +176,7 @@ 1 47 'М 1 48 'И 1 49 'Т -1 50 'ь +1 50 'Ь 1 51 'Б 1 52 'Ю 1 53 ', From f97798e710929c0acb2b110c1cc16b1b267039a0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 19 May 2013 20:59:55 +0200 Subject: [PATCH 36/42] devsd: don't raise Enomem error if sdmalloc() fails, instead wait for the memory to become available filesystems do not handle i/o errors well (cwfs will abandon the blocks), and temporary exhaustion of kernel memory (because of too many i/o's in parallel) causes read and write on the partition to fail. i think it is better to wait for the memory to become available in this case. the single allocation is at max SDmaxio bytes, which makes it likely to become available. if we havnt even enought fo that, then rebooting the machine would be the best option. (aux/reboot) --- sys/src/9/port/devsd.c | 20 +++++++++++++------- sys/src/9/port/sdscsi.c | 3 +-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sys/src/9/port/devsd.c b/sys/src/9/port/devsd.c index 0c53b6e47..38b9a4548 100644 --- a/sys/src/9/port/devsd.c +++ b/sys/src/9/port/devsd.c @@ -847,9 +847,12 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off) b = (uchar*)a; allocd = 0; }else{ - b = sdmalloc(nb*unit->secsize); - if(b == nil) - error(Enomem); + while((b = sdmalloc(nb*unit->secsize)) == nil){ + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 100); + poperror(); + } + } allocd = 1; } if(waserror()){ @@ -929,8 +932,12 @@ sdrio(SDreq* r, void* a, long n) } data = nil; - if(n > 0 && (data = sdmalloc(n)) == nil) - error(Enomem); + while(n > 0 && (data = sdmalloc(n)) == nil){ + if(!waserror()){ + tsleep(&up->sleep, return0, 0, 100); + poperror(); + } + } if(waserror()){ sdfree(data); r->data = nil; @@ -1484,8 +1491,7 @@ sdwrite(Chan* c, void* a, long n, vlong off) } if(n < 6 || n > sizeof(req->cmd)) error(Ebadarg); - if((req = malloc(sizeof(SDreq))) == nil) - error(Enomem); + req = smalloc(sizeof(SDreq)); req->unit = unit; if(waserror()){ free(req); diff --git a/sys/src/9/port/sdscsi.c b/sys/src/9/port/sdscsi.c index defad953e..e6b53c0b8 100644 --- a/sys/src/9/port/sdscsi.c +++ b/sys/src/9/port/sdscsi.c @@ -384,8 +384,7 @@ scsibio(SDunit* unit, int lun, int write, void* data, long nb, uvlong bno) SDreq *r; long rlen; - if((r = malloc(sizeof(SDreq))) == nil) - error(Enomem); + r = smalloc(sizeof(SDreq)); r->unit = unit; r->lun = lun; again: From 18b8ae56e8f944df3c9078afd294aad03b204557 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 23:55:38 +0200 Subject: [PATCH 37/42] use resrcwait() when waiting for memory to become available use resrcwait() when waiting for memory to become available. randomize the sleep time and properly restore old process status in case tsleep() gets interrupted. --- sys/src/9/port/alloc.c | 2 +- sys/src/9/port/devsd.c | 4 ++-- sys/src/9/port/pgrp.c | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/src/9/port/alloc.c b/sys/src/9/port/alloc.c index 194eb9f37..6e422c9e3 100644 --- a/sys/src/9/port/alloc.c +++ b/sys/src/9/port/alloc.c @@ -175,7 +175,7 @@ smalloc(ulong size) if(v != nil) break; if(!waserror()){ - tsleep(&up->sleep, return0, 0, 100); + resrcwait(0); poperror(); } } diff --git a/sys/src/9/port/devsd.c b/sys/src/9/port/devsd.c index 38b9a4548..5cc44b31c 100644 --- a/sys/src/9/port/devsd.c +++ b/sys/src/9/port/devsd.c @@ -849,7 +849,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off) }else{ while((b = sdmalloc(nb*unit->secsize)) == nil){ if(!waserror()){ - tsleep(&up->sleep, return0, 0, 100); + resrcwait("no memory for sdbio"); poperror(); } } @@ -934,7 +934,7 @@ sdrio(SDreq* r, void* a, long n) data = nil; while(n > 0 && (data = sdmalloc(n)) == nil){ if(!waserror()){ - tsleep(&up->sleep, return0, 0, 100); + resrcwait("no memory for sdrio"); poperror(); } } diff --git a/sys/src/9/port/pgrp.c b/sys/src/9/port/pgrp.c index 22fc78b56..21ac7af86 100644 --- a/sys/src/9/port/pgrp.c +++ b/sys/src/9/port/pgrp.c @@ -306,6 +306,10 @@ resrcwait(char *reason) p = up->psstate; if(reason) { + if(waserror()){ + up->psstate = p; + nexterror(); + } up->psstate = reason; now = seconds(); /* don't tie up the console with complaints */ @@ -314,7 +318,9 @@ resrcwait(char *reason) print("%s\n", reason); } } - - tsleep(&up->sleep, return0, 0, 300); - up->psstate = p; + tsleep(&up->sleep, return0, 0, 100+nrand(200)); + if(reason) { + up->psstate = p; + poperror(); + } } From 926dd18a7a335c231774288702eb35efb9d1058a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 01:03:20 +0200 Subject: [PATCH 38/42] wifi: handle malloc errors in wifiattach() --- sys/src/9/pc/wifi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/src/9/pc/wifi.c b/sys/src/9/pc/wifi.c index 84631a7b9..a23604569 100644 --- a/sys/src/9/pc/wifi.c +++ b/sys/src/9/pc/wifi.c @@ -464,8 +464,14 @@ wifiattach(Ether *ether, void (*transmit)(Wifi*, Wnode*, Block*)) Wifi *wifi; wifi = malloc(sizeof(Wifi)); - wifi->ether = ether; + if(wifi == nil) + error(Enomem); wifi->iq = qopen(8*1024, 0, 0, 0); + if(wifi->iq == nil){ + free(wifi); + error(Enomem); + } + wifi->ether = ether; wifi->transmit = transmit; wifi->status = Snone; From 6ac8a3ca650ead149ed4062a6b06c92a7a961520 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 01:17:38 +0200 Subject: [PATCH 39/42] devether: handle malloc error in etherprobe() --- sys/src/9/pc/devether.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/src/9/pc/devether.c b/sys/src/9/pc/devether.c index 1a5d08bbd..91d1c8574 100644 --- a/sys/src/9/pc/devether.c +++ b/sys/src/9/pc/devether.c @@ -380,6 +380,10 @@ etherprobe(int cardno, int ctlrno) char buf[128], name[32]; ether = malloc(sizeof(Ether)); + if(ether == nil){ + print("etherprobe: no memory for Ether\n"); + return nil; + } memset(ether, 0, sizeof(Ether)); ether->ctlrno = ctlrno; ether->tbdf = BUSUNKNOWN; @@ -460,8 +464,7 @@ etherprobe(int cardno, int ctlrno) ether->limit = bsz; } if(ether->oq == nil) - panic("etherreset %s: can't allocate output queue of %ld bytes", - name, bsz); + panic("etherreset %s: can't allocate output queue of %ld bytes", name, bsz); ether->alen = Eaddrlen; memmove(ether->addr, ether->ea, Eaddrlen); memset(ether->bcast, 0xFF, Eaddrlen); From 5aa2a1a845dd073fdf6c2772f1d0e3e8bc04493c Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Mon, 20 May 2013 13:48:09 +0200 Subject: [PATCH 40/42] =?UTF-8?q?kbmap/ua:=20fix=20uppercase=20=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sys/lib/kbmap/ua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/lib/kbmap/ua b/sys/lib/kbmap/ua index 31f2a5b28..31eebfc2f 100644 --- a/sys/lib/kbmap/ua +++ b/sys/lib/kbmap/ua @@ -176,7 +176,7 @@ 1 47 'М 1 48 'И 1 49 'Т -1 50 'ь +1 50 'Ь 1 51 'Б 1 52 'Ю 1 53 ', From c4f57ff4927986ac2c45e1d4a84ad425a9c9aae9 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 17:32:48 +0200 Subject: [PATCH 41/42] pcuart: malloc error handling, cleanup --- sys/src/9/pc/uartisa.c | 10 ++++++++-- sys/src/9/pc/uartpci.c | 34 ++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/sys/src/9/pc/uartisa.c b/sys/src/9/pc/uartisa.c index f02080d70..f6b590724 100644 --- a/sys/src/9/pc/uartisa.c +++ b/sys/src/9/pc/uartisa.c @@ -18,16 +18,22 @@ uartisa(int ctlrno, ISAConf* isa) Uart *uart; char buf[64]; + uart = malloc(sizeof(Uart)); + if(uart == nil){ + print("uartisa: no memory for Uart\n"); + return nil; + } + io = isa->port; snprint(buf, sizeof(buf), "%s%d", isaphysuart.name, ctlrno); if(ioalloc(io, 8, 0, buf) < 0){ print("uartisa: I/O 0x%uX in use\n", io); + free(uart); return nil; } - uart = malloc(sizeof(Uart)); ctlr = i8250alloc(io, isa->irq, BUSUNKNOWN); - if(uart == nil || ctlr == nil){ + if(ctlr == nil){ iofree(io); free(uart); return nil; diff --git a/sys/src/9/pc/uartpci.c b/sys/src/9/pc/uartpci.c index ec8ce9e94..1f97bd930 100644 --- a/sys/src/9/pc/uartpci.c +++ b/sys/src/9/pc/uartpci.c @@ -21,17 +21,23 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name, char buf[64]; Uart *head, *uart; + head = malloc(sizeof(Uart)*n); + if(head == nil){ + print("uartpci: no memory for Uarts\n"); + return nil; + } + io = p->mem[barno].bar & ~0x01; snprint(buf, sizeof(buf), "%s%d", pciphysuart.name, ctlrno); if(ioalloc(io, p->mem[barno].size, 0, buf) < 0){ print("uartpci: I/O 0x%uX in use\n", io); + free(head); return nil; } - head = uart = malloc(sizeof(Uart)*n); + uart = head; for(i = 0; i < n; i++){ - ctlr = i8250alloc(io, p->intl, p->tbdf); - io += iosize; + ctlr = i8250alloc(io + i*iosize, p->intl, p->tbdf); if(ctlr == nil) continue; @@ -44,16 +50,20 @@ uartpci(int ctlrno, Pcidev* p, int barno, int n, int freq, char* name, (uart-1)->next = uart; uart++; } - - if (head) { - if(perlehead != nil) - perletail->next = head; - else - perlehead = head; - for(perletail = head; perletail->next != nil; - perletail = perletail->next) - ; + if(head == uart){ + iofree(io); + free(head); + return nil; } + + if(perlehead != nil) + perletail->next = head; + else + perlehead = head; + for(perletail = head; perletail->next != nil; + perletail = perletail->next) + ; + return head; } From 58201a67c1cfceda2993979852a367b213abc0ee Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 20 May 2013 17:43:30 +0200 Subject: [PATCH 42/42] uarti8250: print on malloc failure --- sys/src/9/pc/uarti8250.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/src/9/pc/uarti8250.c b/sys/src/9/pc/uarti8250.c index fe14bdf0e..845e4401a 100644 --- a/sys/src/9/pc/uarti8250.c +++ b/sys/src/9/pc/uarti8250.c @@ -621,12 +621,14 @@ i8250alloc(int io, int irq, int tbdf) { Ctlr *ctlr; - if((ctlr = malloc(sizeof(Ctlr))) != nil){ - ctlr->io = io; - ctlr->irq = irq; - ctlr->tbdf = tbdf; + ctlr = malloc(sizeof(Ctlr)); + if(ctlr == nil){ + print("i8250alloc: no memory for Ctlr\n"); + return nil; } - + ctlr->io = io; + ctlr->irq = irq; + ctlr->tbdf = tbdf; return ctlr; }