aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6f/s6f_confdir_open.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-06-18 18:58:34 +0000
committerLaurent Bercot <ska@appnovation.com>2025-06-18 18:58:34 +0000
commit8a6eaed305dbe4ec6a87fe37000f7461bf563937 (patch)
treec80d489ba6852447f56eb805e0ada4005b94b89f /src/libs6f/s6f_confdir_open.c
parent83622b9b37821cccab3c535209200b9ccd2ba6a3 (diff)
downloads6-frontend-8a6eaed305dbe4ec6a87fe37000f7461bf563937.tar.gz
Add a lot of stuff, implement basic service_start
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6f/s6f_confdir_open.c')
-rw-r--r--src/libs6f/s6f_confdir_open.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libs6f/s6f_confdir_open.c b/src/libs6f/s6f_confdir_open.c
new file mode 100644
index 0000000..8e0838f
--- /dev/null
+++ b/src/libs6f/s6f_confdir_open.c
@@ -0,0 +1,38 @@
+/* ISC license. */
+
+#include <skalibs/bsdsnowflake.h>
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <skalibs/stat.h>
+#include <skalibs/strerr.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/unix-transactional.h>
+
+#include "s6f.h"
+
+int s6f_confdir_open (char const *s, int flagcreate)
+{
+ struct stat st ;
+ int fd = open_read(s) ;
+ if (fd == -1)
+ {
+ if (errno != ENOENT || !flagcreate)
+ strerr_diefu3sys(111, "open ", s, " for reading") ;
+ if (flagcreate)
+ {
+ s6f_mkdirp(s, 02755) ;
+ fd = open_read(s) ;
+ if (fd == -1)
+ strerr_diefu3sys(111, "open ", s, " for reading") ;
+ }
+ }
+ if (fstat(fd, &st) == -1)
+ strerr_diefu2sys(111, "fstat ", s) ;
+ if (!S_ISDIR(st.st_mode))
+ strerr_dief2x(111, s, " is not a directory") ;
+ if (access_at(fd, ".", R_OK|W_OK, 1) == -1)
+ strerr_diefu2sys(111, "access ", s) ;
+ return fd ;
+}