From: Ismael Luceno <ismael@iodev.co.uk>
To: musl@lists.openwall.com
Cc: Rich Felker <dalias@libc.org>, Ismael Luceno <ismael@iodev.co.uk>
Subject: [musl] [PATCH 1/2] nftw: implement FTW_CHDIR
Date: Sat, 22 Jan 2022 14:26:21 +0100 [thread overview]
Message-ID: <20220122132621.32485-2-ismael@iodev.co.uk> (raw)
In-Reply-To: <20220122132621.32485-1-ismael@iodev.co.uk>
Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
src/misc/nftw.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/misc/nftw.c b/src/misc/nftw.c
index 8dcff7fefd2a..0a35686e663d 100644
--- a/src/misc/nftw.c
+++ b/src/misc/nftw.c
@@ -87,6 +87,8 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
DIR *d = fdopendir(dfd);
if (d) {
struct dirent *de;
+ if (flags & FTW_CHDIR)
+ fchdir(dfd);
while ((de = readdir(d))) {
if (de->d_name[0] == '.'
&& (!de->d_name[1]
@@ -123,6 +125,7 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
int r, cs;
size_t l;
char pathbuf[PATH_MAX+1];
+ int orig_dfd;
if (fd_limit <= 0) return 0;
@@ -133,9 +136,16 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
}
memcpy(pathbuf, path, l+1);
+ if (flags & FTW_CHDIR)
+ orig_dfd = open(".", O_CLOEXEC | O_PATH);
+
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
r = do_nftw(pathbuf, fn, fd_limit, flags, NULL);
pthread_setcancelstate(cs, 0);
+ if (flags & FTW_CHDIR) {
+ fchdir(orig_dfd);
+ close(orig_dfd);
+ }
return r;
}
--
2.33.0
next prev parent reply other threads:[~2022-01-22 13:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 13:26 [musl] [PATCH 0/2] nftw: Implement FTW_CHDIR and FTW_ACTIONRETVAL Ismael Luceno
2022-01-22 13:26 ` Ismael Luceno [this message]
2022-01-22 13:26 ` [musl] [PATCH 2/2] nftw: implement FTW_ACTIONRETVAL (GNU extension) Ismael Luceno
2022-01-22 14:47 ` Ismael Luceno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220122132621.32485-2-ismael@iodev.co.uk \
--to=ismael@iodev.co.uk \
--cc=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).