blob: e4f2a7ef853fd07682cf0a9152fa54f6e1253f75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}
}
|