shithub: neindaw

Download patch

ref: db328d440497a5d2b0292b55f9ceb77e5eb9a0e8
parent: 0da73060a5e334ea86b0ad4641c6144d97d813e7
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Mar 20 18:45:37 EDT 2020

cfg: use dirreadall in order to have less fds

--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -154,25 +154,28 @@
 	}
 	ui->label = strdup(s != nil ? s + 1 : ui->path);
 
-	while ((n = dirread(f, &dirs)) > 0) {
-		for (i = 0; i < n; i++) {
-			name = dirs[i].name;
-			s = smprint("%s/%s", path, name);
-			if (strcmp(name, "metadata") == 0) {
-				readmeta(ui, s);
-			} else if (strcmp(name, "clone") == 0) {
-				ui->flags |= Hasclone;
-			} else if (strcmp(name, "ctl") == 0) {
-				ui->ctl = open(s, ORDWR);
-				readctl(ui);
-			} else if (dirs[i].mode & DMDIR) {
-				ui->child = realloc(ui->child, (ui->numchild+1) * sizeof(*ui->child));
-				ui->child[ui->numchild++] = newui(s);
-			}
-			free(s);
+	n = dirreadall(f, &dirs);
+	close(f);
+	if (n < 0)
+		fprint(2, "newui: %s: %r", s);
+
+	for (i = 0; i < n; i++) {
+		name = dirs[i].name;
+		s = smprint("%s/%s", path, name);
+		if (strcmp(name, "metadata") == 0) {
+			readmeta(ui, s);
+		} else if (strcmp(name, "clone") == 0) {
+			ui->flags |= Hasclone;
+		} else if (strcmp(name, "ctl") == 0) {
+			ui->ctl = open(s, ORDWR);
+			readctl(ui);
+		} else if (dirs[i].mode & DMDIR) {
+			ui->child = realloc(ui->child, (ui->numchild+1) * sizeof(*ui->child));
+			ui->child[ui->numchild++] = newui(s);
 		}
+		free(s);
 	}
-	close(f);
+	free(dirs);
 
 	return ui;
 }