add --skip=chroot/start-stop-daemon and --skip=chroot/policy-rc.d

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-09-02 23:25:48 +02:00
parent 18c1e9bbc5
commit e61e352f67
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1
3 changed files with 68 additions and 32 deletions

View file

@ -264,6 +264,8 @@ Test: not-having-to-install-apt-in-include-because-a-hook-did-it-before
Test: remove-start-stop-daemon-and-policy-rc-d-in-hook Test: remove-start-stop-daemon-and-policy-rc-d-in-hook
Test: skip-start-stop-daemon-policy-rc
Test: compare-output-with-pre-seeded-var-cache-apt-archives Test: compare-output-with-pre-seeded-var-cache-apt-archives
Needs-QEMU: true Needs-QEMU: true
Variants: any Variants: any

View file

@ -1426,6 +1426,9 @@ sub run_chroot {
# existing inside the chroot # existing inside the chroot
# #
# See #911290 for more problems of this interface # See #911290 for more problems of this interface
if (any { $_ eq 'chroot/policy-rc.d' } @{ $options->{skip} }) {
info "skipping chroot/policy-rc.d as requested";
} else {
if (-d "$options->{root}/usr/sbin/") { if (-d "$options->{root}/usr/sbin/") {
open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d" open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d"
or error "cannot open policy-rc.d: $!"; or error "cannot open policy-rc.d: $!";
@ -1435,11 +1438,16 @@ sub run_chroot {
chmod 0755, "$options->{root}/usr/sbin/policy-rc.d" chmod 0755, "$options->{root}/usr/sbin/policy-rc.d"
or error "cannot chmod policy-rc.d: $!"; or error "cannot chmod policy-rc.d: $!";
} }
}
# the file might not exist if it was removed in a hook # the file might not exist if it was removed in a hook
if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
info "skipping chroot/start-stop-daemon as requested";
} else {
if (-f "$options->{root}/sbin/start-stop-daemon") { if (-f "$options->{root}/sbin/start-stop-daemon") {
if (-e "$options->{root}/sbin/start-stop-daemon.REAL") { if (-e "$options->{root}/sbin/start-stop-daemon.REAL") {
error "$options->{root}/sbin/start-stop-daemon.REAL already" error
"$options->{root}/sbin/start-stop-daemon.REAL already"
. " exists"; . " exists";
} }
move( move(
@ -1449,26 +1457,36 @@ sub run_chroot {
open my $fh, '>', "$options->{root}/sbin/start-stop-daemon" open my $fh, '>', "$options->{root}/sbin/start-stop-daemon"
or error "cannot open start-stop-daemon: $!"; or error "cannot open start-stop-daemon: $!";
print $fh "#!/bin/sh\n"; print $fh "#!/bin/sh\n";
print $fh "echo \"Warning: Fake start-stop-daemon called, doing" print $fh
"echo \"Warning: Fake start-stop-daemon called, doing"
. " nothing\">&2\n"; . " nothing\">&2\n";
close $fh; close $fh;
chmod 0755, "$options->{root}/sbin/start-stop-daemon" chmod 0755, "$options->{root}/sbin/start-stop-daemon"
or error "cannot chmod start-stop-daemon: $!"; or error "cannot chmod start-stop-daemon: $!";
} }
}
&{$cmd}(); &{$cmd}();
# cleanup # cleanup
if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
info "skipping chroot/start-stop-daemon as requested";
} else {
if (-e "$options->{root}/sbin/start-stop-daemon.REAL") { if (-e "$options->{root}/sbin/start-stop-daemon.REAL") {
move( move(
"$options->{root}/sbin/start-stop-daemon.REAL", "$options->{root}/sbin/start-stop-daemon.REAL",
"$options->{root}/sbin/start-stop-daemon" "$options->{root}/sbin/start-stop-daemon"
) or error "cannot move start-stop-daemon: $!"; ) or error "cannot move start-stop-daemon: $!";
} }
}
if (any { $_ eq 'chroot/policy-rc.d' } @{ $options->{skip} }) {
info "skipping chroot/policy-rc.d as requested";
} else {
if (-f "$options->{root}/usr/sbin/policy-rc.d") { if (-f "$options->{root}/usr/sbin/policy-rc.d") {
unlink "$options->{root}/usr/sbin/policy-rc.d" unlink "$options->{root}/usr/sbin/policy-rc.d"
or error "cannot unlink policy-rc.d: $!"; or error "cannot unlink policy-rc.d: $!";
} }
}
}; };
@ -6765,6 +6783,12 @@ out in B<extract> mode.
Run B<--customize-hook> options and all F<customize*> scripts in B<--hook-dir>. Run B<--customize-hook> options and all F<customize*> scripts in B<--hook-dir>.
This step is not carried out in B<extract> mode. This step is not carried out in B<extract> mode.
For each command that is run inside the chroot, B<mmdebstrap> will disable
running services by temporarily moving F</usr/sbin/policy-rc.d> and
F</sbin/start-stop-daemon> if they exist. This can be disabled with
B<--skip=chroot/policy-rc.d> and B<--skip=chroot/start-stop-daemon>,
respectively.
=item B<cleanup> =item B<cleanup>
Performs cleanup tasks, unless B<--skip=cleanup> is used: Performs cleanup tasks, unless B<--skip=cleanup> is used:

View file

@ -0,0 +1,10 @@
#!/bin/sh
set -eu
export LC_ALL=C.UTF-8
trap "rm -f /tmp/debian-chroot.tar" EXIT INT TERM
{{ CMD }} --mode={{ MODE }} --variant=apt \
--skip=chroot/start-stop-daemon,chroot/policy-rc.d \
--customize-hook='test ! -e "$1/sbin/start-stop-daemon.REAL"' \
--customize-hook='test ! -e "$1/usr/sbin/policy-rc.d"' \
{{ DIST }} /tmp/debian-chroot.tar {{ MIRROR }}
tar -tf /tmp/debian-chroot.tar | sort | diff -u tar1.txt -