From e61e352f679093fc09cf0068fd5ec11b60bbbe17 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Fri, 2 Sep 2022 23:25:48 +0200 Subject: [PATCH] add --skip=chroot/start-stop-daemon and --skip=chroot/policy-rc.d --- coverage.txt | 2 + mmdebstrap | 88 ++++++++++++++++---------- tests/skip-start-stop-daemon-policy-rc | 10 +++ 3 files changed, 68 insertions(+), 32 deletions(-) create mode 100644 tests/skip-start-stop-daemon-policy-rc diff --git a/coverage.txt b/coverage.txt index 5aceec4..bae0a9b 100644 --- a/coverage.txt +++ b/coverage.txt @@ -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: skip-start-stop-daemon-policy-rc + Test: compare-output-with-pre-seeded-var-cache-apt-archives Needs-QEMU: true Variants: any diff --git a/mmdebstrap b/mmdebstrap index cd5172e..ca43d3f 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1426,48 +1426,66 @@ sub run_chroot { # existing inside the chroot # # See #911290 for more problems of this interface - if (-d "$options->{root}/usr/sbin/") { - open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d" - or error "cannot open policy-rc.d: $!"; - print $fh "#!/bin/sh\n"; - print $fh "exit 101\n"; - close $fh; - chmod 0755, "$options->{root}/usr/sbin/policy-rc.d" - or error "cannot chmod policy-rc.d: $!"; + if (any { $_ eq 'chroot/policy-rc.d' } @{ $options->{skip} }) { + info "skipping chroot/policy-rc.d as requested"; + } else { + if (-d "$options->{root}/usr/sbin/") { + open my $fh, '>', "$options->{root}/usr/sbin/policy-rc.d" + or error "cannot open policy-rc.d: $!"; + print $fh "#!/bin/sh\n"; + 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 - 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"; + 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 (-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}(); # cleanup - if (-e "$options->{root}/sbin/start-stop-daemon.REAL") { - move( - "$options->{root}/sbin/start-stop-daemon.REAL", - "$options->{root}/sbin/start-stop-daemon" - ) or error "cannot move start-stop-daemon: $!"; + 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") { + 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") { - unlink "$options->{root}/usr/sbin/policy-rc.d" - or error "cannot unlink policy-rc.d: $!"; + 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") { + unlink "$options->{root}/usr/sbin/policy-rc.d" + or error "cannot unlink policy-rc.d: $!"; + } } }; @@ -6765,6 +6783,12 @@ out in B mode. Run B<--customize-hook> options and all F scripts in B<--hook-dir>. This step is not carried out in B mode. +For each command that is run inside the chroot, B will disable +running services by temporarily moving F and +F if they exist. This can be disabled with +B<--skip=chroot/policy-rc.d> and B<--skip=chroot/start-stop-daemon>, +respectively. + =item B Performs cleanup tasks, unless B<--skip=cleanup> is used: diff --git a/tests/skip-start-stop-daemon-policy-rc b/tests/skip-start-stop-daemon-policy-rc new file mode 100644 index 0000000..bdf5469 --- /dev/null +++ b/tests/skip-start-stop-daemon-policy-rc @@ -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 -