|
Message-Id: <20220122145158.3779-2-ismael@iodev.co.uk> Date: Sat, 22 Jan 2022 15:51:58 +0100 From: Ismael Luceno <ismael@...ev.co.uk> To: musl@...ts.openwall.com Cc: Rich Felker <dalias@...c.org>, Ismael Luceno <ismael@...ev.co.uk> Subject: [PATCH v2 1/2] nftw: implement FTW_CHDIR Signed-off-by: Ismael Luceno <ismael@...ev.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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.