mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
To: Ariadne Conill <ariadne@dereferenced.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] nftw: implement FTW_ACTIONRETVAL
Date: Mon, 12 Apr 2021 15:45:07 +0900	[thread overview]
Message-ID: <YHPsc9nu0crZ5yKc@atmark-techno.com> (raw)
In-Reply-To: <70ea894a-a4bf-1ae8-ddce-1393caab9b@dereferenced.org>

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

  reply	other threads:[~2021-04-12  6:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26  5:44 Dominique Martinet
2021-04-12  5:53 ` [musl] " Dominique Martinet
2021-04-12  6:09 ` [musl] " Ariadne Conill
2021-04-12  6:45   ` Dominique Martinet [this message]
2021-04-12 14:17 ` Rich Felker
2021-04-12 23:25   ` Dominique Martinet

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=YHPsc9nu0crZ5yKc@atmark-techno.com \
    --to=dominique.martinet@atmark-techno.com \
    --cc=ariadne@dereferenced.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).