forked from josch/mmdebstrap
add a new pipe to communicate the number of blocks to the parent instead of abusing the hookhelper/listener
This commit is contained in:
parent
a5ea38cbad
commit
df18304449
1 changed files with 30 additions and 38 deletions
68
mmdebstrap
68
mmdebstrap
|
@ -3257,24 +3257,6 @@ sub hooklistener {
|
|||
if ($? != 0) {
|
||||
error "tar failed";
|
||||
}
|
||||
} elsif ($msg eq "nblks") {
|
||||
# handle the nblks message
|
||||
my $numblocks;
|
||||
debug "received message: nblks";
|
||||
{
|
||||
my $ret = read(STDIN, $numblocks, $len)
|
||||
// error "cannot read from socket: $!";
|
||||
if ($ret == 0) {
|
||||
error "received eof on socket";
|
||||
}
|
||||
}
|
||||
if ($numblocks !~ /^\d+$/) {
|
||||
error "invalid number of blocks: $numblocks";
|
||||
}
|
||||
debug "sending okthx";
|
||||
print STDOUT (pack("n", 0) . "okthx")
|
||||
or error "cannot write to socket: $!";
|
||||
STDOUT->flush();
|
||||
} else {
|
||||
error "unknown message: $msg";
|
||||
}
|
||||
|
@ -4566,7 +4548,6 @@ sub main() {
|
|||
error "unknown format: $format";
|
||||
}
|
||||
|
||||
my $numblocks = 0;
|
||||
my $exitstatus = 0;
|
||||
my @taropts = (
|
||||
'--sort=name',
|
||||
|
@ -4602,6 +4583,13 @@ sub main() {
|
|||
socketpair my $childsock, my $parentsock, AF_UNIX, SOCK_STREAM, PF_UNSPEC
|
||||
or error "socketpair failed: $!";
|
||||
$options->{hooksock} = $childsock;
|
||||
# for communicating the required number of blocks, we don't need
|
||||
# bidirectional communication, so a pipe() is enough
|
||||
# we don't communicate this via the hook communication because
|
||||
# a) this would abuse the functionality exclusively for hooks
|
||||
# b) it puts code writing the protocol outside of the helper/listener
|
||||
# c) the forked listener process cannot communicate to its parent
|
||||
pipe my $nblkreader, my $nblkwriter or error "pipe failed: $!";
|
||||
if ($options->{mode} eq 'unshare') {
|
||||
$pid = get_unshare_cmd(
|
||||
sub {
|
||||
|
@ -4621,21 +4609,19 @@ sub main() {
|
|||
|
||||
setup($options);
|
||||
|
||||
if (!$options->{dryrun} && $format eq 'ext2') {
|
||||
my $numblocks = approx_disk_usage($options->{root});
|
||||
debug "sending nblks";
|
||||
print $childsock (
|
||||
pack("n", length "$numblocks") . "nblks$numblocks");
|
||||
$childsock->flush();
|
||||
debug "waiting for okthx";
|
||||
checkokthx $childsock;
|
||||
}
|
||||
|
||||
print $childsock (pack('n', 0) . 'adios');
|
||||
$childsock->flush();
|
||||
|
||||
close $childsock;
|
||||
|
||||
close $nblkreader;
|
||||
if (!$options->{dryrun} && $format eq 'ext2') {
|
||||
my $numblocks = approx_disk_usage($options->{root});
|
||||
print $nblkwriter "$numblocks\n";
|
||||
$nblkwriter->flush();
|
||||
}
|
||||
close $nblkwriter;
|
||||
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate creating tarball...";
|
||||
} elsif (any { $_ eq $format } ('tar', 'squashfs', 'ext2')) {
|
||||
|
@ -4690,20 +4676,19 @@ sub main() {
|
|||
|
||||
setup($options);
|
||||
|
||||
if (!$options->{dryrun} && $format eq 'ext2') {
|
||||
my $numblocks = approx_disk_usage($options->{root});
|
||||
print $childsock (
|
||||
pack("n", length "$numblocks") . "nblks$numblocks");
|
||||
$childsock->flush();
|
||||
debug "waiting for okthx";
|
||||
checkokthx $childsock;
|
||||
}
|
||||
|
||||
print $childsock (pack('n', 0) . 'adios');
|
||||
$childsock->flush();
|
||||
|
||||
close $childsock;
|
||||
|
||||
close $nblkreader;
|
||||
if (!$options->{dryrun} && $format eq 'ext2') {
|
||||
my $numblocks = approx_disk_usage($options->{root});
|
||||
print $nblkwriter $numblocks;
|
||||
$nblkwriter->flush();
|
||||
}
|
||||
close $nblkwriter;
|
||||
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate creating tarball...";
|
||||
} elsif (any { $_ eq $format } ('tar', 'squashfs', 'ext2')) {
|
||||
|
@ -4827,6 +4812,13 @@ sub main() {
|
|||
|
||||
close $parentsock;
|
||||
|
||||
my $numblocks = 0;
|
||||
close $nblkwriter;
|
||||
if (!$options->{dryrun} && $format eq 'ext2') {
|
||||
chomp($numblocks = <$nblkreader>);
|
||||
}
|
||||
close $nblkreader;
|
||||
|
||||
if ($options->{dryrun}) {
|
||||
# nothing to do
|
||||
} elsif ($format eq 'directory') {
|
||||
|
|
Loading…
Reference in a new issue