git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] wrapper: Fix a errno discrepancy on NetBSD.

From
Junio C Hamano <gitster@pobox.com>
Date
May 5, 2025, 15:43 UTC
Message-ID
<xmqqtt5zoyg9.fsf@gitster.g>
In-Reply-To
<20250503133158.GA4450@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 10 quoted lines
> That changed in cfea2f2da8 (packed-backend: check whether the
> "packed-refs" is regular file, 2025-02-28), which uses open_nofollow()
> to check for symlinks while we open it. But it feels like it would be
> more direct to just lstat() the file in the first place (which we end up
> doing anyway to check for other things besides symlinks!).
> ...
> It's not as "atomic" as open_nofollow() and fstat(), but I don't think
> we care about that for fsck. This is about consistency checking, not
> trying to beat races against active adversaries (not to mention that our
> open_nofollow() is best-effort anyway, and may be racy).

True. Atomicity, which the use of open_nofollow() and fstat() tries to achieve, may not matter in fsck. We can think of the use of open_nofollow() in this particular codepath merely as a convenient helper function, and I do not think we have any problem with such a helper function.

But open_nofollow() and its emulation can be called from other codepaths that may care about atomicity, and I am not sure what our attitude towards atomicity requirements vs platform capabilities should be.

If an atomicity (or any other) requirement in a particular codepath has a simple and obvious way to solve on common platforms, but that the mechanism to implement the simple and obvious way is unavailable on other platforms, where does it lead us?

For some kind of requirements, we can treat it merely as a quality of implementation issue, similar to how finalize_object_file() ideally wants to do the create(TMP) then link(TMP->FINAL) then unlink(TMP) dance (because we want to detect collisions when able) but has fallback implementation to create(TMP) then rename(TMP->FINAL) (which punts on collision detection) on platforms where the preferred way does not work. It falls into this category, I would think, to think of use of open_nofollow() in this codepath as a mere helper function that makes the code in fsck shorter.

But for other kind of requirements, we want to fulfill them on all platforms that we claim to support. Using open_nofollow() to achieve hard atomicity requirement would be a bug in such a situation. Should we somehow warn our developers against its use?

Idealists in us first try hard to find the right abstraction that would work everywhere, and use compat/ layer to implement that abstraction, but we of course are often not successful, and end up with a series of #ifdef for pieces of platform-specific code in fairly higher layer. It feels that open_nofollow() that is not necesarily atomic is the latter but that is done at a level that is a bit too low. I dunno.

Previous: Collin FunkNext: Jeff King
Message 13 of 25 in “wrapper: Fix a errno discrepancy on NetBSD.”
  1. wrapper: Fix a errno discrepancy on NetBSD.Collin Funk, May 2, 2025
  2. brian m. carlsonMay 3, 2025
  3. Junio C HamanoMay 3, 2025
  4. Collin FunkMay 3, 2025
  5. Junio C HamanoMay 3, 2025
  6. Collin FunkMay 3, 2025
  7. Jeff KingMay 3, 2025
  8. shejialuoMay 3, 2025
  9. Jeff KingMay 3, 2025
  10. Patrick SteinhardtMay 5, 2025
  11. shejialuoMay 5, 2025
  12. Collin FunkMay 3, 2025
  13. Junio C HamanoMay 5, 2025
  14. Jeff KingMay 5, 2025
  15. shejialuoMay 6, 2025
  16. Junio C HamanoMay 6, 2025
  17. wrapper: NetBSD gives EFTYPE and FreeBSD gives EMFILE where POSIX uses ELOOPCollin Funk, May 3, 2025
  18. brian m. carlsonMay 3, 2025
  19. Collin FunkMay 3, 2025
  20. Patrick SteinhardtMay 5, 2025
  21. Junio C HamanoMay 5, 2025
  22. Collin FunkMay 6, 2025
  23. Patrick SteinhardtMay 6, 2025
  24. wrapper: NetBSD gives EFTYPE and FreeBSD gives EMFILE where POSIX uses ELOOPCollin Funk, May 6, 2025
  25. Patrick SteinhardtMay 6, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.