• Bug#1085646: sbuild: Assumes UNSHARE_TMPDIR_TEMPLATE is mode 4777

    From Johannes Schauer Marin Rodrigues@21:1/5 to niels@thykier.net on Thu Apr 10 14:30:01 2025
    Control: tag -1 + moreinfo

    Hi,

    On Mon, 21 Oct 2024 13:25:33 +0200 Niels Thykier <niels@thykier.net> wrote:
    The sbuild code assumes that the directory hosting the

    UNSHARE_TMPDIR_TEMPLATE is mode 4777 (--chroot-mode=unshare). When it is

    not, the following rm failure will appear under cleanup



    +------------------------------------------------------------------------------+

    | Cleanup |

    +------------------------------------------------------------------------------+



    Purging /<<BUILDDIR>>

    Not cleaning session: cloned chroot in use

    rm: cannot remove '/home/user/debian/sbuild-test/tmp.sbuild.4Gf6tS2': Permission denied

    [...]



    This happens for both successful and failed builds. The temporary

    directory is properly cleaned regardless of this error (I guess there is

    rm code both on the host and "inside" the chroot).



    In my case, I changed UNSHARE_TMPDIR_TEMPLATE into a directory under my

    user's HOME folder that I just created with mkdir -p. On my system, /tmp

    is mounted with "noexec" and therefore the default could not be used.


    yes, in the code there is this comment right after the "rm -rf" runs:

    # we ignore the exit status, because the command will fail to remove the
    # unpack directory itself because of insufficient permissions

    It would be nice if there were an easy way to instruct rm to remove a directory recursively *except* for the root directory. What do you suggest should sbuild do instead? I see several options:

    * implement our own recursive removal which ignores the parent
    * redirect the rm -rf output to /dev/null to not confuse the user
    * if rm -rf fails, print a message saying that the failure is not fatal
    because there will be a rmdir on the outside which will clean the root

    Thanks!

    cheers, josch
    --==============f34702488264747178=MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Description: signature
    Content-Type: application/pgp-signature; name="signature.asc"; charset="us-ascii"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEElFhU6KL81LF4wVq58sulx4+9g+EFAmf3trMACgkQ8sulx4+9 g+H2hxAAvKNHP/aVkpvIaUlwl/A25ZIDiq4/c228I5nRc19BdFR24GNWwbCA20fU t8QTGwNhbpQCuk9R6vomRNrCLWCq+N6OncChxQnUBQIGfpSzkhx+hwJEUmcgy2q5 uY0K7VrpVrPCr/m1VNsCkbN0IMwzvjz+CmcYoIIwYreodt6JO9/L8trO7375MuL9 IdeuHhb4u6y99/MK4f1Dn6uC6X5qzewBuoPCqFNykk8JrrqEw5ZcFFQZ2zDJp3zO oERycmecKfu8hf0hGthBMDNDvSKT/uE7O4v8mH6MRhnPkLjdYvpupku3clmOFXQ1 3vtIkVRb3Zw32Di0hytuAeCk8xo0ai6RMaWQq3/Sqm1UuRxfbRDF5qkupk4sCzGc cXnXRUP3XDXlCRYc5Mrhm0FDtb6PogKH40KrECWJRn9ZzNYH/0w81GGhzQfUNbUs t7Dh5DxcoWERpQChF3pz62eSaMsJhjJW/EFDZIbKwueYv0BO0rOMnp6l7Q0vSuJM lMhkDSHCQs3+P4mfH5Bgha3W1VQ57BqOsZjzqXOj+LchkFM0r+CHmGluxqRLQAQ8 DnOZCcTGNkxMWS/xghypJgAAMTm40dAb6HmyMJ+EJH550iXykLPr1AW2lvoGunE9 Z0Wn6PICUQ/PkIA5mXpSiJgOJB9TI4w/cKJgVIq7KBvt1L73UfE=
    =qiNZ
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johannes Schauer Marin Rodrigues@21:1/5 to All on Wed Apr 23 16:10:01 2025
    Hi Niels,

    Quoting Niels Thykier (2025-04-21 22:13:32)
    Of the options presented, I would recommend the first one.

    That option has my preference because:

    A) It does not present an error to be ignored. I do not like such
    behavior since I feel it promotes error blindness. The third
    alternative fails this one in my view.

    B) It does not hide unrelated errors (that is, if another error occurs
    that message will not be hidden from the user). The second alternative
    fails this one in my view.

    I agree with your assesment. Thank you for sharing your opinion on this. While I started implementing this using Perl's remove_tree() I remembered that I already had the same problem with mmdebstrap. I now just copied what I do with mmdebstrap and recorded the reasoning behind that in the commit message:

    https://salsa.debian.org/debian/sbuild/-/merge_requests/179

    Thanks!

    cheers, josch
    --==============697080446895443223=MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Description: signature
    Content-Type: application/pgp-signature; name="signature.asc"; charset="us-ascii"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEElFhU6KL81LF4wVq58sulx4+9g+EFAmgI82cACgkQ8sulx4+9 g+HRZQ/+Jef4f27cDdTykY/yK9TRj141sBlBXSSUCJo1QCFjwJdwgIxJtuQp2j/9 uFWPHhrCg/+xajc1wmrvfoRE0dkg5m1jSDxC2zPtJjl6wKjajLXzKBUeCvvZKTeP nAr15jWqihOwo42tQByjMckTcEkFAguQEZil1xSFNfAJ3YZLj/2jKDjencgqTatH ReuP77f71Cct9NaXQ2Msyn4PH5Gp4Gecbl7r3FHu1TI9UH4KuwHvirp43blYjJkW /L4doTsmJsl5fRsZin24K4Q3Qn+Y7UPIdJQ3ckGHPnmBQPcGSWrMlf5JKAETpfvg Sw52q03CqYKXlG51o4MFvY+ghuTehmDgobhzY/ByYe8q3TWVpMdm1X1qUa1HaNbN skdU2b3q23EqXMDkQO8T2+xd0cg4OyEZA5MboN9NV7RIoYEA7CDHuHx5Yhqxvqwk PjBarnzNUNoTk+QWg5dy/uufjZ7w94OdZeNDGLCWmLalaPpA+Xh1bYrl/FdBGhdK DeIhksLHgZcirrfujKcrImadRn5Fl1AeEJSs+jDMaBQkiSK2HapMyTJQodo4KiFQ rPYs3J6bJ5f4vMFD9S18xyLgzw+3WRpgWyFz2/8aMmhfQ9pciswe04oO1MTcYIjf QNtC8ZEU+75JSaDelOtwXXHUNTcSBLY7XLqC/gl1kqhARB3DQM8=
    =y+IM
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)