Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for utimensat as an alternative to lutimes #11751

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

artemist
Copy link
Member

OpenBSD doesn't support lutimes, but does support utimensat which subsumes it. In fact, all the BSDs, Linux, and newer macOS all support it. So lets make this our first choice for the implementation.

In addition, let's get rid of the lutimes ENOSYS special case. The Linux manpage says

ENOSYS

The kernel does not support this call; Linux 2.6.22 or later is
required.

which I think is the origin of this check, but that's a very old version of Linux at this point. The code can be simplified a lot of we drop support for it here (as we've done elsewhere, anyways).

Motivation

We've been working towards a more functional nix on various *BSD systems. This fixes a nonessential feature, and is useful i combination with #11750 which fixes build on OpenBSD

Context

OpenBSD does not support the lutimes syscall to mtime of a symlink. However, it supports the common utimensat syscall that allows setting mtimes with nanosecond precision for symlinks.

As part of the change, @Ericson2314 noticed that lutimes has been in Linux for 17 years and the fallback is no longer required, making it easier to clean up the code.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

OpenBSD doesn't support `lutimes`, but does support `utimensat` which
subsumes it. In fact, all the BSDs, Linux, and newer macOS all support
it. So lets make this our first choice for the implementation.

In addition, let's get rid of the `lutimes` `ENOSYS` special case. The
Linux manpage says

> ENOSYS
>
> The kernel does not support this call; Linux 2.6.22 or later is
> required.

which I think is the origin of this check, but that's a very old version
of Linux at this point. The code can be simplified a lot of we drop
support for it here (as we've done elsewhere, anyways).

Co-Authored-By: John Ericson <John.Ericson@Obsidian.Systems>
};
if (utimensat(AT_FDCWD, path.c_str(), times, AT_SYMLINK_NOFOLLOW) == -1)
throw SysError("changing modification time of '%s' (using `utimensat`)", path);
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to keep lutimes if all modern OSes support utimensat?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine either way. I guess I would lean towards removing it in a separate commit/PR so if we need it back it's an easier revert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with separating. It may have some knock-on implications like increasing the minimum macOS version enforced in the installer (I think utimensat was added in 10.13).

@Ericson2314 Ericson2314 merged commit 63f9159 into NixOS:master Oct 27, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants