shithub: bar

Download patch

ref: 595e1948331d24bb2ff576f47b744f938d2d7021
parent: a45b2a4b326a8c80597b06218ac4df100d1c74a2
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Aug 29 15:24:10 EDT 2022

race condition (wctl access) with riow - don't fail if wctl fails to open

--- a/bar.c
+++ b/bar.c
@@ -13,7 +13,7 @@
 	Off = 3,
 };
 
-static int wctl, owidth, width, twidth, bottom, bat, minheight, seplen, sepw, hlitem;
+static int wctl = -1, owidth, width, twidth, bottom, bat, minheight, seplen, sepw, hlitem;
 static char sep[16], bats[16], *aux;
 static char *pos = "rb", *dfmt = "YYYY/MM/DD WW hh:mm:ss", *items[64];
 static int itemw[64], nitems;
@@ -68,6 +68,9 @@
 	char t[64];
 	static int ow, oh;
 
+	if(wctl < 0 && (wctl = open("/dev/wctl", OWRITE)) < 0)
+		return;
+
 	fprint(wctl, bottom ? "bottom" : "top");
 	w = Dx(display->image->r);
 	h = Dy(display->image->r);
@@ -298,8 +301,6 @@
 		Bterm(b);
 	}
 
-	if((wctl = open("/dev/wctl", ORDWR)) < 0)
-		sysfatal("%r");
 	bat = open("/mnt/pm/battery", OREAD);
 	if(initdraw(nil, nil, "bar") < 0)
 		sysfatal("initdraw: %r");