"(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
"(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
+use constant (CLONE_NEWNS => 0x00020000,
+ CLONE_NEWUTS => 0x04000000,
+ CLONE_NEWIPC => 0x08000000,
+ CLONE_NEWUSER => 0x10000000,
+ CLONE_NEWPID => 0x20000000,
+ CLONE_NEWNET => 0x40000000);
+
sub run_with_timeout {
my ($timeout, $code, @param) = @_;
return $input;
}
+# The $cmd parameter can be:
+# -) a string
+# This is generally executed by passing it to the shell with the -c option.
+# However, it can be executed in one of two ways, depending on whether
+# there's a pipe involved:
+# *) with pipe: passed explicitly to bash -c, prefixed with:
+# set -o pipefail &&
+# *) without a pipe: passed to perl's open3 which uses 'sh -c'
+# (Note that this may result in two different syntax requirements!)
+# FIXME?
+# -) an array of arguments (strings)
+# Will be executed without interference from a shell. (Parameters are passed
+# as is, no escape sequences of strings will be touched.)
+# -) an array of arrays
+# Each array represents a command, and each command's output is piped into
+# the following command's standard input.
+# For this a shell command string is created with pipe symbols between each
+# command.
+# Each command is a list of strings meant to end up in the final command
+# unchanged. In order to achieve this, every argument is shell-quoted.
+# Quoting can be disabled for a particular argument by turning it into a
+# reference, this allows inserting arbitrary shell options.
+# For instance: the $cmd [ [ 'echo', 'hello', \'>/dev/null' ] ] will not
+# produce any output, while the $cmd [ [ 'echo', 'hello', '>/dev/null' ] ]
+# will literally print: hello >/dev/null
sub run_command {
my ($cmd, %param) = @_;
my $old_umask;
my $cmdstr;
- if (!ref($cmd)) {
+ if (my $ref = ref($cmd)) {
+ if (ref($cmd->[0])) {
+ $cmdstr = 'set -o pipefail && ';
+ my $pipe = '';
+ foreach my $command (@$cmd) {
+ # concatenate quoted parameters
+ # strings which are passed by reference are NOT shell quoted
+ $cmdstr .= $pipe . join(' ', map { ref($_) ? $$_ : shellquote($_) } @$command);
+ $pipe = ' | ';
+ }
+ $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmdstr" ];
+ } else {
+ $cmdstr = cmd2string($cmd);
+ }
+ } else {
$cmdstr = $cmd;
if ($cmd =~ m/\|/) {
# see 'man bash' for option pipefail
} else {
$cmd = [ $cmd ];
}
- } else {
- $cmdstr = cmd2string($cmd);
}
my $errmsg;
return; # nothing
}
+sub unshare {
+ my ($flags) = @_;
+ syscall 272, $flags;
+}
+
1;