summaryrefslogtreecommitdiffstats
path: root/lib/MGA/DrakISO/Utils.pm
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2018-01-10 09:03:20 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2018-01-12 08:44:42 +0000
commitff30da3ebb107421372e2a1a6d37f7c189667f2b (patch)
tree7dcb10f555e74768f55029d644d16e636abb5420 /lib/MGA/DrakISO/Utils.pm
parent98ac027245772b49c24b1bbe35b0f33e6551c3e8 (diff)
downloaddrakiso-ff30da3ebb107421372e2a1a6d37f7c189667f2b.tar
drakiso-ff30da3ebb107421372e2a1a6d37f7c189667f2b.tar.gz
drakiso-ff30da3ebb107421372e2a1a6d37f7c189667f2b.tar.bz2
drakiso-ff30da3ebb107421372e2a1a6d37f7c189667f2b.tar.xz
drakiso-ff30da3ebb107421372e2a1a6d37f7c189667f2b.zip
Simplify run_() helper function and minimise direct calls to system().
Diffstat (limited to 'lib/MGA/DrakISO/Utils.pm')
-rw-r--r--lib/MGA/DrakISO/Utils.pm31
1 files changed, 12 insertions, 19 deletions
diff --git a/lib/MGA/DrakISO/Utils.pm b/lib/MGA/DrakISO/Utils.pm
index dcccf0b..f98e46d 100644
--- a/lib/MGA/DrakISO/Utils.pm
+++ b/lib/MGA/DrakISO/Utils.pm
@@ -28,7 +28,6 @@ use strict;
use MDK::Common;
use common;
use fs;
-use run_program;
use IPC::Open3;
use IO::Select;
@@ -52,27 +51,21 @@ sub glob__ {
}
sub run_ {
- my $options = ref $_[0] eq 'HASH' ? shift @_ : {};
my @cmd = @_;
- $options->{timeout} ||= 'never';
- if (arch() !~ /^arm/) {
- my $targetarch = delete $options->{targetarch};
- unshift @cmd, 'setarch', $targetarch if $targetarch;
- }
- print "running " . (exists $options->{root} && "(in chroot) ") . join(' ', @cmd) . "\n" if $::verbose > 1;
- run_program::raw($options, @cmd);
+
+ print "@cmd\n" if $::verbose > 2;
+ system(@cmd) == 0;
}
sub run_as_root {
- my (@cmd) = @_;
+ my @cmd = @_;
if (@cmd > 1) {
unshift @cmd, $sudo if $sudo;
} else {
@cmd[0] = join(' ', $sudo, @cmd[0]);
}
- print "@cmd\n" if $::verbose > 2;
- system(@cmd) == 0;
+ run_(@cmd);
}
sub run_in_root {
@@ -124,18 +117,18 @@ sub copy_or_link {
}
sub mount {
- my ($dst, $src, $o_options) = @_;
+ my ($dst, $src, @o_options) = @_;
mkdir_p($dst);
- system(join(' ', 'sudo mount', $o_options, $src, $dst)) == 0
+ run_as_root('mount', @o_options, $src, $dst)
or die "ERROR: failed to mount $src on $dst\n";
}
sub mount_system_fs {
my ($root) = @_;
- mount($root . '/dev', '/dev', '--bind -o ro');
- mount($root . '/proc', 'none', '-t proc');
- mount($root . '/sys', 'none', '-t sysfs');
- mount($root . '/run', 'none', '-t tmpfs');
+ mount($root . '/dev', '/dev', '--bind', '-o', 'ro');
+ mount($root . '/proc', 'none', '-t', 'proc');
+ mount($root . '/sys', 'none', '-t', 'sysfs');
+ mount($root . '/run', 'none', '-t', 'tmpfs');
}
sub umount_all_in_root {
@@ -144,7 +137,7 @@ sub umount_all_in_root {
my @mounts = grep { $_ =~ $root } split("\n", cat_('/proc/mounts'));
foreach (reverse(@mounts)) {
my @field = split(' ' , $_);
- system(join(' ', 'sudo umount', $field[1]));
+ run_as_root('umount', $field[1]);
}
}