shithub: jacksense

Download patch

ref: eed67adf642ff342fc341eee1b7fdf4d4b54c5d6
parent: c5b6d2a91925b35f9dd88e0da19e24e6bf114d41
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Nov 17 11:28:24 EST 2020

check a few times before trusting the sense

--- a/jacksense.c
+++ b/jacksense.c
@@ -14,7 +14,7 @@
 {
 	int hp, sp, cmd, ctl, vol, lastvol, newvol;
 	int hpsafevol, spsafevol;
-	u32int x, y[4], has, had;
+	u32int x, y[4], has, had, c;
 	Biobuf *b;
 	char *s, *a[16], tmp[32];
 
@@ -61,10 +61,16 @@
 	had = -1;
 	lastvol = (spsafevol < hpsafevol ? spsafevol : hpsafevol)*2/3;
 	for(;;){
+		c = 0;
+again:
 		if(write(cmd, &x, 4) != 4 || read(cmd, y, sizeof(y)) < 4)
 			sysfatal("failed");
 		has = y[0] & (1<<31);
 		if(has != had){
+			if(c++ < 2){
+				sleep(75);
+				goto again;
+			}
 			newvol = lastvol;
 			if(pread(vol, tmp, sizeof(tmp)-1, 0) > 0 && strncmp(tmp, "master ", 7) == 0)
 				lastvol = atoi(tmp+7);