The following commit has been merged in the infra-513663 branch:
commit 298b4d9eee629f17a8ca211881f258efa9893ed0
Author: Niels Thykier <[email protected]>
Date:   Thu Mar 31 13:35:43 2011 +0200

    Added rundir to the interface of L::Cmd::Simple
    
    This is basically an extension of run that takes a directory as
    first argument, fork, chdir to that dir and then run the command.

diff --git a/lib/Lintian/Command/Simple.pm b/lib/Lintian/Command/Simple.pm
index fbacdaf..2ab34ea 100644
--- a/lib/Lintian/Command/Simple.pm
+++ b/lib/Lintian/Command/Simple.pm
@@ -100,6 +100,50 @@ sub run {
     return $? >> 8;
 }
 
+=item rundir(dir, command, argument  [, ...])
+
+Executes the given C<command> with the given arguments and in C<dir>
+returns the status code as one would see it from a shell script.
+
+Being fair, the only advantage of this function (or method) over the
+CORE::system() function is the way the return status is reported.
+
+=cut
+
+sub rundir {
+    my $self;
+    my $pid;
+    my $res;
+
+    if (ref $_[0]) {
+       $self = shift;
+       return -1
+           if defined($self->{'pid'});
+    }
+    $pid = fork();
+    if (not defined($pid)) {
+       # failed
+        $res = -1;
+    } elsif ($pid > 0) {
+       # parent
+        if (defined($self)){
+            $self->{'pid'} = $pid;
+            $res = $self->wait();
+        } else {
+            $res = Lintian::Command::Simple::wait($pid);
+        }
+    } else {
+       # child
+        my $dir = shift;
+       close(STDIN);
+       open(STDIN, '<', '/dev/null');
+        chdir($dir) or die("Failed to chdir to $dir: $!\n");
+       CORE::exec @_ or die("Failed to exec '$_[0]': $!\n");
+    }
+
+    return $res;
+}
+
 =item background(command, argument  [, ...])
 
 Executes the given C<command> with the given arguments asynchronously

-- 
Debian package checker


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]

Reply via email to