[Debconf-devel] Bug#1091442: dpkg-preconfigure calling apt-extracttemplates breaks DPKG_ROOT support

Johannes Schauer Marin Rodrigues josch at debian.org
Fri Jan 10 14:53:00 GMT 2025


Control: reopen -1

Hi debconf & apt maintainers,

Quoting Johannes Schauer Marin Rodrigues (2025-01-09 18:45:32)
> Quoting Helmut Grohne (2024-12-26 20:27:29)
> > > > I'm am looking for ideas of how to fix this.
> > I question why we run dpkg-preconfigure from mmdebstrap. In what
> > situation can it have any beneficial effect?
> you didn't reply anymore to Helmut's mail so I assume that this means that you
> do not disagree with his analysis?
> 
> In that case I'm reassigning this bug to mmdebstrap and will fix it there.

it seems that the test that I wrote to check that this works was faulty and the
bug persists. I talked again with Helmut Grohne and Julian Klode on IRC and we
there are now the following ideas to fix this:

1. mmdebstrap fixes this
------------------------

The problem with my workaround in mmdebstrap was that setting

    #clear DPkg::Pre-Install-Pkgs;

in a config passed to apt via APT_CONFIG is rendered useless as
/etc/apt/apt.conf.d/70debconf will still take priority. So one possible
solution to this is: let mmdebstrap write yet another config file which is able
to override 70debconf:

@@ -3108,7 +3108,11 @@ sub run_setup() {
     # dpkg-preconfigure should not be needed as we also have set
     # DEBIAN_FRONTEND=noninteractive and DEBCONF_NONINTERACTIVE_SEEN=true and
     # should thus never see debconf prompts. See #1091442 for details.
-    print $conf "#clear DPkg::Pre-Install-Pkgs;\n";
+    {
+        open my $tmp, '>', "$options->{root}/etc/apt/apt.conf.d/99debconf"
+          or error "cannot open /etc/apt/apt.conf.d/99debconf: $!";
+        print $tmp "#clear DPkg::Pre-Install-Pkgs;\n";
+    }
 
     close $conf;
 

2. apt fixes this
-----------------

In #debian-apt Julian argued that apt should really not be running *any*
scripts if "Dir" is not "/". The reason for that is that apt is not telling
scripts about the setting of "Dir" at all, so it's dangerous to call them if
apt is not operating on the root directory but a different path. According to
Julian (and I agree) it is weird if somebody runs:

    apt update -o Dir=foo

and then hooks from the system outside of foo are run. So we could also fix
this by doing (minimal untested patch):

--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -1545,11 +1545,13 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
    unsigned int const MaxArgBytes = _config->FindI("Dpkg::MaxArgBytes", OSArgMax);
    bool const NoTriggers = _config->FindB("DPkg::NoTriggers", true);
 
+   if (_config->FindDir("Dir") == "/") { // only run hooks if we operate on the root
    if (RunScripts("DPkg::Pre-Invoke") == false)
       return false;
 
    if (RunScriptsWithPkgs("DPkg::Pre-Install-Pkgs") == false)
       return false;
+   }
 
    auto const noopDPkgInvocation = _config->FindB("Debug::pkgDPkgPM",false);
    // store auto-bits as they are supposed to be after dpkg is run
@@ -2216,8 +2218,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
 
    d->progress->Stop();
 
+   if (_config->FindDir("Dir") == "/") { // only run hooks if we operate on the root
    if (RunScripts("DPkg::Post-Invoke") == false)
       return false;
+   }
 
    return d->dpkg_error.empty();
 }

3. debconf fixes this
---------------------

Thirdly, and lastly, one could argue that it does not make sense for
dpkg-preconfigure to do anything in a bootstrapping scenario where the user is
not asked debconf questions in the first place. Instead of inventing a way how
to communicate "we are in a bootstrapping scenario" to dpkg-preconfigure, could
dpkg-reconfigure just exit early and do nothing if
DEBIAN_FRONTEND=noninteractive? Because in that case, there will not be any
debconf questions asked, so why run dpkg-preconfigure at all?

--- a/dpkg-preconfigure
+++ b/dpkg-preconfigure
@@ -113,6 +113,11 @@ qq{Usage: dpkg-preconfigure [options] [debs]
        "apt"                   => \$apt,
 );
 
+if (exists $ENV{DEBIAN_FRONTEND} and $ENV{DEBIAN_FRONTEND} eq 'noninteractive') {
+    print STDERR sprintf("dpkg-preconfigure: ".gettext("Skipping dpkg-preconfigure with DEBIAN_FRONTEND set to 'noninteractive'")), "\n";
+    exit 0;
+}
+
 # In apt mode, need unbuffered output. Let's just enable it.
 $|=1;
 

What do you think?

Thanks!

cheers, josch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: signature
URL: <http://alioth-lists.debian.net/pipermail/debconf-devel/attachments/20250110/d0ca616f/attachment.sig>


More information about the Debconf-devel mailing list