summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2002-08-06 12:58:58 +0000
committerPascal Rigaux <pixel@mandriva.com>2002-08-06 12:58:58 +0000
commit58811579e3abc5e2741456474b05772378e11219 (patch)
tree6310ec314ce3699b21620a04231bf6d79cab7040
parent47c85d99043cca6b4e972f297a685d67c1db7cfc (diff)
downloaddrakx-58811579e3abc5e2741456474b05772378e11219.tar
drakx-58811579e3abc5e2741456474b05772378e11219.tar.gz
drakx-58811579e3abc5e2741456474b05772378e11219.tar.bz2
drakx-58811579e3abc5e2741456474b05772378e11219.tar.xz
drakx-58811579e3abc5e2741456474b05772378e11219.zip
(raw): new function allowing special options like {timeout}
-rw-r--r--perl-install/run_program.pm25
1 files changed, 22 insertions, 3 deletions
diff --git a/perl-install/run_program.pm b/perl-install/run_program.pm
index fe3b938f3..78ae48559 100644
--- a/perl-install/run_program.pm
+++ b/perl-install/run_program.pm
@@ -23,10 +23,16 @@ sub rooted_get_stdout {
wantarray ? @r : join('', @r);
}
-sub run { rooted('', @_) }
+sub run { raw({}, @_) }
sub rooted {
my ($root, $name, @args) = @_;
+ raw({ root => $root }, $name, @args);
+}
+
+sub raw {
+ my ($options, $name, @args) = @_;
+ my $root = $options->{root} || '';
my $str = ref $name ? $name->[0] : $name;
log::l("running: $str @args" . ($root ? " with root $root" : ""));
@@ -45,8 +51,21 @@ sub rooted {
my $stderr = $stderr_raw && (ref($stderr_raw) ? "$ENV{HOME}/tmp/.drakx-stderr.$$" : "$root$stderr_raw");
if (my $pid = fork) {
- waitpid $pid, 0;
- $? == 0 or return;
+ my $ok;
+ eval {
+ local $SIG{ALRM} = sub { die "ALARM" };
+ alarm($options->{timeout} || 10 * 60);
+ waitpid $pid, 0;
+ $ok = $? == 0;
+ alarm 0;
+ };
+ if ($@) {
+ log::l("ERROR: killing runaway process");
+ kill 9, $pid;
+ return;
+ }
+ $ok or return;
+
if ($stdout_raw && ref($stdout_raw)) {
if (ref($stdout_raw) eq 'ARRAY') {
@$stdout_raw = cat_($stdout);