[pve-devel] r5009 - pve-storage/pve2
svn-commits at proxmox.com
svn-commits at proxmox.com
Mon Aug 16 13:02:55 CEST 2010
Author: dietmar
Date: 2010-08-16 11:02:55 +0000 (Mon, 16 Aug 2010)
New Revision: 5009
Modified:
pve-storage/pve2/Storage.pm
pve-storage/pve2/control.in
Log:
Modified: pve-storage/pve2/Storage.pm
===================================================================
--- pve-storage/pve2/Storage.pm 2010-08-16 11:00:57 UTC (rev 5008)
+++ pve-storage/pve2/Storage.pm 2010-08-16 11:02:55 UTC (rev 5009)
@@ -16,6 +16,7 @@
use Getopt::Long qw(GetOptionsFromArray);
use Socket;
use Digest::SHA1;
+use PVE::Tools;
my $ISCSIADM = '/usr/bin/iscsiadm';
my $UDEVADM = '/sbin/udevadm';
@@ -250,142 +251,6 @@
return $res;
}
-sub run_command {
- my ($cmd, %param) = @_;
-
- my $reader = IO::File->new();
- my $writer = IO::File->new();
- my $error = IO::File->new();
-
- $cmd = [ $cmd ] if !ref($cmd);
-
- my $cmdstr = join (' ', @$cmd);
-
- my $timeout;
- my $input;
- my $outfunc;
- my $errfunc;
-
- foreach my $p (keys %param) {
- if ($p eq 'timeout') {
- $timeout = $param{$p};
- } elsif ($p eq 'input') {
- $input = $param{$p};
- } elsif ($p eq 'outfunc') {
- $outfunc = $param{$p};
- } elsif ($p eq 'errfunc') {
- $errfunc = $param{$p};
- } else {
- die "got unknown parameter '$p' for run_command\n";
- }
- }
-
- # try to avoid locale related issues/warnings
- my $lang = $param{lang} || 'C';
-
- my $orig_pid = $$;
-
- my $pid;
- eval {
- local $ENV{LANG} = $lang;
-
- # suppress LVM warnings like: "File descriptor 3 left open";
- local $ENV{LVM_SUPPRESS_FD_WARNINGS} = "1";
-
- $pid = open3 ($writer, $reader, $error, @$cmd) || die $!;
- };
-
- my $err = $@;
-
- # catch exec errors
- if ($orig_pid != $$) {
- warn "ERROR: $err";
- POSIX::_exit (1);
- kill ('KILL', $$);
- }
-
- die $err if $err;
-
- print $writer $input if defined $input;
- close $writer;
-
- my $select = new IO::Select;
- $select->add ($reader);
- $select->add ($error);
-
- my $outlog = '';
- my $errlog = '';
-
- while ($select->count) {
- my @handles = $select->can_read ($timeout);
-
- if (defined ($timeout) && (scalar (@handles) == 0)) {
- kill (9, $pid);
- waitpid ($pid, 0);
- die "command '$cmdstr' failed: timeout";
- }
-
- foreach my $h (@handles) {
- my $buf = '';
- my $count = sysread ($h, $buf, 4096);
- if (!defined ($count)) {
- my $err = $!;
- kill (9, $pid);
- waitpid ($pid, 0);
- die "command '$cmdstr' failed: $err";
- }
- $select->remove ($h) if !$count;
- if ($h eq $reader) {
- if ($outfunc) {
- eval {
- $outlog .= $buf;
- while ($outlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
- my $line = $1;
- &$outfunc ($line);
- }
- };
- my $err = $@;
- if ($err) {
- kill (9, $pid);
- waitpid ($pid, 0);
- die $err;
- }
- } else {
- print $buf;
- *STDOUT->flush();
- }
- } elsif ($h eq $error) {
- if ($errfunc) {
- eval {
- $errlog .= $buf;
- while ($errlog =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
- my $line = $1;
- &$errfunc ($line);
- }
- };
- my $err = $@;
- if ($err) {
- kill (9, $pid);
- waitpid ($pid, 0);
- die $err;
- }
- } else {
- print STDERR $buf;
- *STDERR->flush();
- }
- }
- }
- }
-
- &$outfunc($outlog) if $outfunc && $outlog;
- &$errfunc($errlog) if $errfunc && $errlog;
-
- my $rv = waitpid ($pid, 0);
- my $ec = ($? >> 8);
-
- die "command '$cmdstr' failed with exit code $ec\n" if $ec;
-}
-
sub read_proc_mounts {
local $/; # enable slurp mode
Modified: pve-storage/pve2/control.in
===================================================================
--- pve-storage/pve2/control.in 2010-08-16 11:00:57 UTC (rev 5008)
+++ pve-storage/pve2/control.in 2010-08-16 11:02:55 UTC (rev 5009)
@@ -3,7 +3,7 @@
Section: perl
Priority: optional
Architecture: @@ARCH@@
-Depends: perl (>= 5.6.0-16), libfilesys-df-perl, nfs-common, udev
+Depends: perl (>= 5.6.0-16), libfilesys-df-perl, nfs-common, udev, libpve-common-perl
Maintainer: Proxmox Support Team <support at proxmox.com>
Description: Proxmox VE storage management library
This package contains the storage management library used by Proxmox VE.
More information about the pve-devel
mailing list