summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-09-26 17:39:08 -0400
committerJune McEnroe <june@causal.agency>2021-09-26 17:39:08 -0400
commitf346f61ea05e3500c37f52f0bfd8ef4754991716 (patch)
tree7709d9f197fea42b8b567fcacaa47a35a1517bea
parentOpenBSD: Simplify pledge(2) and unveil(2) strategy (diff)
downloadcatsit-f346f61ea05e3500c37f52f0bfd8ef4754991716.tar.gz
catsit-f346f61ea05e3500c37f52f0bfd8ef4754991716.zip
Don't parse config until after daemonization
And consequently, until after pledge(2) and unveil(2) on OpenBSD.
Replace parsing before daemonization with a simple check that the
file is readable. There's not much that can go wrong in parsing
anyway.
-rw-r--r--daemon.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/daemon.c b/daemon.c
index 88f59b2..efeaf22 100644
--- a/daemon.c
+++ b/daemon.c
@@ -216,6 +216,9 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	error = access(configPath, R_OK);
+	if (error) err(EX_NOINPUT, "%s", configPath);
+
 	error = access(serviceDir, X_OK);
 	if (error) err(EX_NOINPUT, "%s", serviceDir);
 
@@ -269,9 +272,6 @@ int main(int argc, char *argv[]) {
 	int writer = open(fifoPath, O_WRONLY | O_NONBLOCK | O_CLOEXEC);
 	if (writer < 0) err(EX_CANTCREAT, "%s", fifoPath);
 
-	error = parseConfig(configPath);
-	if (error) return EX_DATAERR;
-
 	if (daemonize) {
 		error = daemon(0, 0);
 		if (error) {
@@ -306,6 +306,7 @@ int main(int argc, char *argv[]) {
 	signal(SIGCHLD, signalHandler);
 	signal(SIGINFO, signalHandler);
 
+	parseConfig(configPath);
 	for (size_t i = 0; i < services.len; ++i) {
 		serviceStart(&services.ptr[i]);
 	}