From: Baptiste Daroussin Date: Mon, 26 Dec 2022 14:49:41 +0000 (+0100) Subject: statctrl: add a version of statctrl using file descriptors X-Git-Tag: RELEASE_1_4_0_a2~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=995fe21daf4b70e25412778f1b354e552fc0dc69;p=thirdparty%2Fmlmmj.git statctrl: add a version of statctrl using file descriptors --- diff --git a/include/statctrl.h b/include/statctrl.h index 06014679..97bde93d 100644 --- a/include/statctrl.h +++ b/include/statctrl.h @@ -27,5 +27,6 @@ #include bool statctrl(const char *listdir, const char *ctrlstr); +bool fstatctrl(int, const char *ctrlstr); #endif /* STATCTRL_H */ diff --git a/src/statctrl.c b/src/statctrl.c index 2c7f7ba9..93e13b7f 100644 --- a/src/statctrl.c +++ b/src/statctrl.c @@ -30,6 +30,22 @@ #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) {