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: 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,48 +1426,66 @@ 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 (-d "$options->{root}/usr/sbin/") { if (any { $_ eq 'chroot/policy-rc.d' } @{ $options->{skip} }) {
open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d" info "skipping chroot/policy-rc.d as requested";
or error "cannot open policy-rc.d: $!"; } else {
print $fh "#!/bin/sh\n"; if (-d "$options->{root}/usr/sbin/") {
print $fh "exit 101\n"; open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d"
close $fh; or error "cannot open policy-rc.d: $!";
chmod 0755, "$options->{root}/usr/sbin/policy-rc.d" print $fh "#!/bin/sh\n";
or error "cannot chmod policy-rc.d: $!"; print $fh "exit 101\n";
close $fh;
chmod 0755, "$options->{root}/usr/sbin/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 (-f "$options->{root}/sbin/start-stop-daemon") { if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
if (-e "$options->{root}/sbin/start-stop-daemon.REAL") { info "skipping chroot/start-stop-daemon as requested";
error "$options->{root}/sbin/start-stop-daemon.REAL already" } else {
. " exists"; if (-f "$options->{root}/sbin/start-stop-daemon") {
if (-e "$options->{root}/sbin/start-stop-daemon.REAL") {
error
"$options->{root}/sbin/start-stop-daemon.REAL already"
. " exists";
}
move(
"$options->{root}/sbin/start-stop-daemon",
"$options->{root}/sbin/start-stop-daemon.REAL"
) or error "cannot move start-stop-daemon: $!";
open my $fh, '>', "$options->{root}/sbin/start-stop-daemon"
or error "cannot open start-stop-daemon: $!";
print $fh "#!/bin/sh\n";
print $fh
"echo \"Warning: Fake start-stop-daemon called, doing"
. " nothing\">&2\n";
close $fh;
chmod 0755, "$options->{root}/sbin/start-stop-daemon"
or error "cannot chmod start-stop-daemon: $!";
} }
move(
"$options->{root}/sbin/start-stop-daemon",
"$options->{root}/sbin/start-stop-daemon.REAL"
) or error "cannot move start-stop-daemon: $!";
open my $fh, '>', "$options->{root}/sbin/start-stop-daemon"
or error "cannot open start-stop-daemon: $!";
print $fh "#!/bin/sh\n";
print $fh "echo \"Warning: Fake start-stop-daemon called, doing"
. " nothing\">&2\n";
close $fh;
chmod 0755, "$options->{root}/sbin/start-stop-daemon"
or error "cannot chmod start-stop-daemon: $!";
} }
&{$cmd}(); &{$cmd}();
# cleanup # cleanup
if (-e "$options->{root}/sbin/start-stop-daemon.REAL") { if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
move( info "skipping chroot/start-stop-daemon as requested";
"$options->{root}/sbin/start-stop-daemon.REAL", } else {
"$options->{root}/sbin/start-stop-daemon" if (-e "$options->{root}/sbin/start-stop-daemon.REAL") {
) or error "cannot move start-stop-daemon: $!"; move(
"$options->{root}/sbin/start-stop-daemon.REAL",
"$options->{root}/sbin/start-stop-daemon"
) or error "cannot move start-stop-daemon: $!";
}
} }
if (-f "$options->{root}/usr/sbin/policy-rc.d") { if (any { $_ eq 'chroot/policy-rc.d' } @{ $options->{skip} }) {
unlink "$options->{root}/usr/sbin/policy-rc.d" info "skipping chroot/policy-rc.d as requested";
or error "cannot unlink policy-rc.d: $!"; } else {
if (-f "$options->{root}/usr/sbin/policy-rc.d") {
unlink "$options->{root}/usr/sbin/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 -