git: 9front

Download patch

ref: 87378a033bc405999bcf8c53675f4231dc119672
parent: ccd28c111457d5bdf6ab8ef63b119397d3441756
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Sep 7 21:28:34 EDT 2016

kernel: make sure procalarm() remaining time doesnt become negative

--- a/sys/src/9/port/alarm.c
+++ b/sys/src/9/port/alarm.c
@@ -63,14 +63,20 @@
 	Proc **l, *f;
 	ulong when, old;
 
+	when = MACHP(0)->ticks;
 	old = up->alarm;
-	if(old)
-		old = tk2ms(old - MACHP(0)->ticks);
+	if(old) {
+		old -= when;
+		if((long)old > 0)
+			old = tk2ms(old);
+		else
+			old = 0;
+	}
 	if(time == 0) {
 		up->alarm = 0;
 		return old;
 	}
-	when = ms2tk(time)+MACHP(0)->ticks;
+	when += ms2tk(time);
 	if(when == 0)
 		when = 1;
 
--