public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 1/4] Sync getcwd with gnulib
Date: Thu, 27 Aug 2020 07:53:23 -0300	[thread overview]
Message-ID: <CAMXh4bVDPWMwqu0LHxBfQgmBWDz6txO-d_WX3=mz_zfHibzYSg@mail.gmail.com> (raw)
In-Reply-To: <87ft881p5b.fsf@oldenburg2.str.redhat.com>

On Thu, Aug 27, 2020 at 5:14 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Adhemerval Zanella via Libc-alpha:
>
> > +#if HAVE_MINIMALLY_WORKING_GETCWD
> > +  /* If AT_FDCWD is not defined, the algorithm below is O(N**2) and
> > +     this is much slower than the system getcwd (at least on
> > +     GNU/Linux).  So trust the system getcwd's results unless they
> > +     look suspicious.
> > +
> > +     Use the system getcwd even if we have openat support, since the
> > +     system getcwd works even when a parent is unreadable, while the
> > +     openat-based approach does not.
> > +
> > +     But on AIX 5.1..7.1, the system getcwd is not even minimally
> > +     working: If the current directory name is slightly longer than
> > +     PATH_MAX, it omits the first directory component and returns
> > +     this wrong result with errno = 0.  */
> > +
> > +# undef getcwd
> > +  dir = getcwd_system (buf, size);
> > +  if (dir || (size && errno == ERANGE))
> > +    return dir;
>
> This conflicts with the getcwd_system implementation does not set errno.
>
> > +  /* Solaris getcwd (NULL, 0) fails with errno == EINVAL, but it has
> > +     internal magic that lets it work even if an ancestor directory is
> > +     inaccessible, which is better in many cases.  So in this case try
> > +     again with a buffer that's almost always big enough.  */
> > +  if (errno == EINVAL && buf == NULL && size == 0)
> > +    {
> > +      char big_buffer[BIG_FILE_NAME_LENGTH + 1];
> > +      dir = getcwd_system (big_buffer, sizeof big_buffer);
> > +      if (dir)
> > +        return strdup (dir);
> > +    }
>
> > +          /* When we've iterated through all directory entries without finding
> > +             one with a matching d_ino, rewind the stream and consider each
> > +             name again, but this time, using lstat.  This is necessary in a
> > +             chroot on at least one system (glibc-2.3.6 + linux 2.6.12), where
> > +             .., ../.., ../../.., etc. all had the same device number, yet the
> > +             d_ino values for entries in / did not match those obtained
> > +             via lstat.  */
> > +          if (d == NULL && errno == 0 && use_d_ino)
> > +            {
> > +              use_d_ino = false;
> > +              __rewinddir (dirstream);
> > +              d = __readdir (dirstream);
> > +            }
>
> I'm not sure if it's worthwhile to have such code in glibc.
>
> The generic getcwd isn't used by Hurd, right?  Would it make sense to
> have a trimmed-down Linux implementation as well?

This specific part is not used by glibc, for LIBC my patch sets
HAVE_MINIMALLY_WORKING_GETCWD
explicit to 0. I just added to sync with gnulib implementation and
make future changes less complex
(and it also checks if gnulib code to disable the LIBC part is working
correctly).

  reply	other threads:[~2020-08-27 10:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26 21:02 Adhemerval Zanella
2020-08-26 21:02 ` [PATCH 2/4] linux: Remove __ASSUME_ATFCTS Adhemerval Zanella
2020-08-26 21:02 ` [PATCH 3/4] Use LFS readdir in generic POSIX getcwd [BZ# 22899] Adhemerval Zanella
2020-08-27  9:58   ` Florian Weimer
2020-08-26 21:02 ` [PATCH 4/4] io: Reorganize the getcwd implementation Adhemerval Zanella
2020-08-26 22:39   ` Paul Eggert
2020-08-27 12:35   ` Adhemerval Zanella
2020-08-27 13:21     ` Florian Weimer
2020-08-27 13:40       ` Adhemerval Zanella
2020-08-27 17:29     ` Adhemerval Zanella
2020-08-27 19:20   ` [PATCH v2] " Adhemerval Zanella
2020-08-27 23:44     ` Paul Eggert
2020-08-31 18:27       ` Adhemerval Zanella
2020-08-26 22:39 ` [PATCH 1/4] Sync getcwd with gnulib Paul Eggert
2020-08-27 11:07   ` Adhemerval Zanella
2020-08-27  8:14 ` Florian Weimer
2020-08-27 10:53   ` Adhemerval Zanella [this message]
2020-08-27 10:58     ` Florian Weimer
2020-08-27 11:06       ` Adhemerval Zanella
2020-08-27 11:10         ` Florian Weimer
2020-08-27 11:33           ` Adhemerval Zanella

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='CAMXh4bVDPWMwqu0LHxBfQgmBWDz6txO-d_WX3=mz_zfHibzYSg@mail.gmail.com' \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).