shithub: riscv

Download patch

ref: df6b68092cf2806d7c517e15d2db57b0b19a9788
parent: 91c7e0b127ef494b151fae81d80885fd3d306dc5
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);
--