LINUX.ORG.RU

История изменений

Исправление MariaRTI, (текущая версия) :

Немного изменил код. Создал свою переменную и присвоил ей результат =cwd();

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html

# Used as a standard client cmd that can be used for many of the xcat cmds.
# It grabs the arguments, noderange, and stdin and then submits the request to
# xcatd and waits for responses.  Most of the client/server communication is
# contained in Client.pm.

# To use this, sym link your cmd name to this script.
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
use lib "$::XCATROOT/lib/perl";
print " 1";
use Cwd;
#use IO::Socket::SSL;
#use IO::Socket::INET;
print " 2";
use File::Basename;
print " 3";
#use Data::Dumper;
use xCAT::Client;
print " 4";
use strict;
print " 5";
my $bname = basename($0);
print " 6";
my $cmdref;
print " 7";
if ($bname =~ /xcatclient/) { $cmdref->{command}->[0] = shift @ARGV; } # xcatclient was invoked directly and the 1st arg is cmd name that is used to locate the plugin
else { $cmdref->{command}->[0] = $bname; } # the cmd was sym linked to xcatclient
print " 8";
my $my_cwd = cwd();
print " 9 my_cwd=" . $my_cwd;
$cmdref->{cwd}->[0] = $my_cwd;
print " 10";
my $data;
print " 11";
# allows our plugins to get the stdin of the cmd that invoked the plugin
if ((($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/)) || !defined($ENV{'TERM'}))
{
    my $rin = "";
    my $rout;
    vec($rin, fileno(STDIN), 1) = 1;
    my $nfound = select($rout = $rin, "", "", 1);
    if ($nfound)
    {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}
else
{
    if (-p STDIN) {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}

print " 12";
my $arg;
my @tmpargv = @ARGV;

# lslite needs to handle imagename besides noderange
# so do not fill {noderange} if imagename given
my $str = join(',', @tmpargv);
print " 13";
if (($bname =~ /lslite/) && $str =~ /-i/)
{
    $arg = "NO_NODE_RANGE";
}
else
{ # Consider the 1st non-hyphen arg to be the noderange.  All others (before and after) go on the arg list.
    $arg = shift(@ARGV);
    while ($arg =~ /^-/) {
        push(@{ $cmdref->{arg} }, $arg);
        $arg = shift(@ARGV);
    }
}
print " 14";
if ($arg ne "NO_NODE_RANGE") {

    # The noderange can be specified through a noderange file,
    # the noderange file can be a relative path,
    # convert the relative path to a full path.
    # an ideal way is converting the relative path in xCAT::Noderange::noderange,
    # but the existing xCAT::Noderange::noderange can not get the cwd(),
    # needs to change all the callers to pass the cwd(),
    # there are more than 100 callers.
    my @tempnr = ();
    foreach my $nr (split(/,/, $arg)) {
        if ($nr =~ /^\^(.*)$/) {
            my $nrf = $1;
            if ($nrf !~ /^\//) {    #relative path
                $nrf = Cwd::abs_path($nrf);
            }
            $nrf = "\^" . $nrf;
            push @tempnr, $nrf;
        } else {
            push @tempnr, $nr;
        }
    }
    $arg = join(',', @tempnr);
    $cmdref->{noderange}->[0] = $arg;
}
print " 15";
if (@ARGV) {
    push(@{ $cmdref->{arg} }, @ARGV);
}
print " 16";
foreach (keys %ENV) {
    if (/^XCAT_/) {
        $cmdref->{environment}->{$_} = $ENV{$_};
    }
}
print " 17";
# Allow to print server information when -V/--verbose
foreach (reverse(@ARGV)) {
    if ($_ eq '-V' || $_ eq '--verbose') {
        $ENV{'XCATSHOWSVR'} = 1;
        last;
    }
}

print " 18";
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
print " 19";
exit $xCAT::Client::EXITCODE;

Не понятно, почему ошибка генерируется внутри стандартной перловой функции cwd(), а текст ошибки явно из кода xcat. Как они связаны? Порядок выполнения виден по принтам.

root@xcatmn:/home/worker# rpower cn1 status
 1 2 3 4 5 6 7 8cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: timeout
 9 my_cwd=/home/worker 10 11 12 13 14 15 16 17 18 19root@xcatmn:/home/worker# 

на шаге 8, при вызове cwd(), выполнение затормаживается секунды на 3, затем внутри этого шага продолжается с ошибками, далее шаг 9 с печатью результата и далее до конца скрипта.

Исправление MariaRTI, :

Немного изменил код. Создал свою переменную и присвоил ей результат =cwd();

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html

# Used as a standard client cmd that can be used for many of the xcat cmds.
# It grabs the arguments, noderange, and stdin and then submits the request to
# xcatd and waits for responses.  Most of the client/server communication is
# contained in Client.pm.

# To use this, sym link your cmd name to this script.
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
use lib "$::XCATROOT/lib/perl";
print " 1";
use Cwd;
#use IO::Socket::SSL;
#use IO::Socket::INET;
print " 2";
use File::Basename;
print " 3";
#use Data::Dumper;
use xCAT::Client;
print " 4";
use strict;
print " 5";
my $bname = basename($0);
print " 6";
my $cmdref;
print " 7";
if ($bname =~ /xcatclient/) { $cmdref->{command}->[0] = shift @ARGV; } # xcatclient was invoked directly and the 1st arg is cmd name that is used to locate the plugin
else { $cmdref->{command}->[0] = $bname; } # the cmd was sym linked to xcatclient
print " 8";
my $my_cwd = cwd();
print " 9 my_cwd=" . $my_cwd;
$cmdref->{cwd}->[0] = $my_cwd;
print " 10";
my $data;
print " 11";
# allows our plugins to get the stdin of the cmd that invoked the plugin
if ((($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/)) || !defined($ENV{'TERM'}))
{
    my $rin = "";
    my $rout;
    vec($rin, fileno(STDIN), 1) = 1;
    my $nfound = select($rout = $rin, "", "", 1);
    if ($nfound)
    {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}
else
{
    if (-p STDIN) {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}

print " 12";
my $arg;
my @tmpargv = @ARGV;

# lslite needs to handle imagename besides noderange
# so do not fill {noderange} if imagename given
my $str = join(',', @tmpargv);
print " 13";
if (($bname =~ /lslite/) && $str =~ /-i/)
{
    $arg = "NO_NODE_RANGE";
}
else
{ # Consider the 1st non-hyphen arg to be the noderange.  All others (before and after) go on the arg list.
    $arg = shift(@ARGV);
    while ($arg =~ /^-/) {
        push(@{ $cmdref->{arg} }, $arg);
        $arg = shift(@ARGV);
    }
}
print " 14";
if ($arg ne "NO_NODE_RANGE") {

    # The noderange can be specified through a noderange file,
    # the noderange file can be a relative path,
    # convert the relative path to a full path.
    # an ideal way is converting the relative path in xCAT::Noderange::noderange,
    # but the existing xCAT::Noderange::noderange can not get the cwd(),
    # needs to change all the callers to pass the cwd(),
    # there are more than 100 callers.
    my @tempnr = ();
    foreach my $nr (split(/,/, $arg)) {
        if ($nr =~ /^\^(.*)$/) {
            my $nrf = $1;
            if ($nrf !~ /^\//) {    #relative path
                $nrf = Cwd::abs_path($nrf);
            }
            $nrf = "\^" . $nrf;
            push @tempnr, $nrf;
        } else {
            push @tempnr, $nr;
        }
    }
    $arg = join(',', @tempnr);
    $cmdref->{noderange}->[0] = $arg;
}
print " 15";
if (@ARGV) {
    push(@{ $cmdref->{arg} }, @ARGV);
}
print " 16";
foreach (keys %ENV) {
    if (/^XCAT_/) {
        $cmdref->{environment}->{$_} = $ENV{$_};
    }
}
print " 17";
# Allow to print server information when -V/--verbose
foreach (reverse(@ARGV)) {
    if ($_ eq '-V' || $_ eq '--verbose') {
        $ENV{'XCATSHOWSVR'} = 1;
        last;
    }
}

print " 18";
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
print " 19";
exit $xCAT::Client::EXITCODE;

Не понятно, почему ошибка генерируется внутри стандартной перловой функции cwd(), а текст ошибки явно из кода xcat. Как они связаны? Порядок выполнения виден по принтам.

root@xcatmn:/home/worker# rpower cn1 status
 1 2 3 4 5 6 7 8cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: timeout
 9 my_cwd=/home/worker 10 11 12 13 14 15 16 17 18 19root@xcatmn:/home/worker# 

Исходная версия MariaRTI, :

Немного изменил код. Создал свою переменную и присвоил ей результат =cwd();

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html

# Used as a standard client cmd that can be used for many of the xcat cmds.
# It grabs the arguments, noderange, and stdin and then submits the request to
# xcatd and waits for responses.  Most of the client/server communication is
# contained in Client.pm.

# To use this, sym link your cmd name to this script.
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
use lib "$::XCATROOT/lib/perl";
print " 1";
use Cwd;
#use IO::Socket::SSL;
#use IO::Socket::INET;
print " 2";
use File::Basename;
print " 3";
#use Data::Dumper;
use xCAT::Client;
print " 4";
use strict;
print " 5";
my $bname = basename($0);
print " 6";
my $cmdref;
print " 7";
if ($bname =~ /xcatclient/) { $cmdref->{command}->[0] = shift @ARGV; } # xcatclient was invoked directly and the 1st arg is cmd name that is used to locate the plugin
else { $cmdref->{command}->[0] = $bname; } # the cmd was sym linked to xcatclient
print " 8";
my $my_cwd = cwd();
print " 9 my_cwd=" . $my_cwd;
$cmdref->{cwd}->[0] = $my_cwd;
print " 10";
my $data;
print " 11";
# allows our plugins to get the stdin of the cmd that invoked the plugin
if ((($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/)) || !defined($ENV{'TERM'}))
{
    my $rin = "";
    my $rout;
    vec($rin, fileno(STDIN), 1) = 1;
    my $nfound = select($rout = $rin, "", "", 1);
    if ($nfound)
    {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}
else
{
    if (-p STDIN) {
        while (<STDIN>) { $data .= $_; }
        $cmdref->{stdin}->[0] = $data;
    }
}

print " 12";
my $arg;
my @tmpargv = @ARGV;

# lslite needs to handle imagename besides noderange
# so do not fill {noderange} if imagename given
my $str = join(',', @tmpargv);
print " 13";
if (($bname =~ /lslite/) && $str =~ /-i/)
{
    $arg = "NO_NODE_RANGE";
}
else
{ # Consider the 1st non-hyphen arg to be the noderange.  All others (before and after) go on the arg list.
    $arg = shift(@ARGV);
    while ($arg =~ /^-/) {
        push(@{ $cmdref->{arg} }, $arg);
        $arg = shift(@ARGV);
    }
}
print " 14";
if ($arg ne "NO_NODE_RANGE") {

    # The noderange can be specified through a noderange file,
    # the noderange file can be a relative path,
    # convert the relative path to a full path.
    # an ideal way is converting the relative path in xCAT::Noderange::noderange,
    # but the existing xCAT::Noderange::noderange can not get the cwd(),
    # needs to change all the callers to pass the cwd(),
    # there are more than 100 callers.
    my @tempnr = ();
    foreach my $nr (split(/,/, $arg)) {
        if ($nr =~ /^\^(.*)$/) {
            my $nrf = $1;
            if ($nrf !~ /^\//) {    #relative path
                $nrf = Cwd::abs_path($nrf);
            }
            $nrf = "\^" . $nrf;
            push @tempnr, $nrf;
        } else {
            push @tempnr, $nr;
        }
    }
    $arg = join(',', @tempnr);
    $cmdref->{noderange}->[0] = $arg;
}
print " 15";
if (@ARGV) {
    push(@{ $cmdref->{arg} }, @ARGV);
}
print " 16";
foreach (keys %ENV) {
    if (/^XCAT_/) {
        $cmdref->{environment}->{$_} = $ENV{$_};
    }
}
print " 17";
# Allow to print server information when -V/--verbose
foreach (reverse(@ARGV)) {
    if ($_ eq '-V' || $_ eq '--verbose') {
        $ENV{'XCATSHOWSVR'} = 1;
        last;
    }
}

print " 18";
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
print " 19";
exit $xCAT::Client::EXITCODE;

Не понятно, почему выполнение останавливается внутри перловой функции cwd(), а в сообщении об ошибке текст явно из кода xcat. Порядок выполнения виден по принтам.

root@xcatmn:/home/worker# rpower cn1 status
 1 2 3 4 5 6 7 8cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: Invalid authentication algorithm
cn1: [xcatmn]: Error: ERROR: timeout
 9 my_cwd=/home/worker 10 11 12 13 14 15 16 17 18 19root@xcatmn:/home/worker#