diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-23 22:18:31 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-24 09:34:10 +0100 |
commit | aa3cc58a9f988fb8086c8f38cd25a95819a2c846 (patch) | |
tree | 517f11971eaa1139b68c160fed80c5b8651188d7 | |
parent | 98503c6d0cae795be89efd74ccab821729c2143a (diff) | |
download | systemd-aa3cc58a9f988fb8086c8f38cd25a95819a2c846.tar.gz |
recurse-dir: give callers of recurse_dir_at() control over path prefix
One of the niceties of recurse_dir()/recurse_dir_at() is that the path
argument is decoration, it's not used for actually accessing the fs in
anyway. That's very handy in environments where chroots and relative
paths are used, as we can path in any path we like and the recursion
function will suffix with whatever it discovers but will not try to make
sense of the prefix you pass.
This works great, except that the recurse_dir_at() wrapper broke that:
it adjusted the path if NULL to "." simply for the sake of making
openat() on the top work. Let's make this adjustment more local and do
it only for the openat() itself, and otherwise pass the path through the
way we got it. This means: if a caller really wants the paths that are
concatenated to start with a "." it can just pass that. This way the
caller gets full control back of the path prefix. Win!
Note that all current users of recurse_dir_at() don't pass NULL as
second arg, hence this check is without any real effect for now. It's
preparation for future uses however.
-rw-r--r-- | src/basic/recurse-dir.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/src/basic/recurse-dir.c b/src/basic/recurse-dir.c index d1fee91c32..efa1797b7b 100644 --- a/src/basic/recurse-dir.c +++ b/src/basic/recurse-dir.c @@ -444,10 +444,7 @@ int recurse_dir_at( assert(atfd >= 0 || atfd == AT_FDCWD); assert(func); - if (!path) - path = "."; - - fd = openat(atfd, path, O_DIRECTORY|O_CLOEXEC); + fd = openat(atfd, path ?: ".", O_DIRECTORY|O_CLOEXEC); if (fd < 0) return -errno; |