git: 9front

Download patch

ref: c9fdc09053a80ea0ae1c2c1ba5bb4a4597628a2f
parent: a8661e1ec9a43064e15ff28bbd13bdc091c1ff74
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Nov 22 17:28:20 EST 2013

kernel: kproc error and exit

catch the error() that can be thrown by sleep() and tsleep()
in kprocs.

add missing pexit() calls.

always set the freemem argument to pexit() from kproc otherwise
the process gets added to the broken list.

--- a/sys/src/9/port/alarm.c
+++ b/sys/src/9/port/alarm.c
@@ -13,6 +13,9 @@
 	Proc *rp;
 	ulong now;
 
+	while(waserror())
+		;
+
 	for(;;){
 		now = MACHP(0)->ticks;
 		qlock(&alarms);
--- a/sys/src/9/port/devaoe.c
+++ b/sys/src/9/port/devaoe.c
@@ -701,8 +701,10 @@
 	}
 	runlock(&devs);
 	i = Nms - TK2MS(Ticks - starttick);
-	if(i > 0)
+	if(i > 0 && !waserror()){
 		tsleep(&up->sleep, return0, 0, i);
+		poperror();
+	}
 	goto loop;
 }
 
--- a/sys/src/9/port/devsdp.c
+++ b/sys/src/9/port/devsdp.c
@@ -908,6 +908,8 @@
 	int i;
 	Conv *c;
 
+	while(waserror())
+		;
 	for(;;) {
 		tsleep(&up->sleep, return0, 0, 1000);
 		sec = TK2SEC(m->ticks);
--- a/sys/src/9/port/devsegment.c
+++ b/sys/src/9/port/devsegment.c
@@ -530,6 +530,8 @@
 	incref(g->s);
 	up->seg[sno] = g->s;
 
+	while(waserror())
+		;
 	for(done = 0; !done;){
 		sleep(&g->cmdwait, cmdready, g);
 		if(waserror()){
@@ -554,6 +556,8 @@
 		g->cmd = Cnone;
 		wakeup(&g->replywait);
 	}
+
+	pexit("done", 1);
 }
 
 Dev segmentdevtab = {
--- a/sys/src/9/port/random.c
+++ b/sys/src/9/port/random.c
@@ -42,10 +42,11 @@
 	up->basepri = PriNormal;
 	up->priority = up->basepri;
 
+	while(waserror())
+		;
 	for(;;){
-		for(;;)
-			if(++rb.randomcount > 100000)
-				break;
+		if(++rb.randomcount <= 100000)
+			continue;
 		if(anyhigher())
 			sched();
 		if(!rbnotfull(0))
--- a/sys/src/9/port/swap.c
+++ b/sys/src/9/port/swap.c
@@ -147,12 +147,11 @@
 	Segment *s;
 	Proc *p, *ep;
 
-	if(waserror())
-		panic("pager: os error");
-
 	p = proctab(0);
 	ep = &p[conf.nproc];
 
+	while(waserror())
+		;
 loop:
 	up->psstate = "Idle";
 	wakeup(&palloc.r);
--- a/sys/src/9/port/usbehci.c
+++ b/sys/src/9/port/usbehci.c
@@ -2225,6 +2225,8 @@
 	hp = a;
 	ctlr = hp->aux;
 	poll = &ctlr->poll;
+	while(waserror())
+		;
 	for(;;){
 		if(ctlr->nreqs == 0){
 			if(0)ddprint("ehcipoll %#p sleep\n", ctlr->capio);
--