GNU bug report logs - #75405
gzip --synchronous doesn't work with musl

Previous Next

Package: gzip;

Reported by: Lasse Collin <lasse.collin <at> tukaani.org>

Date: Mon, 6 Jan 2025 13:30:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Lasse Collin <lasse.collin <at> tukaani.org>
Subject: bug#75405: closed (Re: bug#75405: gzip --synchronous doesn't work
 with musl)
Date: Fri, 10 Jan 2025 18:20:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#75405: gzip --synchronous doesn't work with musl

which was filed against the gzip package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 75405 <at> debbugs.gnu.org.

-- 
75405: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75405
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Lasse Collin <lasse.collin <at> tukaani.org>
Cc: 75405-done <at> debbugs.gnu.org
Subject: Re: bug#75405: gzip --synchronous doesn't work with musl
Date: Fri, 10 Jan 2025 10:19:32 -0800
Thanks, I installed that test. Marking this gzip bug as done.

[Message part 3 (message/rfc822, inline)]
From: Lasse Collin <lasse.collin <at> tukaani.org>
To: bug-gzip <at> gnu.org
Subject: gzip --synchronous doesn't work with musl
Date: Mon, 6 Jan 2025 15:29:22 +0200
[Message part 4 (text/plain, inline)]
On Linux/musl:

    $ echo foo > foo
    $ gzip --synchronous foo

    gzip: foo.gz: Bad file descriptor

From gzip.c:

      dfd = open (dfname, O_SEARCH | O_DIRECTORY);

...

        if ((synchronous
             && ((0 <= dfd && fdatasync (dfd) != 0 && errno != EINVAL)
                 || (fsync (ofd) != 0 && errno != EINVAL)))
            || close (ofd) != 0)
          write_error ();

In musl, O_SEARCH maps to Linux-specific O_PATH which doesn't allow
fsync or fdatasync. Gnulib's fcntl module's docs already warn about a
similar situation with fchmod.

As far as I understand this, O_SEARCH in POSIX is only meant for openat
and such APIs. Then it makes sense that O_SEARCH becomes O_PATH because
O_PATH can open a directory that lacks read permission. This way openat
can be used even for such directories.

Maybe there is no way to sync a directory that only has write and search
permissions. Luckily such a combination is rare.

A short fix is using O_RDONLY when --synchronous has been specified:

      dfd = open (dfname, (synchronous ? O_RDONLY : O_SEARCH)
                          | O_DIRECTORY);

I also tried opening a separate file descriptor for syncing (see the
attachment) but I think the above change is better. However, both have
a weakness that if the directory cannot be opened, --synchronous will
silently skip syncing the directory. It would be safer to show an error
if the directory cannot be opened when --synchronous has been specified.

-- 
Lasse Collin
[dfd_sync.patch (text/x-patch, attachment)]

This bug report was last modified 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.