Re: Can we avoid chdir'ing in resolve_symlinks() ? - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: Can we avoid chdir'ing in resolve_symlinks() ?
Date
Msg-id CA+hUKG+fnijtDM67A-afBtEPTCSjtVm3CNkxQagDgtmEGNaBZg@mail.gmail.com
Whole thread Raw
In response to Re: Can we avoid chdir'ing in resolve_symlinks() ?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Can we avoid chdir'ing in resolve_symlinks() ?
List pgsql-hackers
On Sun, Sep 4, 2022 at 2:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Here's a draft patch for this.  It seems to work on Linux,
> but the Windows code is just speculation.  In particular,
> I did
>
>         path = _fullpath(NULL, fname, 0);
>         if (path == NULL)
>                 _dosmaperr(GetLastError());
>
> but I'm not really sure that the _dosmaperr bit is needed,
> because the _fullpath man page I found makes reference to
> setting "errno" [1].  It's likely to be hard to test, because
> most of the possible error cases should be nigh unreachable
> in our usage; we already know the input is a valid reference
> to an executable file.

I tried lots of crazy stuff[1] to try to get an error out of this
thing, but came up empty handed.  Unlike realpath(), _fullpath()
doesn't resolve symlinks (or junctions), so I guess there's less to go
wrong.  It still needs the present working directory, which is a
per-drive concept on this OS, but even bogus drives don't seem to
produce an error (despite what the manual says).

I'd still lean towards assuming errno is set, given that the manual
references errno and not GetLastError().  Typical manual pages
explicitly tell you when GetLastError() has the error (example:
GetFullPathName(), for which this might be intended as a more Unix-y
wrapper, but even if so there's nothing to say that _fullpath() can't
set errno directly itself, in which case you might clobber it that
way).

[1] https://cirrus-ci.com/task/4935917730267136?logs=main



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: pgstat: stats added in ReadPageInternal() aren't getting reported via pg_stat_wal
Next
From: James Coleman
Date:
Subject: Add hint about downloadable logs to CI README