Re: Can we avoid chdir'ing in resolve_symlinks() ?

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Can we avoid chdir'ing in resolve_symlinks() ?
Date: 2022-09-27 01:58:38
Message-ID: CA+hUKG+fnijtDM67A-afBtEPTCSjtVm3CNkxQagDgtmEGNaBZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Sep 4, 2022 at 2:42 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message James Coleman 2022-09-27 02:08:12 Add hint about downloadable logs to CI README
Previous Message Kyotaro Horiguchi 2022-09-27 01:58:30 Re: pgstat: stats added in ReadPageInternal() aren't getting reported via pg_stat_wal