summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-18 14:20:49 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commite5e0c80fdfa8861931df799574d5a60c96b6aa13 (patch)
tree3ff055d308feb83a85c3d8a2edd0eb9ebcfd42a4 /src/basic/fs-util.c
parentd1dbf40d47cfa883c4c9fa264dfd84cd57a03b85 (diff)
util-lib: introduce new empty_or_root() helper (#8746)
We check the same condition at various places. Let's add a trivial, common helper for this, and use it everywhere. It's not going to make things much faster or much shorter, but I think a lot more readable
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 858441c94..5bf1413c1 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -579,10 +579,6 @@ int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
}
#endif // 0
-static bool noop_root(const char *root) {
- return isempty(root) || path_equal(root, "/");
-}
-
static bool safe_transition(const struct stat *a, const struct stat *b) {
/* Returns true if the transition from a to b is safe, i.e. that we never transition from unprivileged to
* privileged files or directories. Why bother? So that unprivileged code can't symlink to privileged files
@@ -633,7 +629,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
* specified path. */
/* A root directory of "/" or "" is identical to none */
- if (noop_root(original_root))
+ if (empty_or_root(original_root))
original_root = NULL;
if (!original_root && !ret && (flags & (CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_OPEN)) == CHASE_OPEN) {
@@ -718,7 +714,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
/* If we already are at the top, then going up will not change anything. This is in-line with
* how the kernel handles this. */
- if (isempty(done) || path_equal(done, "/"))
+ if (empty_or_root(done))
continue;
parent = dirname_malloc(done);
@@ -904,7 +900,7 @@ int chase_symlinks_and_open(
if (chase_flags & CHASE_NONEXISTENT)
return -EINVAL;
- if (noop_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
+ if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
/* Shortcut this call if none of the special features of this call are requested */
r = open(path, open_flags);
if (r < 0)
@@ -944,7 +940,7 @@ int chase_symlinks_and_opendir(
if (chase_flags & CHASE_NONEXISTENT)
return -EINVAL;
- if (noop_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
+ if (empty_or_root(root) && !ret_path && (chase_flags & (CHASE_NO_AUTOFS|CHASE_SAFE)) == 0) {
/* Shortcut this call if none of the special features of this call are requested */
d = opendir(path);
if (!d)