|
|
@ -1188,6 +1188,28 @@ sub run_hooks {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my @env_opts = ();
|
|
|
|
|
|
|
|
# There is no need to unset TMPDIR because we already have set it ourselves
|
|
|
|
|
|
|
|
# to "$options->{root}/tmp" in run_setup(). This is to have a writable
|
|
|
|
|
|
|
|
# TMPDIR even in unshare mode.
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# The APT_CONFIG variable, if set, will confuse any manual calls to
|
|
|
|
|
|
|
|
# apt-get. If you want to use the same config used by mmdebstrap, the
|
|
|
|
|
|
|
|
# original value is stored in MMDEBSTRAP_APT_CONFIG.
|
|
|
|
|
|
|
|
if (defined $ENV{APT_CONFIG} && $ENV{APT_CONFIG} ne "") {
|
|
|
|
|
|
|
|
push @env_opts, '--unset=APT_CONFIG';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $ENV{APT_CONFIG} && $ENV{APT_CONFIG} ne "") {
|
|
|
|
|
|
|
|
push @env_opts, "MMDEBSTRAP_APT_CONFIG=$ENV{APT_CONFIG}";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Storing the mode is important for hook scripts to potentially change
|
|
|
|
|
|
|
|
# their behavior depending on the mode. It's also important for when the
|
|
|
|
|
|
|
|
# hook wants to use the mmdebstrap --hook-helper.
|
|
|
|
|
|
|
|
push @env_opts, "MMDEBSTRAP_MODE=$options->{mode}";
|
|
|
|
|
|
|
|
# This is the file descriptor of the socket that the mmdebstrap
|
|
|
|
|
|
|
|
# --hook-helper can write to and read from to communicate with the outside.
|
|
|
|
|
|
|
|
push @env_opts, ("MMDEBSTRAP_HOOKSOCK=" . fileno($options->{hooksock}));
|
|
|
|
|
|
|
|
|
|
|
|
my $runner = sub {
|
|
|
|
my $runner = sub {
|
|
|
|
foreach my $script (@{ $options->{"${name}_hook"} }) {
|
|
|
|
foreach my $script (@{ $options->{"${name}_hook"} }) {
|
|
|
|
if (
|
|
|
|
if (
|
|
|
@ -1246,20 +1268,25 @@ sub run_hooks {
|
|
|
|
# execute it directly if it's an executable file
|
|
|
|
# execute it directly if it's an executable file
|
|
|
|
# or if it there are no shell metacharacters
|
|
|
|
# or if it there are no shell metacharacters
|
|
|
|
# (the /a regex modifier makes \w match only ASCII)
|
|
|
|
# (the /a regex modifier makes \w match only ASCII)
|
|
|
|
0 == system('env', '--unset=TMPDIR', '--unset=APT_CONFIG',
|
|
|
|
0 == system('env', @env_opts, $script, $options->{root})
|
|
|
|
$script, $options->{root})
|
|
|
|
|
|
|
|
or error "command failed: $script";
|
|
|
|
or error "command failed: $script";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
info "running --$name-hook in shell: sh -c '$script' exec"
|
|
|
|
info "running --$name-hook in shell: sh -c '$script' exec"
|
|
|
|
. " $options->{root}";
|
|
|
|
. " $options->{root}";
|
|
|
|
# otherwise, wrap everything in sh -c
|
|
|
|
# otherwise, wrap everything in sh -c
|
|
|
|
0 == system('env', '--unset=TMPDIR', '--unset=APT_CONFIG',
|
|
|
|
0 == system('env', @env_opts,
|
|
|
|
'sh', '-c', $script, 'exec', $options->{root})
|
|
|
|
'sh', '-c', $script, 'exec', $options->{root})
|
|
|
|
or error "command failed: $script";
|
|
|
|
or error "command failed: $script";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Unset the close-on-exec flag, so that the file descriptor does not
|
|
|
|
|
|
|
|
# get closed when we exec
|
|
|
|
|
|
|
|
my $flags = fcntl($options->{hooksock}, F_GETFD, 0)
|
|
|
|
|
|
|
|
or error "fcntl F_GETFD: $!";
|
|
|
|
|
|
|
|
fcntl($options->{hooksock}, F_SETFD, $flags & ~FD_CLOEXEC)
|
|
|
|
|
|
|
|
or error "fcntl F_SETFD: $!";
|
|
|
|
if ($name eq 'setup') {
|
|
|
|
if ($name eq 'setup') {
|
|
|
|
# execute directly without mounting anything (the mount points do not
|
|
|
|
# execute directly without mounting anything (the mount points do not
|
|
|
|
# exist yet)
|
|
|
|
# exist yet)
|
|
|
@ -1267,6 +1294,8 @@ sub run_hooks {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
run_chroot(\&$runner, $options);
|
|
|
|
run_chroot(\&$runner, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restore flags
|
|
|
|
|
|
|
|
fcntl($options->{hooksock}, F_SETFD, $flags) or error "fcntl F_SETFD: $!";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|