|
Message-ID: <YHPsc9nu0crZ5yKc@atmark-techno.com> Date: Mon, 12 Apr 2021 15:45:07 +0900 From: Dominique Martinet <dominique.martinet@...ark-techno.com> To: Ariadne Conill <ariadne@...eferenced.org> Cc: musl@...ts.openwall.com Subject: Re: [PATCH] nftw: implement FTW_ACTIONRETVAL Hi, Ariadne Conill wrote on Mon, Apr 12, 2021 at 12:09:47AM -0600: > I'm not an expert on the nftw APIs, so please be patient. Thanks for the reply. I'm in no particular hurry, as long as I know I'm not ignored :) It's not always obvious on big lists, so sorry for my tone. > > +#ifdef _GNU_SOURCE > > +#define FTW_ACTIONRETVAL 0x10 > > +#define FTW_CONTINUE 0 > > +#define FTW_STOP 1 > > It would be nice to document why FTW_CONTINUE and FTW_STOP were added as > constants, since the original implementation did not use them. I found > myself quite confused, since the code below did not reference either of > these constants and had to look up the spec for the nftw API. This could be > done in the commit message, it's just helpful for understanding the context. That's a good point, the code does not reference these because it just somehow works out with these value, but I actually have no idea what to use as the spec myself... I based myself on the linux man pages[1], which only refers to various versions of POSIX, but as far as I can see these do not define any spec for FTW_ACTIONRETVAL -- so where is the source of truth? glibc? [1] https://man7.org/linux/man-pages/man3/nftw.3.html If you have something to use as reference I can add it to the commit message for v2, yes. > > diff --git a/src/misc/nftw.c b/src/misc/nftw.c > > index 8dcff7fefd2a..2994968dcbbe 100644 > > --- a/src/misc/nftw.c > > +++ b/src/misc/nftw.c > > @@ -8,6 +8,10 @@ > > #include <limits.h> > > #include <pthread.h> > > > > +#define FTW_ACTIONRETVAL 0x10 > > +#define FTW_SKIP_SUBTREE 2 > > +#define FTW_SKIP_SIBLINGS 3 > > + > > struct history > > { > > struct history *chain; > > @@ -100,6 +104,12 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, > > path[j]='/'; > > strcpy(path+j+1, de->d_name); > > if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { > > + if (flags & FTW_ACTIONRETVAL) { > > Why not set r to zero here? It would allow you to remove the next part > entirely. I'm sorry, I'm not sure what 'the next part' refers to here. If it's the two break/continue checks, the continue check could be be skipped by making fn return value return 0 if retval is set and r was FTW_SKIP_SUBTREE; but FTW_SKIP_SIBLINGS would have to stay, so the code would be half simplified at the cost of adding extra checks for both fn calls to fix the return value. If it's the part in nftw itself (I guess that's what you meant), then unfortunately that's not true if the function would return SKIP_SIBLING or SKIP_SUBTREE for the top level do_nftw() call. That's about just as corner case as it can get, but I implemented this comparing what glibc returns for various corner cases and glibc's nftw() returns 0 if the callback function returns FTW_SKIP_SIBLINGS or SUBTREE on its first invocation... Which would no longer be the case for us, hence the extra check. I'm not sure how much musl cares about compat there, the man page does not describe what nftw() should return if the callbacks returned these requests. I personally think asking to skip the first directory is borderline invalid usage, but if we skip it nftw worked as intended so it's a success and we should return 0? I guess... Well, no strong feeling either way, happy to set r to 0 here (after the two checks) and skip the last cleanu check in nftw(). Thanks, -- Dominique
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.