tree-wide: introduce PATH_IN_SET macro
This commit is contained in:
@@ -569,10 +569,10 @@ static int binary_is_good(const char *binary) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return !path_equal(d, "true") &&
|
||||
!path_equal(d, "/bin/true") &&
|
||||
!path_equal(d, "/usr/bin/true") &&
|
||||
!path_equal(d, "/dev/null");
|
||||
return !PATH_IN_SET(d, "true"
|
||||
"/bin/true",
|
||||
"/usr/bin/true",
|
||||
"/dev/null");
|
||||
}
|
||||
|
||||
int fsck_exists(const char *fstype) {
|
||||
|
||||
@@ -48,6 +48,19 @@ bool path_equal(const char *a, const char *b) _pure_;
|
||||
bool path_equal_or_files_same(const char *a, const char *b);
|
||||
char* path_join(const char *root, const char *path, const char *rest);
|
||||
|
||||
/* Note: the search terminates on the first NULL item. */
|
||||
#define PATH_IN_SET(p, ...) \
|
||||
({ \
|
||||
char **s; \
|
||||
bool _found = false; \
|
||||
STRV_FOREACH(s, STRV_MAKE(__VA_ARGS__)) \
|
||||
if (path_equal(p, *s)) { \
|
||||
_found = true; \
|
||||
break; \
|
||||
} \
|
||||
_found; \
|
||||
})
|
||||
|
||||
int path_strv_make_absolute_cwd(char **l);
|
||||
char** path_strv_resolve(char **l, const char *prefix);
|
||||
char** path_strv_resolve_uniq(char **l, const char *prefix);
|
||||
|
||||
+2
-4
@@ -376,8 +376,7 @@ static int mount_add_quota_links(Mount *m) {
|
||||
static bool should_umount(Mount *m) {
|
||||
MountParameters *p;
|
||||
|
||||
if (path_equal(m->where, "/") ||
|
||||
path_equal(m->where, "/usr") ||
|
||||
if (PATH_IN_SET(m->where, "/", "/usr") ||
|
||||
path_startswith(m->where, "/run/initramfs"))
|
||||
return false;
|
||||
|
||||
@@ -408,8 +407,7 @@ static int mount_add_default_dependencies(Mount *m) {
|
||||
* Also, don't bother with anything mounted below virtual
|
||||
* file systems, it's also going to be virtual, and hence
|
||||
* not worth the effort. */
|
||||
if (path_equal(m->where, "/") ||
|
||||
path_equal(m->where, "/usr") ||
|
||||
if (PATH_IN_SET(m->where, "/", "/usr") ||
|
||||
path_startswith(m->where, "/run/initramfs") ||
|
||||
path_startswith(m->where, "/proc") ||
|
||||
path_startswith(m->where, "/sys") ||
|
||||
|
||||
@@ -90,6 +90,12 @@ static void test_path(void) {
|
||||
assert_se(path_equal(path_kill_slashes(p2), "/aaa/./ccc"));
|
||||
assert_se(path_equal(path_kill_slashes(p3), "/./"));
|
||||
}
|
||||
|
||||
assert_se(PATH_IN_SET("/bin", "/", "/bin", "/foo"));
|
||||
assert_se(PATH_IN_SET("/bin", "/bin"));
|
||||
assert_se(PATH_IN_SET("/bin", "/foo/bar", "/bin"));
|
||||
assert_se(PATH_IN_SET("/", "/", "/", "/foo/bar"));
|
||||
assert_se(!PATH_IN_SET("/", "/abc", "/def"));
|
||||
}
|
||||
|
||||
static void test_find_binary(const char *self) {
|
||||
|
||||
Reference in New Issue
Block a user