]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
debian: Simplify cmdline to get the list of packages to install
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 18 Apr 2023 19:13:39 +0000 (21:13 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 18 Apr 2023 19:44:05 +0000 (21:44 +0200)
Let's not bother with file descriptor inheritance and just write
the list of packages to a temporary file.

mkosi/distributions/debian.py
mkosi/run.py

index 2e57b259a5ac0427ec4aea8b252992b0aa06bd73..5324ce96daa1b2a49693adb7bc64cfce4545065f 100644 (file)
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
-import os
 import shutil
 import tempfile
 from collections.abc import Sequence
@@ -80,22 +79,18 @@ class DebianInstaller(DistributionInstaller):
             state.root.joinpath(d).symlink_to(f"usr/{d}")
             state.root.joinpath(f"usr/{d}").mkdir(mode=0o755)
 
-        # Next, we invoke apt install with an info fd to which it writes the debs it's operating on. When
-        # passing "-oDebug::pkgDpkgPm=1", apt will not actually execute any dpkg commands, which turns the
-        # install command into a command that downloads the debs and tells us the full paths to the essential
-        # debs and any dependencies that apt would install in the apt cache.
-        with tempfile.TemporaryFile(dir=state.workspace, mode="w+") as f:
-            os.set_inheritable(f.fileno(), True)
-
+        # Next, we invoke apt-get install to download all the essential packages. With DPkg::Pre-Install-Pkgs,
+        # we specify a shell command that will receive the list of packages that will be installed on stdin.
+        # By configuring Debug::pkgDpkgPm=1, apt-get install will not actually execute any dpkg commands, so
+        # all it does is download the essential debs and tell us their full in the apt cache without actually
+        # installing them.
+        with tempfile.NamedTemporaryFile(dir=state.workspace, mode="r") as f:
             cls.install_packages(state, [
-                "-oDebug::pkgDpkgPm=1",
-                f"-oAPT::Keep-Fds::={f.fileno()}",
-                f"-oDPkg::Tools::options::'cat >&{f.fileno()}'::InfoFD={f.fileno()}",
-                f"-oDpkg::Pre-Install-Pkgs::=cat >&{f.fileno()}",
+                "-oDebug::pkgDPkgPm=1",
+                f"-oDPkg::Pre-Install-Pkgs::=cat >{f.name}",
                 "?essential", "?name(usr-is-merged)",
             ])
 
-            f.seek(0)
             essential = f.read().strip().splitlines()
 
         # Now, extract the debs to the chroot by first extracting the sources tar file out of the deb and
index e0393400c1c2643665eff9cf85ccd35529405c79..b6ff3f757a256becdf9f4322745989949ddfa1a6 100644 (file)
@@ -220,7 +220,7 @@ def _run(
 
     try:
         return subprocess.run(cmdline, check=check, stdout=stdout, stderr=stderr, env=env, **kwargs,
-                              preexec_fn=foreground, close_fds=False)
+                              preexec_fn=foreground)
     except FileNotFoundError as e:
         die(f"{cmdline[0]} not found in PATH.", e)