summaryrefslogtreecommitdiffstats
path: root/perl-install/run_program.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/run_program.pm')
-rw-r--r--perl-install/run_program.pm45
1 files changed, 38 insertions, 7 deletions
diff --git a/perl-install/run_program.pm b/perl-install/run_program.pm
index e4f2a7ef8..293910cb8 100644
--- a/perl-install/run_program.pm
+++ b/perl-install/run_program.pm
@@ -1,4 +1,4 @@
-package run_program;
+package run_program; # $Id$
use diagnostics;
use strict;
@@ -9,22 +9,53 @@ use log;
sub run($@) { rooted('', @_) }
-sub rooted($$@) {
+sub rooted {
my ($root, $name, @args) = @_;
+ my $str = ref $name ? $name->[0] : $name;
+ log::l("running: $str @args" . ($root ? " with root $root" : ""));
+
+ return 1 if $root && $<;
- log::l("running: $name @args" . ($root ? " with root $root" : ""));
$root ? $root .= '/' : ($root = '');
- fork and wait, return $? == 0;
+ if (my $pid = fork) {
+ waitpid $pid, 0;
+ return $? == 0;
+ }
{
+ my ($stdout, $stdoutm, $stderr, $stderrm);
+ ($stdoutm, $stdout, @args) = @args if $args[0] =~ /^>>?$/;
+ ($stderrm, $stderr, @args) = @args if $args[0] =~ /^2>>?$/;
+
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 :(";
+ if ($stderr) {
+ $stderrm =~ s/2//;
+ open STDERR, "$stderrm $root$stderr" or die "run_program can't output in $root$stderr (mode `$stderrm')";
+ } elsif ($::isInstall) {
+ open STDERR, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log";
+ }
+ if ($stdout) {
+ open STDOUT, "$stdoutm $root$stdout" or die "run_program can't output in $root$stdout (mode `$stdoutm')";
+ } elsif ($::isInstall) {
+ open STDOUT, ">> /tmp/ddebug.log" or open STDOUT, ">> /dev/tty7" or die "run_program can't log, give me access to /tmp/ddebug.log";
+ }
$root and chroot $root;
chdir "/";
- exec $name, @args or log::l("exec of $name failed: $!"), exit(-1);
+ if (ref $name) {
+ unless (exec { $name->[0] } $name->[1], @args) {
+ log::l("exec of $name->[0] failed: $!");
+ c::_exit(1);
+ }
+ } else {
+ unless (exec $name, @args) {
+ log::l("exec of $name failed: $!");
+ c::_exit(1);
+ }
+
+ }
}
+
}