]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
statctrl: add a version of statctrl using file descriptors
authorBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 26 Dec 2022 14:49:41 +0000 (15:49 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 26 Dec 2022 14:49:41 +0000 (15:49 +0100)
include/statctrl.h
src/statctrl.c

index 060146792d29482aab71ec038d831930ced28689..97bde93d03d3471d77b2d2dd5d534e1e29d194a1 100644 (file)
@@ -27,5 +27,6 @@
 #include <stdbool.h>
 
 bool statctrl(const char *listdir, const char *ctrlstr);
+bool fstatctrl(int, const char *ctrlstr);
 
 #endif /* STATCTRL_H */
index 2c7f7ba9a0d5ca6c634a4b29e43abe18fee36aaf..93e13b7fd1b98d1757d5fbb083c3bde17d50faf2 100644 (file)
 #include "statctrl.h"
 #include "log_error.h"
 
+bool
+fstatctrl(int fd, const char *ctrlstr)
+{
+       char *filename;
+
+       xasprintf(&filename, "%s", ctrlstr);
+       if (faccessat(fd, filename, F_OK, 0) == -1) {
+               if(errno == ENOENT)
+                       return (false);
+               log_error(LOG_ARGS, "Could not stat control/%s. "
+                   "Bailing out.", ctrlstr);
+               exit(EXIT_FAILURE);
+       }
+       return (true);
+}
+
 bool
 statctrl(const char *listdir, const char *ctrlstr)
 {