diff options
Diffstat (limited to 'perl-install/run_program.pm')
-rw-r--r-- | perl-install/run_program.pm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/perl-install/run_program.pm b/perl-install/run_program.pm new file mode 100644 index 000000000..e4f2a7ef8 --- /dev/null +++ b/perl-install/run_program.pm @@ -0,0 +1,30 @@ +package run_program; + +use diagnostics; +use strict; + +use log; + +1; + +sub run($@) { rooted('', @_) } + +sub rooted($$@) { + my ($root, $name, @args) = @_; + + log::l("running: $name @args" . ($root ? " with root $root" : "")); + $root ? $root .= '/' : ($root = ''); + + fork and wait, return $? == 0; + { + open STDIN, "/dev/null" or die "can't open /dev/null as stdin"; + + open STDERR, ">> /dev/tty5" or open STDERR, ">> /tmp/exec.log" or die "runProgramRoot can't log :("; + open STDOUT, ">> /dev/tty5" or open STDOUT, ">> /tmp/exec.log" or die "runProgramRoot can't log :("; + + $root and chroot $root; + chdir "/"; + + exec $name, @args or log::l("exec of $name failed: $!"), exit(-1); + } +} |