Hello Paul,
On Fri, Oct 31, 2025 at 02:54:37PM -0600, Paul Eggert wrote:
> On 10/31/25 13:00, Pavel Cahyna wrote:
>
> > Perhaps, since gnulib already provides openat(), the O_RESOLVE_BENEATH
> > flag (from FreeBSD) could be added to it?
>
> That might be cleaner, yes. Though I expect it should be a new module
> resolve-beneath, that adds support for the O_RESOLVE_BENEATH flag to openat,
> and similarly adds AT_RESOLVE_BENEATH support to fstatat etc.
I see that you added openat2 in commit
0b97ffdf32bdab909d02449043447237273df75e and that in tar tests commit
2e243986c70eea455a1cc59b12634a00aa1c93b1 you accounted for the errno
difference between FreeBSD and Linux when *BENEATH leads to failure.
I think though that the latter shows that the errno reported by the
openat2 module should be more consistent. I.e. that ENOTCAPABLE should
be translated to EXDEV. Otherwise, a caller that needs a more
sophisticated error handling than just perror(3) or strerror(3) must do
something like
fd = openat2( (...) );
if (fd < 0)
{
if (errno == EXDEV
#ifdef ENOTCAPABLE
|| errno == ENOTCAPABLE
#endif
)
{
/* RESOLVE_BENEATH error handling */
which looks needlessly complicated. IOW, I am afraid that on FreeBSD
openat2 becomes a Frankenmonster with Linux-like arguments, but
FreeBSD-like error reporting.
(Of course, the "s/: Cross-device link$/: Invalid cross-device link/"
part of the latter commit needs to be preserved.)
Regards, Pavel