From b6cf41ab77a4324b4f4cf0bc9e3d82a5fef9ebd4 Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Sat, 16 Oct 2021 17:03:31 -0400 Subject: Import refactored xdg.c from pounce --- log.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'log.c') 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 } -- cgit 1.4.1-2-gfad0