version 1.216, 2004/07/27 11:34:49
|
version 1.217, 2004/07/28 21:33:22
|
Line 1138 sub establish_key_handler {
|
Line 1138 sub establish_key_handler {
|
®ister_handler("ekey", \&establish_key_handler, 0, 1,1); |
®ister_handler("ekey", \&establish_key_handler, 0, 1,1); |
|
|
|
|
|
# Handler for the load command. Returns the current system load average |
|
# to the requestor. |
|
# |
|
# Parameters: |
|
# $cmd - the actual keyword that invoked us. |
|
# $tail - the tail of the request that invoked us. |
|
# $replyfd- File descriptor connected to the client |
|
# Implicit Inputs: |
|
# $currenthostid - Global variable that carries the name of the host |
|
# known as. |
|
# $clientname - Global variable that carries the name of the hsot we're connected to. |
|
# Returns: |
|
# 1 - Ok to continue processing. |
|
# 0 - Program should exit. |
|
# Side effects: |
|
# Reply information is sent to the client. |
|
sub load_handler { |
|
my ($cmd, $tail, $replyfd) = @_; |
|
|
|
# Get the load average from /proc/loadavg and calculate it as a percentage of |
|
# the allowed load limit as set by the perl global variable lonLoadLim |
|
|
|
my $loadavg; |
|
my $loadfile=IO::File->new('/proc/loadavg'); |
|
|
|
$loadavg=<$loadfile>; |
|
$loadavg =~ s/\s.*//g; # Extract the first field only. |
|
|
|
my $loadpercent=100*$loadavg/$perlvar{'lonLoadLim'}; |
|
|
|
&Reply( $replyfd, "$loadpercent\n", "$cmd:$tail"); |
|
|
|
return 1; |
|
} |
|
register_handler("load", \&load_handler, 0, 1, 0); |
|
|
|
# |
|
# Process the userload request. This sub returns to the client the current |
|
# user load average. It can be invoked either by clients or managers. |
|
# |
|
# Parameters: |
|
# $cmd - the actual keyword that invoked us. |
|
# $tail - the tail of the request that invoked us. |
|
# $replyfd- File descriptor connected to the client |
|
# Implicit Inputs: |
|
# $currenthostid - Global variable that carries the name of the host |
|
# known as. |
|
# $clientname - Global variable that carries the name of the hsot we're connected to. |
|
# Returns: |
|
# 1 - Ok to continue processing. |
|
# 0 - Program should exit |
|
# Implicit inputs: |
|
# whatever the userload() function requires. |
|
# Implicit outputs: |
|
# the reply is written to the client. |
|
# |
|
sub user_load_handler { |
|
my ($cmd, $tail, $replyfd) = @_; |
|
|
|
my $userloadpercent=&userload(); |
|
&Reply($replyfd, "$userloadpercent\n", "$cmd:$tail"); |
|
|
|
return 1; |
|
} |
|
register_handler("userload", \&user_load_handler, 0, 1, 0); |
|
|
|
|
#--------------------------------------------------------------- |
#--------------------------------------------------------------- |
# |
# |
Line 1252 sub process_request {
|
Line 1318 sub process_request {
|
|
|
#------------------- Commands not yet in spearate handlers. -------------- |
#------------------- Commands not yet in spearate handlers. -------------- |
|
|
# ------------------------------------------------------------------------ load |
|
if ($userinput =~ /^load/) { # client only |
|
if (isClient) { |
|
my $loadavg; |
|
{ |
|
my $loadfile=IO::File->new('/proc/loadavg'); |
|
$loadavg=<$loadfile>; |
|
} |
|
$loadavg =~ s/\s.*//g; |
|
my $loadpercent=100*$loadavg/$perlvar{'lonLoadLim'}; |
|
print $client "$loadpercent\n"; |
|
} else { |
|
Reply($client, "refused\n", $userinput); |
|
|
|
} |
|
# -------------------------------------------------------------------- userload |
|
} elsif ($userinput =~ /^userload/) { # client only |
|
if(isClient) { |
|
my $userloadpercent=&userload(); |
|
print $client "$userloadpercent\n"; |
|
} else { |
|
Reply($client, "refused\n", $userinput); |
|
|
|
} |
|
# |
|
# Transactions requiring encryption: |
|
# |
|
# ----------------------------------------------------------------- currentauth |
# ----------------------------------------------------------------- currentauth |
} elsif ($userinput =~ /^currentauth/) { |
if ($userinput =~ /^currentauth/) { |
if (($wasenc==1) && isClient) { # Encoded & client only. |
if (($wasenc==1) && isClient) { # Encoded & client only. |
my ($cmd,$udom,$uname)=split(/:/,$userinput); |
my ($cmd,$udom,$uname)=split(/:/,$userinput); |
my $result = GetAuthType($udom, $uname); |
my $result = GetAuthType($udom, $uname); |