summary refs log tree commit diff
path: root/log.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-10-16 17:03:31 -0400
committerJune McEnroe <june@causal.agency>2021-10-16 17:03:31 -0400
commitb6cf41ab77a4324b4f4cf0bc9e3d82a5fef9ebd4 (patch)
tree45fb76bbe6f5037d5827130c89e63e6d9cc22c16 /log.c
parentchroot: Factor out and add OpenBSD build (diff)
downloadcatgirl-b6cf41ab77a4324b4f4cf0bc9e3d82a5fef9ebd4.tar.gz
catgirl-b6cf41ab77a4324b4f4cf0bc9e3d82a5fef9ebd4.zip
Import refactored xdg.c from pounce
Diffstat (limited to 'log.c')
-rw-r--r--log.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/log.c b/log.c
index c13293a..32d771f 100644
--- a/log.c
+++ b/log.c
@@ -47,10 +47,15 @@
 static int logDir = -1;
 
 void logOpen(void) {
-	dataMkdir("");
-	const char *path = dataMkdir("log");
-	logDir = open(path, O_RDONLY | O_CLOEXEC);
-	if (logDir < 0) err(EX_CANTCREAT, "%s", path);
+	char buf[PATH_MAX];
+	int error = mkdir(dataPath(buf, sizeof(buf), "", 0), S_IRWXU);
+	if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", buf);
+
+	error = mkdir(dataPath(buf, sizeof(buf), "log", 0), S_IRWXU);
+	if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", buf);
+
+	logDir = open(buf, O_RDONLY | O_CLOEXEC);
+	if (logDir < 0) err(EX_CANTCREAT, "%s", buf);
 
 #ifdef __FreeBSD__
 	cap_rights_t rights;
@@ -58,7 +63,7 @@ void logOpen(void) {
 		&rights, CAP_MKDIRAT, CAP_CREATE, CAP_WRITE,
 		/* for fdopen(3) */ CAP_FCNTL, CAP_FSTAT
 	);
-	int error = caph_rights_limit(logDir, &rights);
+	error = caph_rights_limit(logDir, &rights);
 	if (error) err(EX_OSERR, "cap_rights_limit");
 #endif
 }