diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-07-07 02:07:39 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-07-07 02:07:39 +0200 |
commit | 8092a428d40ac682df9e80c36988043854579679 (patch) | |
tree | 789262689c0eddf1deabfc01294b36140bee65a6 /src/util.c | |
parent | 31a5f880cf7a742e63a81bacef681939ee4e6616 (diff) |
path,unit: support globbing in conditions and path units
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 344b869c8c..356b4f9de2 100644 --- a/src/util.c +++ b/src/util.c @@ -53,6 +53,7 @@ #include <sys/capability.h> #include <sys/time.h> #include <linux/rtc.h> +#include <glob.h> #include "macro.h" #include "util.h" @@ -5238,6 +5239,30 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h return 0; } +int glob_exists(const char *path) { + glob_t g; + int r, k; + + assert(path); + + zero(g); + errno = 0; + k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); + + if (k == GLOB_NOMATCH) + r = 0; + else if (k == GLOB_NOSPACE) + r = -ENOMEM; + else if (k == 0) + r = !strv_isempty(g.gl_pathv); + else + r = errno ? -errno : -EIO; + + globfree(&g); + + return r; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", |