Od: "René Scharfe" <[email protected]>
Do: "Zenobiusz Kunegunda" <[email protected]>;
Wysłane: 22:31 Środa 2017-03-15
Temat: Re: fatal: Could not get current working directory: Permission denied |
affected 2.10,2.11,2.12, but not 1.9.5 |
>
> > Am 15.03.2017 um 10:44 schrieb Zenobiusz Kunegunda:
>> $ git bisect bad
>> 7333ed1788b4f2b162a35003044d77a716732a1f is the first bad commit
>> commit 7333ed1788b4f2b162a35003044d77a716732a1f
>> Author: René Scharfe
>> Date: Mon Jul 28 20:26:40 2014 +0200
>>
>> setup: convert setup_git_directory_gently_1 et al. to strbuf
>
> That's what I half-suspected, and I think by now I got an idea. Here's
> a test program:
>
> #include
> #include
> #include
> #include
> #include
>
> int main(int argc, char **argv)
> {
> char buf[PATH_MAX];
> int last_errno = 0;
> size_t len;
>
> for (len = 0; len <= PATH_MAX; len++) {
> errno = 0;
> getcwd(buf, len);
> if (errno != last_errno) {
> printf("len = %lu, errno = %d, %s\n",
> len, errno, strerror(errno));
> }
> last_errno = errno;
> }
> return 0;
> }
>
> It runs getcwd(2) with buffer sizes from 0 to PATH_MAX and reports when
> the error code changes along the way. Let's call it test_getcwd. And
> here's what I get on FreeBSD 10.3:
>
> $ mkdir /tmp/a
> $ cd /tmp/a
>
> $ chmod 100 /tmp/a
> $ test_getcwd
> len = 0, errno = 22, Invalid argument
> len = 1, errno = 34, Result too large
> len = 7, errno = 0, No error: 0
>
> $ chmod 000 /tmp/a
> $ test_getcwd
> len = 0, errno = 22, Invalid argument
> len = 1, errno = 34, Result too large
> len = 2, errno = 13, Permission denied
> len = 7, errno = 0, No error: 0
>
> So if we don't have execute permission and our buffer is at least one
> char long but still too small then we get EACCES (13). If we don't have
> read permissions and our buffer is big enough then the call succeeds.
> strbuf_getcwd() expects to get ERANGE (34) and nothing else when the
> buffer is too small.
>
> I'd say it's a bug in FreeBSD -- reporting permission denied or success
> based on the size of the supplied buffer makes no sense to me, at least.
>
> The initial buffer size used by strbuf_getcwd() is 128, so you should be
> fine as long as the absolute path to your repository is shorter than
> that. You should also be fine if you have execute permissions on the
> directory.
>
> And here I'm puzzled again -- you probably have sufficient permissions
> set up for your user, right? What does the test program report for your
> problematic repository and its parent directories?
>
> René
>
>
This program produces same errors I get from git in every directory . But no
errors at all when run as root. Here is example when run as reular user.
$ getcwdtest
len = 0, errno = 22, Invalid argument
len = 1, errno = 34, Result too large
len = 2, errno = 13, Permission denied
len = 19, errno = 0, No error: 0
$ mkdir testdir
$ cd testdir/
$ getcwdtest
len = 0, errno = 22, Invalid argument
len = 1, errno = 34, Result too large
len = 9, errno = 13, Permission denied
len = 27, errno = 0, No error: 0
But when run as root there is no permission denied errors. Filesystem is ZFS.