]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Workaround broken O_SEARCH in musl
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 8 Jan 2025 17:08:08 +0000 (19:08 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 8 Jan 2025 17:20:28 +0000 (19:20 +0200)
Testing with musl 1.2.5 and Linux 6.12, O_SEARCH doesn't result
in a file descriptor that works with fsync() although it should work.
See the added comment.

The same issue affected gzip --synchronous:

    https://bugs.gnu.org/75405

Thanks to Paul Eggert.

src/xz/file_io.c

index 9958b6890f19bb0bf74af1c4ce2a486ab9370dc0..97d6b40102e0527d3a342a6c2fd65ae183c69c51 100644 (file)
@@ -69,6 +69,17 @@ static bool warn_fchown;
 #      define O_NOCTTY 0
 #endif
 
+// In musl 1.2.5, O_SEARCH is defined to O_PATH. As of Linux 6.12,
+// a file descriptor from open("dir", O_SEARCH | O_DIRECTORY) cannot be
+// used with fsync() (fails with EBADF). musl 1.2.5 doesn't emulate it
+// using /proc/self/fd. Even if it did, it might need to do it with
+// fd = open("/proc/...", O_RDONLY); fsync(fd); which fails if the
+// directory lacks read permission. Since we need a working fsync(),
+// O_RDONLY imitates O_SEARCH better than O_PATH.
+#if defined(O_SEARCH) && defined(O_PATH) && O_SEARCH == O_PATH
+#      undef O_SEARCH
+#endif
+
 #ifndef O_SEARCH
 #      define O_SEARCH O_RDONLY
 #endif