summary refs log tree commit diff
diff options
context:
space:
mode:
authorC. McEnroe <june@causal.agency>2020-11-10 15:15:13 -0500
committerC. McEnroe <june@causal.agency>2020-11-10 15:15:43 -0500
commitb7ebd38698c35c23492857f50cbcc6bf124e2757 (patch)
tree48c072337ffb9327fa927f038e2fe7644bffc2ec
parentDo not increment signals (diff)
downloadcatsit-b7ebd38698c35c23492857f50cbcc6bf124e2757.tar.gz
catsit-b7ebd38698c35c23492857f50cbcc6bf124e2757.zip
Refactor unveil calls so errors can be reported properly
-rw-r--r--daemon.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/daemon.c b/daemon.c
index 15c278d..cf7f805 100644
--- a/daemon.c
+++ b/daemon.c
@@ -216,19 +216,23 @@ int main(int argc, char *argv[]) {
 	}
 
 #ifdef __OpenBSD__
-	if (pidPath) {
-		error = unveil(pidPath, "cw");
-		if (error) err(EX_OSERR, "unveil");
+	struct {
+		const char *path;
+		const char *mode;
+	} paths[] = {
+		{ fifoPath, "crw" },
+		{ configPath, "r" },
+		{ "/", "r" },
+		{ "/dev/null", "rw" },
+		{ serviceDir, "r" },
+		{ _PATH_BSHELL, "x" },
+		{ pidPath, "cw" },
+		{ NULL, NULL },
+	};
+	for (size_t i = 0; paths[i].path; ++i) {
+		error = unveil(paths[i].path, paths[i].mode);
+		if (error) err(EX_CANTCREAT, "%s", paths[i].path);
 	}
-	error = unveil(fifoPath, "crw")
-		|| unveil(configPath, "r")
-		|| unveil("/", "r")
-		|| unveil("/dev/null", "rw")
-		|| unveil(serviceDir, "r")
-		|| unveil(_PATH_BSHELL, "x")
-		|| unveil(NULL, NULL);
-	if (error) err(EX_OSERR, "unveil");
-
 	error = pledge(
 		"stdio cpath dpath rpath wpath flock getpw proc exec id", NULL
 	);