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.
This commit is contained in:
C. McEnroe 2021-09-26 17:39:08 -04:00
parent bdcb9ab46f
commit f346f61ea0
1 changed files with 4 additions and 3 deletions

View File

@ -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]);
}