shithub: zuke

Download patch

ref: 7b5192c88829c6f111ee1032c6e5e1f99917f4da
parent: d5f3b567203165fc6bf372ea52f78f828a267fc4
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Jan 28 08:04:33 EST 2021

theming: fix pid reset after postnote, add more error handling

--- a/theme.c
+++ b/theme.c
@@ -26,28 +26,30 @@
 static void
 runpicker(void *x)
 {
-	int *p, f;
+	int *p;
 	char tmp[32];
 
 	snprint(tmp, sizeof(tmp), "-pid %d -dx %d -dy %d", getpid(), 384, 320);
-	newwindow(tmp);
+	if(newwindow(tmp) == 0){
+		p = x;
+		dup(*p, 0); dup(*p, 1); close(*p);
+		close(p[1]);
+		execl("/bin/picker", "picker", nil);
+	}
 
-	p = x;
-	dup(*p, 0); dup(*p, 1); close(*p);
-	close(p[1]);
-	dup(f = open("/dev/null", OWRITE), 2); close(f);
-	execl("/bin/picker", "picker", nil);
-
-	threadexits("exec: %r");
+	fprint(2, "runpicker: %r");
+	threadexits("%r");
 }
 
 void
 themeproc(void *)
 {
-	Biobuf *b;
 	char *s, *v[3];
 	int p[2], n, i;
-	static int pid;
+	static int pid = -1;
+	u32int rgb;
+	Biobuf *b;
+	Image *im;
 
 	threadsetname("themeproc");
 	pipe(p);
@@ -67,9 +69,15 @@
 				if(strcmp(colors[i].id, v[0]) == 0){
 					if(display->locking)
 						lockdisplay(display);
-					freeimage(colors[i].im);
-					colors[i].rgb = strtoul(v[1], nil, 16);
-					colors[i].im = allocimage(display, Rect(0,0,1,1), RGB24, 1, colors[i].rgb<<8 | 0xff);
+					rgb = strtoul(v[1], nil, 16);
+					im = allocimage(display, Rect(0,0,1,1), RGB24, 1, rgb<<8 | 0xff);
+					if(im == nil)
+						fprint(2, "%r\n");
+					else{
+						freeimage(colors[i].im);
+						colors[i].rgb = rgb;
+						colors[i].im = im;
+					}
 					if(display->locking)
 						unlockdisplay(display);
 					themechanged();
@@ -83,6 +91,7 @@
 	}
 	Bterm(b);
 	postnote(PNGROUP, pid, "interrupt");
+	pid = -1;
 
 	threadexits(nil);
 }
@@ -90,8 +99,10 @@
 static int
 loadtheme(char *filename, int init)
 {
-	Biobuf *in;
 	char *s, *v[3];
+	Biobuf *in;
+	u32int rgb;
+	Image *im;
 	int i, n;
 
 	if((in = Bopen(filename, OREAD)) != nil){
@@ -103,9 +114,15 @@
 			if((n = tokenize(s, v, nelem(v))) == 2){
 				for(i = 0; i < nelem(colors); i++){
 					if(strcmp(colors[i].id, v[0]) == 0){
-						freeimage(colors[i].im);
-						colors[i].rgb = strtoul(v[1], nil, 16);
-						colors[i].im = allocimage(display, Rect(0,0,1,1), RGB24, 1, colors[i].rgb<<8 | 0xff);
+						rgb = strtoul(v[1], nil, 16);
+						im = allocimage(display, Rect(0,0,1,1), RGB24, 1, rgb<<8 | 0xff);
+						if(im == nil)
+							fprint(2, "%r\n");
+						else{
+							freeimage(colors[i].im);
+							colors[i].rgb = rgb;
+							colors[i].im = im;
+						}
 						break;
 					}
 				}