From 07f02d62cf03c1fd95c8d2c927d8a134de9328ad Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Wed, 28 Oct 2015 09:31:10 +0000 Subject: [PATCH] [xCAT-server]xcatd: add space between `#` and comments, remove space between `#` and commented code --- xCAT-server/sbin/xcatd | 482 ++++++++++++++++++++--------------------- 1 file changed, 241 insertions(+), 241 deletions(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index b1c6a08e0..4b575569b 100644 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -28,12 +28,12 @@ my $udpctl; my $pid_UDP; my $pid_MON; -#----used for command log start--------- +# ----used for command log start--------- my $cmdlog_svrpid; -#----used for command log end--------- +# ----used for command log end--------- # if AIX - make sure we include perl 5.8.2 in INC path. -# Needed to find perl dependencies shipped in deps tarball. +# Needed to find perl dependencies shipped in deps tarball. if ($^O =~ /^aix/i) { unshift(@INC, qw(/usr/opt/perl5/lib/5.8.2/aix-thread-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.2)); } @@ -56,11 +56,11 @@ use Thread qw(yield); use Fcntl qw/:DEFAULT :flock/; use xCAT::Client qw(submit_request); my $clientselect = new IO::Select; -my $sslclients = 0; #THROTTLE -my $maxsslclients = 64; #default +my $sslclients = 0; # THROTTLE +my $maxsslclients = 64; # default my $batchclients = 50; my @deferredmsgargs; # hold argumentlist for MsgUtils call until after fork - #parallelizing logging overhead with real work + # parallelizing logging overhead with real work sub xexit { while (wait() > 0) { @@ -113,7 +113,7 @@ use Getopt::Long; use Sys::Syslog qw(:DEFAULT setlogsock); openlog("xcat",,"local4"); # turn off warnings for call to setlogsock. puts out warning message if -# syslog tcp port not defined in /etc/services. this can safely be ignored. +# syslog tcp port not defined in /etc/services. this can safely be ignored. no warnings; setlogsock(["tcp","unix","stream"]); use warnings; @@ -138,7 +138,7 @@ unless ($pidfile) { $pidfile = "/var/run/xcatd.pid"; } -#start syslog if it is not up +# start syslog if it is not up if (xCAT::Utils->isLinux()) { my $init_file="/etc/init.d/syslog"; if ((-f "/etc/fedora-release") || (-f "/etc/redhat-release") || (-f "/etc/lsb-release")) { @@ -197,7 +197,7 @@ my $plugins_dir=$::XCATROOT.'/lib/perl/xCAT_plugin'; ($tmp) = $sitetab->getAttribs({'key'=>'xcatconfdir'},'value'); $xcatdir = (($tmp and $tmp->{value}) ? $tmp->{value} : "/etc/xcat"); -#----used for command log start------- +# ----used for command log start------- my $cmdlog_logfile="/var/log/xcat/commands.log"; my $cmdlog_port=3003; ($tmp) = $sitetab->getAttribs({'key'=>'xcatlport'},'value'); @@ -205,7 +205,7 @@ if ($tmp) { $cmdlog_port = $tmp->{value}; } my $cmdlog_alllog="====================================================\n"; -#----used for command log end--------- +# ----used for command log end--------- $sitetab->close; @@ -217,9 +217,9 @@ $SIG{PIPE} = sub { }; $progname = \$0; -#create and update any xCAt tables -#create the user defined external database tables if they do not exist. -#update the tables if there are schema changes. +# create and update any xCAt tables +# create the user defined external database tables if they do not exist. +# update the tables if there are schema changes. # runsqlcmd runs sql scripts provided by the user in # /opt/xcat/lib/perl/xCAT_schema @@ -290,12 +290,12 @@ my $rescanrselect; my $rescanrequest = "rescanplugins"; sub do_installm_service { unless ($sport) { return; } - #This function servers as a handler for messages from installing nodes + # This function servers as a handler for messages from installing nodes my $socket; my $installpidfile; my $retry=1; $SIG{USR2} = sub { - if ($socket) { #do not mess with pid file except when we still have the socket. + if ($socket) { # do not mess with pid file except when we still have the socket. unlink("/var/run/xcat/installservice.pid"); close($socket); $quit=1; $udpctl=0; xCAT::MsgUtils->message("S","xcatd install monitor $$ quiescing"); @@ -312,11 +312,11 @@ my $socket; ReuseAddr => 1, Listen => 8192); } - if (not $socket and open($installpidfile,"<","/var/run/xcat/installservice.pid")) { #if we couldn't get the socket, go to pid to figure out current owner - #TODO: lsof or similar may be a more accurate measure + if (not $socket and open($installpidfile,"<","/var/run/xcat/installservice.pid")) { # if we couldn't get the socket, go to pid to figure out current owner + # TODO: lsof or similar may be a more accurate measure my $pid = <$installpidfile>; if ($pid) { - $retry=100; #grace period for old instance to get out of the way, 5 seconds + $retry=100; # grace period for old instance to get out of the way, 5 seconds kill 12,$pid; yield(); # let peer have a shot at closure } @@ -335,15 +335,15 @@ if ($inet6support) { ReuseAddr => 1, Listen => 8192); } -sleep 0.05; #up to 50 ms outage possible +sleep 0.05; # up to 50 ms outage possible } unless ($socket) { xCAT::MsgUtils->message("S","xcatd unable to open install monitor services on $sport"); die; } - #we have the socket, now we claim the pid file as our own - open($installpidfile,">","/var/run/xcat/installservice.pid"); #if here, everyone else has unlinked installservicepid or doesn't care + # we have the socket, now we claim the pid file as our own + open($installpidfile,">","/var/run/xcat/installservice.pid"); # if here, everyone else has unlinked installservicepid or doesn't care print $installpidfile $$; close($installpidfile); until ($quit) { @@ -394,9 +394,9 @@ sleep 0.05; #up to 50 ms outage possible } else { $client =~ s/\..*//; } - #ensure this is coming from a node IP at least + # ensure this is coming from a node IP at least ($node) = noderange($client); - if ($node) { #Means the source isn't valid + if ($node) { # Means the source isn't valid $validclient=1; last; } @@ -420,11 +420,11 @@ sleep 0.05; #up to 50 ms outage possible node => [ $node ], arg => [ 'next' ], ); - #node should be blocked, race condition may occur otherwise + # node should be blocked, race condition may occur otherwise #my $pid=xCAT::Utils->xfork(); - #unless ($pid) { #fork off the nodeset and potential slowness + #unless ($pid) { # fork off the nodeset and potential slowness plugin_command(\%request,undef,\&build_response); - # exit(0); + #exit(0); #} close($conn); } elsif ($text =~ /installstatus/) { @@ -436,15 +436,15 @@ sleep 0.05; #up to 50 ms outage possible node => [ $node ], arg => [ "$newstat" ], ); - #node should be blocked, race condition may occur otherwise + # node should be blocked, race condition may occur otherwise #my $pid=xCAT::Utils->xfork(); - #unless ($pid) { #fork off the nodeset and potential slowness + #unless ($pid) { # fork off the nodeset and potential slowness plugin_command(\%request,undef,\&build_response); - # exit(0); + #exit(0); #} } close($conn); - } elsif ($text =~ /^unlocktftpdir/) { #TODO: only nodes in install state should be allowed + } elsif ($text =~ /^unlocktftpdir/) { # TODO: only nodes in install state should be allowed mkpath("$tftpdir/xcat/$node"); chmod 01777,"$tftpdir/xcat/$node"; chmod 0666,glob("$tftpdir/xcat/$node/*"); @@ -486,7 +486,7 @@ sleep 0.05; #up to 50 ms outage possible arg => [ 'enact' ], ); my $pid=xCAT::Utils->xfork(); - unless ($pid) { #fork off the nodeset and potential slowness + unless ($pid) { # fork off the nodeset and potential slowness plugin_command(\%request,undef,\&build_response); xexit(0); } @@ -525,7 +525,7 @@ sleep 0.05; #up to 50 ms outage possible } if (open($installpidfile,"<","/var/run/xcat/installservice.pid")) { my $pid = <$installpidfile>; - if ($pid == $$) { #if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it + if ($pid == $$) { # if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it unlink("/var/run/xcat/installservice.pid"); } close($installpidfile); @@ -539,22 +539,22 @@ sub grant_tcrequests { my $availableslots = $batchclients; if (not keys %{$requestors}) { return; } # skip the interaction with SSL if # no requests are actually pending - my $oldtime = time()-180; #drop requests older than three minutes if still around + my $oldtime = time()-180; # drop requests older than three minutes if still around my $msg; eval { store_fd({'req'=>'get_client_count'}, $sslctl); $msg = fd_retrieve($sslctl); }; if (not $msg) { return; } - $availableslots -= $msg->{clientfudge}; #value that forecasts the pressure - $availableslots -= $msg->{sslclientcount}; #subtract all currently really active sessions + $availableslots -= $msg->{clientfudge}; # value that forecasts the pressure + $availableslots -= $msg->{sslclientcount}; # subtract all currently really active sessions my $fudgefactor = $msg->{clientfudge}; foreach my $rkey (keys %{$requestors}) { if ($requestors->{$rkey}->{timestamp} < $oldtime) { delete $requestors->{$rkey}; next; } unless ($availableslots > 0) { next; } # no slots, ignore requests for now - $fudgefactor += 1; #adjust forecast for being busy + $fudgefactor += 1; # adjust forecast for being busy $availableslots-=1; $udpcontext->{socket}->send("resourcerequest: ok\n",0,$requestors->{$rkey}->{sockaddr}); - delete ($requestors->{$rkey}); #we acknoweldged, assume consumer got it, they'll do retry if they failed + delete ($requestors->{$rkey}); # we acknoweldged, assume consumer got it, they'll do retry if they failed } eval { store_fd({'req'=>'set_fudge_factor', 'fudge'=>$fudgefactor}, $sslctl); $msg = fd_retrieve($sslctl); }; } @@ -576,7 +576,7 @@ sub do_discovery_process { populate_vpd_hash(); populate_mp_hash(); $vintage = time(); - } #site table reread every 15 second + } # site table reread every 15 second my $msg = fd_retrieve($broker); my $data; my $client; @@ -598,18 +598,18 @@ sub do_discovery_process { $clientip = inet_ntoa($clientn); $client=gethostbyaddr($clientn,AF_INET); } - if ($data =~ /^\037\213/) { #per rfc 1952, these two bytes are gzip, and they are invalid for - #xcatrequest xml, so go ahead and decompress it + if ($data =~ /^\037\213/) { # per rfc 1952, these two bytes are gzip, and they are invalid for + # xcatrequest xml, so go ahead and decompress it my $bigdata; IO::Uncompress::Gunzip::gunzip(\$data,\$bigdata); $data = $bigdata } my $req = eval { XMLin($data, SuppressEmpty=>undef,ForceArray=>1) }; - if ($req and $req->{command} and ($req->{command}->[0] eq "findme" and $sport < 1000)) { #only consider priveleged port requests to start with + if ($req and $req->{command} and ($req->{command}->[0] eq "findme" and $sport < 1000)) { # only consider priveleged port requests to start with $req->{'_xcat_clienthost'}=$client; $req->{'_xcat_clientip'}=$clientip; $req->{'_xcat_clientport'}=$sport; - if (defined($cmd_handlers{"findme"}) and xCAT::NetworkUtils->nodeonmynet($clientip)) { #only discover from ips that appear to be on a managed network + if (defined($cmd_handlers{"findme"}) and xCAT::NetworkUtils->nodeonmynet($clientip)) { # only discover from ips that appear to be on a managed network xCAT::MsgUtils->message("S","xcatd: Processing discovery request from ".$req->{'_xcat_clientip'}); $req->{cacheonly}->[0] = 1; plugin_command($req,undef,\&build_response); @@ -623,14 +623,14 @@ sub do_discovery_process { } } } -sub do_udp_service { #This function opens up a UDP port - #It will do similar to the standard service, except: - #-Obviously, unencrypted and messages are not guaranteed - #-For that reason, more often than not plugins designed with - #-this method will not expect to have a callback - #Also, this throttles to handle one message at a time, so no forking either - #Explicitly, to handle whatever operations nodes periodically send during discover state - #Could be used for heartbeating and such as desired +sub do_udp_service { # This function opens up a UDP port + # It will do similar to the standard service, except: + # -Obviously, unencrypted and messages are not guaranteed + # -For that reason, more often than not plugins designed with + # -this method will not expect to have a callback + # Also, this throttles to handle one message at a time, so no forking either + # Explicitly, to handle whatever operations nodes periodically send during discover state + # Could be used for heartbeating and such as desired my %args=@_; my $discoctl = $args{discoctl}; $dispatch_requests=0; @@ -642,7 +642,7 @@ sub do_udp_service { #This function opens up a UDP port my $discopid = $args{discopid}; $SIG{USR2} = sub { if ($socket) { - #only clear out pid file when we still have socket. + # only clear out pid file when we still have socket. unlink("/var/run/xcat/udpservice.pid"); close($socket); $quit=1; $socket=0; $udpctl=0; xCAT::MsgUtils->message("S","xcatd udp service $$ quiescing"); @@ -661,7 +661,7 @@ sub do_udp_service { #This function opens up a UDP port if (not $socket and open($udppidfile,"<","/var/run/xcat/udpservice.pid")) { my $pid = <$udppidfile>; if ($pid) { - $retry=100; #grace period for old instance to get out of the way, 5 seconds + $retry=100; # grace period for old instance to get out of the way, 5 seconds kill 12,$pid; yield(); # let peer have a shot at closure } @@ -688,8 +688,8 @@ sub do_udp_service { #This function opens up a UDP port closelog(); die "Unable to start UDP on $port"; } - #only take udp pid if we get the socket - open($udppidfile,">","/var/run/xcat/udpservice.pid"); #if here, everyone else has unlinked udpservicepid or doesn't care + # only take udp pid if we get the socket + open($udppidfile,">","/var/run/xcat/udpservice.pid"); # if here, everyone else has unlinked udpservicepid or doesn't care print $udppidfile $$; close($udppidfile); $select->add($socket); @@ -707,17 +707,17 @@ sub do_udp_service { #This function opens up a UDP port eval { my $tcclients; # hash reference to store traffic control requests while (1) { - unless ($actualpid == $$) { #This really should be impossible now... + unless ($actualpid == $$) { # This really should be impossible now... xCAT::MsgUtils->message("S","xcatd: Something absolutely ludicrous happpened, xCAT developers think this message is impossible to see, post if you see it, fork bomb averted"); exit(1); } - until ($select->can_read(5)) { #Wait for data + until ($select->can_read(5)) { # Wait for data if ($quit) { last; }; populate_site_hash(); yield; } my @hdls; - while (@hdls = $select->can_read(0)) { #Pull all buffer data that can be pulled + while (@hdls = $select->can_read(0)) { # Pull all buffer data that can be pulled my $hdl; foreach $hdl (@hdls) { if ($hdl == $socket) { @@ -726,7 +726,7 @@ sub do_udp_service { #This function opens up a UDP port } elsif ($hdl == $sslctl) { next; #update_udpcontext_from_sslctl(udpcontext=>$udpcontext,select=>$select); - } elsif ($hdl == $discoctl) { #got a discovery response.... + } elsif ($hdl == $discoctl) { # got a discovery response.... } else { print "Something is wrong in udp process (search xcatd for this string)\n"; } @@ -735,9 +735,9 @@ sub do_udp_service { #This function opens up a UDP port foreach my $pkey (keys %packets) { my $saddr = $packets{$pkey}->[0]; $data=$packets{$pkey}->[1]; - if ($data =~ /^\037\213/) { #per rfc 1952, these two bytes are gzip, and they are invalid for - store_fd({data=>$data,sockaddr=>$saddr},$discoctl); #for now, punt the gunzip to the worker process - } elsif ($data =~ /^$data,sockaddr=>$saddr},$discoctl); # for now, punt the gunzip to the worker process + } elsif ($data =~ /^$data,sockaddr=>$saddr},$discoctl); } else { # for *now*, we'll do a tiny YAML subset if ($data =~ /^resourcerequest: xcatd$/) { @@ -746,7 +746,7 @@ sub do_udp_service { #This function opens up a UDP port } } # JSON maybe one day if important if ($quit) { last; } - while (@hdls = $select->can_read(0)) { #grab any incoming requests during run + while (@hdls = $select->can_read(0)) { # grab any incoming requests during run foreach my $hdl (@hdls) { if ($hdl == $socket) { $part = $socket->recv($data,1500); @@ -756,8 +756,8 @@ sub do_udp_service { #This function opens up a UDP port } } } - #Some of those 'future' packets might be stale dupes of this packet, so... - delete $packets{$pkey}; #Delete any duplicates of current packet + # Some of those 'future' packets might be stale dupes of this packet, so... + delete $packets{$pkey}; # Delete any duplicates of current packet } if ($quit) { last; } grant_tcrequests($tcclients,$udpcontext); @@ -766,14 +766,14 @@ sub do_udp_service { #This function opens up a UDP port if ($@) { xCAT::MsgUtils->message("S","xcatd: possible BUG encountered by xCAT UDP service: ".$@); } - unless ($actualpid == $$) { #We should absolutely never be here, exponential growth from a plugin crash. + unless ($actualpid == $$) { # We should absolutely never be here, exponential growth from a plugin crash. xCAT::MsgUtils->message("S","xcatd: Something ludicrous happpened, bailing to avoid fork bomb, double check perl XS modules like 'net-snmp-perl'"); exit 1; } } if (open($udppidfile,"<","/var/run/xcat/udpservice.pid")) { my $pid = <$udppidfile>; - if ($pid == $$) { #if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it + if ($pid == $$) { # if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it unlink("/var/run/xcat/udpservice.pid"); } close($udppidfile); @@ -844,7 +844,7 @@ if (socketpair($readpipe, $writepipe,AF_UNIX,SOCK_STREAM,PF_UNSPEC)) { xCAT::MsgUtils->message("S", "socketpair failed: $!"); } if (defined $pid_init) { - if ($pid_init) { #parent, just sit and wait.. + if ($pid_init) { # parent, just sit and wait.. close($writepipe); %cmd_handlers = %{fd_retrieve($readpipe)}; } else { @@ -872,7 +872,7 @@ unless ($foreground) { } $dbmaster=xCAT::Table::init_dbworker; -my $CHILDPID=0; #Global for reapers +my $CHILDPID=0; # Global for reapers my %immediatechildren; sub generic_reaper { local($!); @@ -956,11 +956,11 @@ $SIG{TERM} = $SIG{INT} = sub { kill 2, $dbmaster; } - #----used for command log start--------- + # ----used for command log start--------- if ($cmdlog_svrpid){ kill 2, $cmdlog_svrpid; } - #----used for command log end--------- + # ----used for command log end--------- $SIG{ALRM} = sub { xexit 0; }; #die "Did not close out in time for 5 second grace period"; }; alarm(2); @@ -991,7 +991,7 @@ unless ($pid_UDP) { xCAT::MsgUtils->message("S", "Unable to fork for UDP/TCP"); die; } - unless ($pid_disco) { #this is the child, therefore the discovery process.. + unless ($pid_disco) { # this is the child, therefore the discovery process.. close($discoctl); $$progname="xcatd: Discovery worker"; do_discovery_process(broker=>$udpbroker); @@ -1031,7 +1031,7 @@ unless ($pid_MON) { xexit(0); } -#----used for command log start--------- +# ----used for command log start--------- $cmdlog_svrpid = xCAT::Utils->xfork; if (! defined $cmdlog_svrpid) { print "xCAT command log sever unable to fork"; @@ -1069,9 +1069,9 @@ unless ($cmdlog_svrpid){ exit(0); }; - #To support another separate feature "logrotate", that feature will change commands.log name every certain time. - #when it changes the commands.log name, it will send HUP signal to 'command log writer' process. - #so when 'command log writer' process receives the HUP siganl, it should reopen the commands.log to make log writing correctly. + # To support another separate feature "logrotate", that feature will change commands.log name every certain time. + # when it changes the commands.log name, it will send HUP signal to 'command log writer' process. + # so when 'command log writer' process receives the HUP siganl, it should reopen the commands.log to make log writing correctly. $SIG{HUP} = sub { my $trytime=200; while($writing){sleep(0.01);} @@ -1160,7 +1160,7 @@ unless ($cmdlog_svrpid){ if($cmdlogsvrlistener){close($cmdlogsvrlistener);} xCAT::MsgUtils->message("S","INFO xcatd: 'Command log writer' process $$ stop"); } -#----used for command log end--------- +# ----used for command log end--------- $$progname="xcatd: SSL listener"; @@ -1181,10 +1181,10 @@ $SIG{TRAP} = sub { } }; -#setup signal in NotifHandler so that the cache can be updated +# setup signal in NotifHandler so that the cache can be updated xCAT::NotifHandler::setup($$, $dbmaster); -#start the monitoring process +# start the monitoring process xCAT_monitoring::monitorctrl::start($$); # Set up communication pipe to have subcommand process be able to reload the @@ -1227,7 +1227,7 @@ $SIG{USR2} = sub { if (not $listener and open($mainpidfile,"<","/var/run/xcat/mainservice.pid")) { my $pid = <$mainpidfile>; if ($pid) { - $retry=100; #grace period for old instance to get out of the way, 5 seconds + $retry=100; # grace period for old instance to get out of the way, 5 seconds kill 12,$pid; yield(); # let peer have a shot at closure } @@ -1273,8 +1273,8 @@ if ($startupparent) { close($startupparent); } -#only write to pid file if we have listener, listener ownership serves as lock to protect integrity -open($mainpidfile,">","/var/run/xcat/mainservice.pid"); #if here, everyone else has unlinked mainservicepid or doesn't care +# only write to pid file if we have listener, listener ownership serves as lock to protect integrity +open($mainpidfile,">","/var/run/xcat/mainservice.pid"); # if here, everyone else has unlinked mainservicepid or doesn't care print $mainpidfile $$; close($mainpidfile); closelog(); @@ -1283,7 +1283,7 @@ my $tconn; my $sslfudgefactor = 0; my $udpalive = 1; until ($quit) { - $SIG{CHLD} = \&ssl_reaper; #set here to ensure that signal handler is not corrupted during loop + $SIG{CHLD} = \&ssl_reaper; # set here to ensure that signal handler is not corrupted during loop while ($udpalive and $udpwatcher->can_read(0)) { # take an intermission to broker some state requests from udp traffic control eval { my $msg = fd_retrieve($udpctl); @@ -1300,7 +1300,7 @@ until ($quit) { } } if (@pendingconnections) { - while ($listenwatcher->can_read(0)) { #grab everything we can, but don't spend any time waiting for more + while ($listenwatcher->can_read(0)) { # grab everything we can, but don't spend any time waiting for more $tconn = $listener->accept; unless ($tconn) { next; } push @pendingconnections,$tconn; @@ -1321,30 +1321,30 @@ until ($quit) { # we have no listen to hear next; } - $tconn = $listener->accept; #we have no connections pending, no rush, just wait until the next connection attempt comes in - unless ($tconn) { next; } #sometimes we get 'undef', in which case carry on with our lives... + $tconn = $listener->accept; # we have no connections pending, no rush, just wait until the next connection attempt comes in + unless ($tconn) { next; } # sometimes we get 'undef', in which case carry on with our lives... push @pendingconnections,$tconn; } - unless (scalar @pendingconnections) { next; } #if for some reason we landed here without any accepted connections, carry on.. - if ($sslclients > $maxsslclients) { #we have enough children, wait for some to exit before spawning more - $bothwatcher->can_read(0.1); #when next connection tries to come in or a tenth of a second, whichever comes first - next; #just keep pulling things off listen queue onto our own + unless (scalar @pendingconnections) { next; } # if for some reason we landed here without any accepted connections, carry on.. + if ($sslclients > $maxsslclients) { # we have enough children, wait for some to exit before spawning more + $bothwatcher->can_read(0.1); # when next connection tries to come in or a tenth of a second, whichever comes first + next; # just keep pulling things off listen queue onto our own } # before we fork, check to see if rescanplugins was previously processed and - # we now have a new cmd_handlers hash to refresh + # we now have a new cmd_handlers hash to refresh my @chdata; if (@chdata = $chrselect->can_read(0)) { foreach my $chd (@chdata) { %cmd_handlers = %{fd_retrieve($chd)}; } } - #we have a pending connection and we are under the threshold, grab one from the list and process it... + # we have a pending connection and we are under the threshold, grab one from the list and process it... my $cnnection=shift @pendingconnections; - #my $previous = select ($cnnection); #assure that perl buffering is not in play at the low level + #my $previous = select ($cnnection); # assure that perl buffering is not in play at the low level #$|=1; #select ($previous); my $connection; - my $child = xCAT::Utils->xfork(); #Yes we fork, IO::Socket::SSL is not threadsafe.. + my $child = xCAT::Utils->xfork(); # Yes we fork, IO::Socket::SSL is not threadsafe.. if ($child) { $immediatechildren{$child}=1; } @@ -1357,7 +1357,7 @@ until ($quit) { if ($child == 0) { close($udpctl); $udpctl=0; $SIG{TERM} = $SIG{INT} = 'DEFAULT'; - $SIG{CHLD} = \&generic_reaper; #THROTTLE + $SIG{CHLD} = \&generic_reaper; # THROTTLE $listener->close; populate_site_hash(); @@ -1380,16 +1380,16 @@ until ($quit) { alarm(0); }; $SIG{ALRM}='DEFAULT'; - if ($@) { #SSL failure + if ($@) { # SSL failure close($cnnection); xexit 0; } unless ($connection) { xexit 0; } - # $previous=select($connection); #also assure buffering not in play at SSL socket, which seems to be possibly independent of lower socket - # $|=1; - # select($previous); + #$previous=select($connection); # also assure buffering not in play at SSL socket, which seems to be possibly independent of lower socket + #$|=1; + #select($previous); $clientselect->add($connection); my $peerhost=undef; my $peerfqdn=undef; @@ -1443,12 +1443,12 @@ if ($inet6support) { xexit(0); } if ($sslfudgefactor) { $sslfudgefactor -= 1; } - $sslclients++; #THROTTLE + $sslclients++; # THROTTLE $cnnection->close(); } if (open($mainpidfile,"<","/var/run/xcat/mainservice.pid")) { my $pid = <$mainpidfile>; - if ($pid == $$) { #if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it + if ($pid == $$) { # if our pid, unlink the file, otherwise, we managed to see the pid after someone else created it unlink("/var/run/xcat/mainservice.pid"); } close($mainpidfile); @@ -1466,7 +1466,7 @@ if ($dbmaster) { kill 2, $dbmaster; } -#stop the monitoring process +# stop the monitoring process xCAT_monitoring::monitorctrl::stop($$); my $parent_fd; @@ -1489,7 +1489,7 @@ sub plugin_command { if ($req->{node}) { @nodes = @{$req->{node}}; } elsif ($req->{noderange} and $req->{noderange}->[0]) { - xCAT::NodeRange::retain_cache(0); #if the request has a 'noderange' element, take the performance hit for the sake of freshness + xCAT::NodeRange::retain_cache(0); # if the request has a 'noderange' element, take the performance hit for the sake of freshness @nodes = noderange($req->{noderange}->[0]); if (nodesmissed) { my $rsp = {errorcode=>['1'],error=>["Invalid nodes and/or groups in noderange: ".join(',',nodesmissed)]}; @@ -1513,29 +1513,29 @@ sub plugin_command { if (defined($cmd_handlers{$req->{command}->[0]})) { my $hdlspec; my @globalhandlers=(); - my $useglobals=1; #If it stays 1, then use globals normally, if 0, use only for 'unhandled_nodes, if -1, don't do at all + my $useglobals=1; # If it stays 1, then use globals normally, if 0, use only for 'unhandled_nodes, if -1, don't do at all my %hdlrcaches; foreach (@{$cmd_handlers{$req->{command}->[0]}}) { $hdlspec =$_->[1]; my $ownmod = $_->[0]; - if ($hdlspec =~ /^site:/) { #A site entry specifies a plugin + if ($hdlspec =~ /^site:/) { # A site entry specifies a plugin my $sitekey = $hdlspec; $sitekey =~ s/^site://; - if ($::XCATSITEVALS{$sitekey}) {#A site style plugin specification is just like - #a static global, it grabs all nodes rather than some - $useglobals = -1; #If they tried to specify anything, don't use the default global handlers at all + if ($::XCATSITEVALS{$sitekey}) {# A site style plugin specification is just like + # a static global, it grabs all nodes rather than some + $useglobals = -1; # If they tried to specify anything, don't use the default global handlers at all unless (@nodes) { $handler_hash{$::XCATSITEVALS{$sitekey}} = 1; $usesiteglobal = 1; } - foreach (@nodes) { #Specified a specific plugin, not a table lookup + foreach (@nodes) { # Specified a specific plugin, not a table lookup $handler_hash{$::XCATSITEVALS{$sitekey}}->{$_} = 1; } } - } elsif ($hdlspec =~ /:/) { #Specificed a table lookup path for plugin name + } elsif ($hdlspec =~ /:/) { # Specificed a table lookup path for plugin name if (@nodes) { # only use table lookup plugin if nodelist exists # Usage will be handled in common AAAhelp plugin - $useglobals = 0; #Only contemplate nodes that aren't caught through searching below in the global handler + $useglobals = 0; # Only contemplate nodes that aren't caught through searching below in the global handler $useunhandled=1; my $table; my $cols; @@ -1552,7 +1552,7 @@ sub plugin_command { my $node; my $colvals = {}; foreach my $colu (@colmns) { - if ($colu =~ /=/) { #a value redirect to a pattern/specific name + if ($colu =~ /=/) { # a value redirect to a pattern/specific name my $coln; my $colv; ($coln,$colv) = split(/=/,$colu,2); $colvals->{$coln} = $colv; @@ -1563,7 +1563,7 @@ sub plugin_command { } - unless (@nodes) { #register the plugin in the event of usage + unless (@nodes) { # register the plugin in the event of usage $handler_hash{$ownmod} = 1; $useglobals = 1; } @@ -1577,7 +1577,7 @@ sub plugin_command { foreach (@columns) { my $col=$_; if (defined($attribs->{$col})) { - if ($colvals->{$col}) { #A pattern match style request. + if ($colvals->{$col}) { # A pattern match style request. if ($attribs->{$col} =~ /$colvals->{$col}/) { $handler_hash{$ownmod}->{$node} = 1; delete $unhandled_nodes{$node}; @@ -1601,18 +1601,18 @@ sub plugin_command { push @globalhandlers,$hdlspec; } } - if ($useglobals == 1) { #Behavior when globals have not been overriden + if ($useglobals == 1) { # Behavior when globals have not been overriden my $hdlspec; foreach $hdlspec (@globalhandlers) { unless (@nodes) { $handler_hash{$hdlspec} = 1; } - foreach (@nodes) { #Specified a specific plugin, not a table lookup + foreach (@nodes) { # Specified a specific plugin, not a table lookup $handler_hash{$hdlspec}->{$_} = 1; } } } elsif ($useglobals == 0) { - unless (@nodes or $usesiteglobal) { #if something like 'makedhcp -n', + unless (@nodes or $usesiteglobal) { # if something like 'makedhcp -n', foreach (keys %handler_hash) { if ($handler_hash{$_} == 1) { delete ($handler_hash{$_}) @@ -1623,13 +1623,13 @@ sub plugin_command { unless (@nodes or $usesiteglobal) { $handler_hash{$hdlspec} = 1; } - foreach (keys %unhandled_nodes) { #Specified a specific plugin, not a table lookup + foreach (keys %unhandled_nodes) { # Specified a specific plugin, not a table lookup $handler_hash{$hdlspec}->{$_} = 1; } } - } #Otherwise, global handler is implicitly disabled + } # Otherwise, global handler is implicitly disabled } else { - return 1; #TODO: error back that request has no known plugin for it + return 1; # TODO: error back that request has no known plugin for it } if ($useunhandled) { my $queuelist=''; @@ -1690,13 +1690,13 @@ sub plugin_command { my $oldprogname=$$progname; $$progname=$oldprogname.": $modname instance"; unless ($handler_hash{$_} == 1) { - #ok, if nodes have numbers, this sorts them numerically... roughly.. - #if node doesn't, then it sorts out alphabetically. + # ok, if nodes have numbers, this sorts them numerically... roughly.. + # if node doesn't, then it sorts out alphabetically. my @nodes = sort {($a =~ /(\d+)/ ? $1 : -1)[0] <=> ($b =~ /(\d+)/ ? $1 : -1)[0] || $a cmp $b } (keys %{$handler_hash{$_}}); $req->{node}=\@nodes; } no strict "refs"; - eval { #REMOVEEVALFORDEBUG + eval { # REMOVEEVALFORDEBUG if ($dispatch_requests) { dispatch_request($req,$callback,$modname); } else { @@ -1716,8 +1716,8 @@ sub plugin_command { } } $$progname=$oldprogname; - }; #REMOVEEVALFORDEBUG - if ($@) { #We are still alive, should be alive, but yet we have an error. This means we are in the case of 'do_request' or something similar. Forward up the death since our communication channel is intact.. + }; # REMOVEEVALFORDEBUG + if ($@) { # We are still alive, should be alive, but yet we have an error. This means we are in the case of 'do_request' or something similar. Forward up the death since our communication channel is intact.. xCAT::MsgUtils->message("S", "$@"); die $@; } @@ -1751,10 +1751,10 @@ sub plugin_command { if (-r $plugins_dir."/".$modname.".pm") { require $plugins_dir."/".$modname.".pm"; $plugin_numchildren++; - my $pfd; #will be referenced for inter-process messaging. - my $parfd; #not causing a problem that I discern yet, but theoretically + my $pfd; # will be referenced for inter-process messaging. + my $parfd; # not causing a problem that I discern yet, but theoretically my $child; - if ($sock) { #If $sock not passed in, don't fork.. + if ($sock) { # If $sock not passed in, don't fork.. if (! socketpair($pfd, $parfd,AF_UNIX,SOCK_STREAM,PF_UNSPEC)) { xCAT::MsgUtils->message("S", "socketpair failed: $!"); die; @@ -1781,7 +1781,7 @@ sub plugin_command { die; } if ($child == 0) { - if ($parfd) { #If xCAT is doing multiple requests in same communication PID, things would get unfortunate otherwise + if ($parfd) { # If xCAT is doing multiple requests in same communication PID, things would get unfortunate otherwise $parent_fd = $parfd; } my $org_parent_fd = $parent_fd; @@ -1789,13 +1789,13 @@ sub plugin_command { $$progname=$oldprogname.": $modname instance"; if ($sock) { close $pfd; } unless ($handler_hash{$_} == 1) { - #ok, if nodes have numbers, this sorts them numerically... roughly.. - #if node doesn't, then it sorts out alphabetically. + # ok, if nodes have numbers, this sorts them numerically... roughly.. + # if node doesn't, then it sorts out alphabetically. my @nodes = sort {($a =~ /(\d+)/ ? $1 : -1)[0] <=> ($b =~ /(\d+)/ ? $1 : -1)[0] || $a cmp $b } (keys %{$handler_hash{$_}}); $req->{node}=\@nodes; } no strict "refs"; - eval { #REMOVEEVALFORDEBUG + eval { # REMOVEEVALFORDEBUG if ($dispatch_requests) { dispatch_request($req,$callback,$modname); } else { @@ -1817,22 +1817,22 @@ sub plugin_command { close($parent_fd); xexit(0); } - $@=""; #sometimes a child 'eval' doesn't clean up $@, if we make it this far, no non-eval bug bombed out - }; #REMOVEEVALFORDEBUG - if ($sock or $shouldbealivepid != $$) { #We shouldn't still be alive, try to send as much detail to parent as possible as to why + $@=""; # sometimes a child 'eval' doesn't clean up $@, if we make it this far, no non-eval bug bombed out + }; # REMOVEEVALFORDEBUG + if ($sock or $shouldbealivepid != $$) { # We shouldn't still be alive, try to send as much detail to parent as possible as to why my $error= "$modname plugin bug, pid $$, process description: '$$progname'"; if ($@) { $error .= " with error '$@'"; - } else { #Sys::Virt and perhaps Net::SNMP sometimes crashes in a way $@ won't catch.. + } else { # Sys::Virt and perhaps Net::SNMP sometimes crashes in a way $@ won't catch.. $error .= " with missing eval error, probably due to special manipulation of $@ or strange circumstances in an XS library, remove evals in xcatd marked 'REMOVEEVALFORDEBUG and run xcatd -f for more info"; } - if (scalar (@nodes)) { #Don't know which of the nodes, so one error message warning about the possibliity.. + if (scalar (@nodes)) { # Don't know which of the nodes, so one error message warning about the possibliity.. $error .= " while trying to fulfill request for the following nodes: ".join(",",@nodes); } xCAT::MsgUtils->message("S","xcatd: $error"); $callback->({error=>[$error],errorcode=>[1]}); - xexit(0); #Die like we should have done - } elsif ($@) { #We are still alive, should be alive, but yet we have an error. This means we are in the case of 'do_request' or something similar. Forward up the death since our communication channel is intact.. + xexit(0); # Die like we should have done + } elsif ($@) { # We are still alive, should be alive, but yet we have an error. This means we are in the case of 'do_request' or something similar. Forward up the death since our communication channel is intact.. xCAT::MsgUtils->message("S", "$@"); die $@; } @@ -1870,7 +1870,7 @@ sub plugin_command { if (@deferredmsgargs) { xCAT::MsgUtils->message(@deferredmsgargs) }; @deferredmsgargs=(); my $nextxmittime = time()+1; - while (($plugin_numchildren > 0) and ($check_fds->count > 0)) { #this tracks end of useful data from children much more closely + while (($plugin_numchildren > 0) and ($check_fds->count > 0)) { # this tracks end of useful data from children much more closely relay_fds($check_fds,$xcatresponses{xcatresponse}); if (time() > $nextxmittime) { $nextxmittime = time()+1; @@ -1893,10 +1893,10 @@ sub plugin_command { $done{transid}=$req->{transid}->[0]; } if ($sock) { - my $clientpresence = new IO::Select; #The client may have gone away without confirmation, don't PIPE over this trivial thing + my $clientpresence = new IO::Select; # The client may have gone away without confirmation, don't PIPE over this trivial thing $clientpresence->add($sock); my $deadline = time()+5; - while ($deadline > time()) { #sometimes can_write exits prematurely without waiting the whole time..... + while ($deadline > time()) { # sometimes can_write exits prematurely without waiting the whole time..... if ($clientpresence->can_write(5)) { send_response(\%done,$sock); last; @@ -1915,18 +1915,18 @@ sub dispatch_callback { delete $rsp->{serverdone}; unless (%$rsp) { return; } store_fd($rsp,$dispatch_parentfd); - yield; #This has to happen before next line could possibly work anyway + yield; # This has to happen before next line could possibly work anyway my $parselect = new IO::Select; $parselect->add($dispatch_parentfd); my $selbits = $parselect->bits; - while (defined($selbits) && ($rsp = select($selbits,undef,undef,5))) { #block for up to 5 seconds before continuing + while (defined($selbits) && ($rsp = select($selbits,undef,undef,5))) { # block for up to 5 seconds before continuing if ($quit) { # termination requested by a clean shutdown facility xexit 0; } - if ($rsp == 0) { #The select call failed to find any ready items + if ($rsp == 0) { # The select call failed to find any ready items last; } - if ($rsp < 0) { #A child exited or other signal event that made select skip out before suggesting succes + if ($rsp < 0) { # A child exited or other signal event that made select skip out before suggesting succes next; } if ($rsp = <$dispatch_parentfd>) { @@ -1935,7 +1935,7 @@ sub dispatch_callback { } last; } else { - $parselect->remove($dispatch_parentfd); #Block until parent acks data + $parselect->remove($dispatch_parentfd); # Block until parent acks data last; } $selbits = $parselect->bits; @@ -1957,7 +1957,7 @@ sub relay_dispatch { eval { $response = fd_retrieve($rin); }; - if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + if ($@ and $@ =~ /^Magic number checking on storable file/) { # this most likely means we ran over the end of available input $fds->remove($rin); close($rin); } else { @@ -1965,7 +1965,7 @@ sub relay_dispatch { $dispatch_cb->($response); } } - yield; #At this point, explicitly yield to other processes. If children will have more data, this process would otherwise uselessly loop on data that never will be. If children are all done, still no harm in waiting a short bit for a timeslice to come back + yield; # At this point, explicitly yield to other processes. If children will have more data, this process would otherwise uselessly loop on data that never will be. If children are all done, still no harm in waiting a short bit for a timeslice to come back return scalar(@ready_ins); } @@ -1982,7 +1982,7 @@ sub dispatch_request { # save the old signal my $old_sig_chld = $SIG{CHLD}; - #----used for trace start--------- + # ----used for trace start--------- my $str_cmd=$req->{command}->[0]." "; if(exists($req->{noderange})){ foreach my $n (@{$req->{noderange}}) { @@ -1997,21 +1997,21 @@ sub dispatch_request { $str_cmd =~ s/(.+) $/$1/g; } xCAT::MsgUtils->trace(0,"D","xcatd: dispatch request '$str_cmd' to plugin '$modname'"); - #----used for trace end--------- + # ----used for trace end--------- - #Hierarchy support. Originally, the default scope for noderange commands was - #going to be the servicenode associated unless overriden. - #However, assume for example that you have blades and a blade is the service node - #rpower being executed by the servicenode for one of its subnodes would have to - #reach it's own management module. This has the potential to be non-trivial for some quite possible network configurations. - #Since plugins may commonly experience this, a preprocess_request implementation - #will for now be required for a command to be scaled through service nodes - #If the plugin offers a preprocess method, use it to set the request array + # Hierarchy support. Originally, the default scope for noderange commands was + # going to be the servicenode associated unless overriden. + # However, assume for example that you have blades and a blade is the service node + # rpower being executed by the servicenode for one of its subnodes would have to + # reach it's own management module. This has the potential to be non-trivial for some quite possible network configurations. + # Since plugins may commonly experience this, a preprocess_request implementation + # will for now be required for a command to be scaled through service nodes + # If the plugin offers a preprocess method, use it to set the request array if ((not (defined $req->{_xcatpreprocessed}->[0] and $req->{_xcatpreprocessed}->[0] == 1)) and (defined(${"xCAT_plugin::".$modname."::"}{preprocess_request}))) { $SIG{CHLD}='DEFAULT'; xCAT::MsgUtils->trace(0,"D","xcatd: handle request '$req->{command}->[0]' by plugin '$modname''s preprocess_request"); $reqs = ${"xCAT_plugin::".$modname."::"}{preprocess_request}->($req,$dispatch_cb,\&do_request); - } else { #otherwise, pass it in without hierarchy support + } else { # otherwise, pass it in without hierarchy support $reqs = [$req]; } @@ -2045,7 +2045,7 @@ sub dispatch_request { foreach (@{$reqs}) { my $pfd; - my $parfd; #use a private variable so it won't trounce itself recursively + my $parfd; # use a private variable so it won't trounce itself recursively my $child; delete $_->{noderange}; if (ref $_->{'_xcatdest'} and (ref $_->{'_xcatdest'}) eq 'ARRAY') { @@ -2057,7 +2057,7 @@ sub dispatch_request { # make the plugin process exit directly instead of wait(), this is useful # for the plugin process to exit successfully when it opened some shell subprocesses. $SIG{TERM} = $SIG{INT} = 'DEFAULT'; - "" =~ m/()/; #clear $1 that we may have sitting around + "" =~ m/()/; # clear $1 that we may have sitting around if ($_->{'_xcatdelay'} and not ref $_->{'_xcatdelay'}) { sleep $_->{'_xcatdelay'}; } # Call the plugin to process the command request # rescanplugins request gets handled directly here in xcatd @@ -2101,8 +2101,8 @@ sub dispatch_request { my @prexcatdests=(); my @xcatdests=(); if ($_->{'_xcatdelay'} and not ref $_->{'_xcatdelay'}) { sleep $_->{'_xcatdelay'}; } - if (ref($_->{'_xcatdest'}) eq 'ARRAY') { #If array, consider it an 'anycast' operation, broadcast done through dupe - #requests, or an alternative join '&' maybe? + if (ref($_->{'_xcatdest'}) eq 'ARRAY') { # If array, consider it an 'anycast' operation, broadcast done through dupe + # requests, or an alternative join '&' maybe? @prexcatdests=@{$_->{'_xcatdest'}}; } else { @prexcatdests=($_->{'_xcatdest'}); @@ -2120,7 +2120,7 @@ sub dispatch_request { foreach $xcatdest (@xcatdests) { my $dlock; if ($xcatdest and xCAT::NetworkUtils->thishostisnot($xcatdest)) { - #mkpath("/var/lock/xcat/"); #For now, limit intra-xCAT requests to one at a time, to mitigate DB handle usage + #mkpath("/var/lock/xcat/"); # For now, limit intra-xCAT requests to one at a time, to mitigate DB handle usage #open($dlock,">","/var/lock/xcat/dispatchto_$xcatdest"); #flock($dlock,LOCK_EX); $ENV{XCATHOST} = ($xcatdest =~ /:/ ? $xcatdest : $xcatdest.":3001" ); @@ -2128,7 +2128,7 @@ sub dispatch_request { my $errstr; eval { undef $_->{'_xcatdest'}; - #mainly used by SN to filter out the incorrect module that xcat command came into + # mainly used by SN to filter out the incorrect module that xcat command came into $_->{'_modname'} = $modname; xCAT::MsgUtils->trace(0,"D","dispatch hierarchical sub-command $_->{command}->[0] to $ENV{XCATHOST}"); @@ -2181,7 +2181,7 @@ sub dispatch_request { xexit; } while (($dispatch_children > 0) and ($child_fdset->count > 0)) { relay_dispatch($child_fdset,$dispatch_cb) } - while (relay_dispatch($child_fdset,$dispatch_cb)) { } #Potentially useless drain. + while (relay_dispatch($child_fdset,$dispatch_cb)) { } # Potentially useless drain. # restore the old signal $SIG{CHLD} = $old_sig_chld; @@ -2202,7 +2202,7 @@ sub do_request { } - #my $sock = shift; #If no sock, will return a response hash + #my $sock = shift; # If no sock, will return a response hash if ($cmd_handlers{$req->{command}->[0]}) { return plugin_command($req,$sock,$rsphandler); } elsif ($req->{command}->[0] eq "noderange" and $req->{noderange}) { @@ -2237,9 +2237,9 @@ sub do_request { sub convey_response { my $resp=shift; - #TODO: This is where the following will/may happen: - #-Track transaction id - #-Save output for deferred commands + # TODO: This is where the following will/may happen: + # -Track transaction id + # -Save output for deferred commands unless ($parent_fd) { build_response($resp); return; @@ -2247,35 +2247,35 @@ sub convey_response { unless ($resp) { return; } $pipeexpected=1; #$resp = XMLout($resp,KeyAttr=>[], NoAttr=>1,RootName=>'xcatresponse'); - #sanitize the response, to avoid being killed by non-printable bytes + # sanitize the response, to avoid being killed by non-printable bytes #$resp =~ tr/\011-\177/?/c; - #seeing if using utf-8 offloads potential issues to client terminal, it didn't + # seeing if using utf-8 offloads potential issues to client terminal, it didn't store_fd($resp,$parent_fd); - yield; #parent must get timeslice anyway before an ack could possibly return + yield; # parent must get timeslice anyway before an ack could possibly return my $parsel = new IO::Select; $parsel->add($parent_fd); my $selbits = $parsel->bits; my $rsp; - while ($selbits && ($rsp = select($selbits, undef, undef, 5))) { #block up to five seconds + while ($selbits && ($rsp = select($selbits, undef, undef, 5))) { # block up to five seconds if ($quit) { # Obey quit flag xexit 0; } - if ($rsp == 0) { #This means the filedescriptor was removed + if ($rsp == 0) { # This means the filedescriptor was removed last; } if ($rsp < 0) { # A signal caused select to skip out, do-over next; } - #At this point, the only possibility is a positive return, meaning parent_fd requires attention of some sort + # At this point, the only possibility is a positive return, meaning parent_fd requires attention of some sort $rsp = <$parent_fd>; - if ($rsp) { #If data actually came in, last, otherwise, remove it from the IO::Select, but both should amount to the same thing + if ($rsp) { # If data actually came in, last, otherwise, remove it from the IO::Select, but both should amount to the same thing last; } else { $parsel->remove($parent_fd); last; } } - yield; #If still around, it means a peer process still hasn't gotten to us, so might as well yield + yield; # If still around, it means a peer process still hasn't gotten to us, so might as well yield $selbits = $parsel->bits; } @@ -2298,9 +2298,9 @@ sub build_response { } sub becomeuser { -#if username and password match, return the new username -#otherwise, return undef -#TODO PAM? +# if username and password match, return the new username +# otherwise, return undef +# TODO PAM? my $passtab = xCAT::Table->new('passwd'); my $id=shift; my $pass=shift; @@ -2318,13 +2318,13 @@ sub becomeuser { }elsif ($pass eq $passent) { return $id; } -# if ($passent =~ /^\$(2a|1)\$.*\$/) { #MD5 or Blowfish hash, calculate before comparison -# $pass = crypt($pass,$passent); -# } #Not bothering with old DES method, for now assume plaintext if not set -# if ($pass eq $passent) { -# return $id; -# } -#If here, unable to validate given credential + #if ($passent =~ /^\$(2a|1)\$.*\$/) { # MD5 or Blowfish hash, calculate before comparison + #$pass = crypt($pass,$passent); + #} # Not bothering with old DES method, for now assume plaintext if not set + #if ($pass eq $passent) { + #return $id; + #} +# If here, unable to validate given credential return undef; } sub populate_site_hash { @@ -2367,15 +2367,15 @@ sub send_response { unless ($encode) { $encode = $globalencode; } if ($encode eq "xml") { my $xml; - if ($response->{xcatresponse}) { #it's an aggregate, keeproot + if ($response->{xcatresponse}) { # it's an aggregate, keeproot $xml = XMLout($response,KeyAttr=>[], NoAttr=>1,KeepRoot=>1); } else { $xml = XMLout($response,RootName => 'xcatresponse',NoAttr=>1); } $xml =~ tr/\011-\177/?/c; - #----used for command log start------- + # ----used for command log start------- my $tmp_xml = $xml; - #----used for command log end -------- + # ----used for command log end -------- eval { my $rsplen = length($xml); my $blocks = int($rsplen/4096)-1; @@ -2389,20 +2389,20 @@ sub send_response { } }; - #----used for command log start------- + # ----used for command log start------- my $cmdlog_xml=""; $tmp_xml =~ s/\e/xxxxESCxxxx/g; $cmdlog_xml .= $tmp_xml.""; my $cmdlog_rsp = XMLin($cmdlog_xml,SuppressEmpty=>undef,ForceArray=>1); cmdlog_collectlog($cmdlog_rsp); - #----used for command log end -------- + # ----used for command log end -------- } elsif ($encode eq "storable") { if ($response->{xcatresponse}) { $response = $response->{xcatresponse}; } nstore_fd($response,$sock); - $sock->flush(); #otherwise, the response might actually get deferred until after the close_notify, crazy huh? + $sock->flush(); # otherwise, the response might actually get deferred until after the close_notify, crazy huh? } } sub get_request { @@ -2413,7 +2413,7 @@ sub get_request { my $line = $request; while ((!$request) || ($request !~ m/<\/xcatrequest>/)) { my $flags=fcntl($sock,F_GETFL,0); - $flags |= O_NONBLOCK; #we want sysread to bail on us, select seems to be evil to us still.. + $flags |= O_NONBLOCK; # we want sysread to bail on us, select seems to be evil to us still.. fcntl($sock,F_SETFL,$flags); my $bytesread; if (!($line) ) { $line = ''; } @@ -2423,7 +2423,7 @@ sub get_request { return undef; } $flags=fcntl($sock,F_GETFL,0); - $flags &= ~O_NONBLOCK; #now we want *print* to be blocking IO + $flags &= ~O_NONBLOCK; # now we want *print* to be blocking IO fcntl($sock,F_SETFL,$flags); $request = $line; } @@ -2443,38 +2443,38 @@ sub service_connection { my $peerhostorg = shift; my $peerport = $sock->peerport; my %tables=(); - #some paranoid measures could reduce a third party abusing stage3 image to attempting to get USER/PASS for BMCs: + # some paranoid measures could reduce a third party abusing stage3 image to attempting to get USER/PASS for BMCs: # -Well, minimally, ignore requests if requesting node is not in spconfig mode (stage3) # -Option to generate a random password per 'getipmi' request. This reduces the exposure to a D.O.S. hopefully - #Give only 15 seconds of silence allowed or terminate connection. Using alarm since we are in thread-unsafe world anyway + # Give only 15 seconds of silence allowed or terminate connection. Using alarm since we are in thread-unsafe world anyway my $timedout = 0; $SIG{ALRM} = sub { $timedout = 1; die; }; my $evalpid = $$; - eval { #REMOVEEVALFORDEBUG + eval { # REMOVEEVALFORDEBUG my $request; my $req=undef; my $line; my $clientsel = new IO::Select; $clientsel->add($sock); while (1) { - unless ($clientsel->can_read(15)) { last; } #don't let an unresponsive client hold us up + unless ($clientsel->can_read(15)) { last; } # don't let an unresponsive client hold us up my $line = <$sock>; # grab one line, check for mode... - #Commenting out, could be a remote exceution path - #consider sereal one day + # Commenting out, could be a remote exceution path + # consider sereal one day #if ($line and $line =~ /^xcatencoding: (.*)/) { - # unless ($supported_encodes{$1}) { - # print $sock "Unsupported encoding $1\n"; - # last; - # } - # print $sock "Encoding accepted\n"; - # $globalencode=$1; - # $line = ""; + #unless ($supported_encodes{$1}) { + #print $sock "Unsupported encoding $1\n"; + #last; + #} + #print $sock "Encoding accepted\n"; + #$globalencode=$1; + #$line = ""; #} $req = get_request($sock,$globalencode,$line); unless ($req) { last; } - #----used for command log start---------- + # ----used for command log start---------- my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time()); $year += 1900; $mon += 1; @@ -2509,10 +2509,10 @@ sub service_connection { } } $cmdlog_alllog .= "\n[Response]\n"; - #----used for command log end---------- + # ----used for command log end---------- - { #TODO: find closing brace.. - #first change peername on 'becomeuser' tag if present and valid + { # TODO: find closing brace.. + # first change peername on 'becomeuser' tag if present and valid if (defined $req->{becomeuser}) { $peername=becomeuser($req->{becomeuser}->[0]->{username}->[0], $req->{becomeuser}->[0]->{password}->[0]); @@ -2522,7 +2522,7 @@ sub service_connection { send_response($resp,$sock); return; } - delete($req->{becomeuser}); #Remove it to keep it from view + delete($req->{becomeuser}); # Remove it to keep it from view } # If the request is to aquire a token for a specific account @@ -2560,7 +2560,7 @@ sub service_connection { delete($req->{tokenid}); } - #we have a full request.. + # we have a full request.. #printf $request."\n"; $request=""; if (xCAT::xcatd->validate($peername,$peerhost,$req,$peerhostorg,\@deferredmsgargs)) { @@ -2580,7 +2580,7 @@ sub service_connection { my $debuglog= "xcatd: open new process : $$progname"; xCAT::MsgUtils->trace(0,"D","$debuglog"); - if ($req->{command}->[0] eq "authcheck") { #provide a method for UI to verify a user without actually requesting action + if ($req->{command}->[0] eq "authcheck") { # provide a method for UI to verify a user without actually requesting action my $resp; if ($peername or $peername eq "0") { $resp->{username}=[$peername]; @@ -2593,7 +2593,7 @@ sub service_connection { } elsif ($cmd_handlers{$req->{command}->[0]}) { plugin_command($req,$sock,\&convey_response); } elsif ($req->{command}->[0] eq "noderange" and $req->{noderange}) { - xCAT::NodeRange::retain_cache(0); #if the request has a 'noderange' element, take the performance hit for the sake of freshness + xCAT::NodeRange::retain_cache(0); # if the request has a 'noderange' element, take the performance hit for the sake of freshness my @nodes = noderange($req->{noderange}->[0]); my %resp; if (nodesmissed) { @@ -2606,8 +2606,8 @@ sub service_connection { } send_response(\%resp,$sock); next; - } elsif ($req->{command}->[0] eq "extnoderange" and $req->{noderange}) { #This is intended for the UIs to build trees - #as this would be part of a highly dynamic construct, it has a shortcut here to minimize server load + } elsif ($req->{command}->[0] eq "extnoderange" and $req->{noderange}) { # This is intended for the UIs to build trees + # as this would be part of a highly dynamic construct, it has a shortcut here to minimize server load my $subgroups=0; if ($req->{arg} and grep /subgroups/,@{$req->{arg}}) { $subgroups=1; @@ -2638,7 +2638,7 @@ sub service_connection { } } } - }; #REMOVEEVALFORDEBUG + }; # REMOVEEVALFORDEBUG if ($@) { # The eval statement caught a program bug.. if ($@ =~ /^SIGPIPE/) { xCAT::MsgUtils->message("S","xcatd: Unexpected client disconnect"); @@ -2660,18 +2660,18 @@ sub service_connection { } } elsif ($evalpid ne $$) { xCAT::MsgUtils->message("S","A child jumped to where it should never ever be, this shouldn't be possible, please report this bug"); - #The folowing corrupts the SSL state preventing any further output by the parent. - #A bug triggering this absolutely - #needs to fixed. With the current code layout it is either trash valid data that could have been or - #risk user missing data - #without knowing it. It's likely possible to rearchitect to change that, but as it stands it really - #should be no longer possible to hit this condition. + # The folowing corrupts the SSL state preventing any further output by the parent. + # A bug triggering this absolutely + # needs to fixed. With the current code layout it is either trash valid data that could have been or + # risk user missing data + # without knowing it. It's likely possible to rearchitect to change that, but as it stands it really + # should be no longer possible to hit this condition. send_response({error=>"A child jumped to where it should never ever be, this shouldn't be possible, please report this bug"},$sock); } - #----used for command log start------- + # ----used for command log start------- cmdlog_submitlog(); - #----used for command log end--------- + # ----used for command log end--------- $SIG{ALRM}= sub { xCAT::MsgUtils->message("S","$$ failed shutting down"); die;}; alarm(10); @@ -2684,7 +2684,7 @@ sub service_connection { } } -sub relay_fds { #Relays file descriptors from pipes to children to the SSL socket +sub relay_fds { # Relays file descriptors from pipes to children to the SSL socket my $fds = shift; my $replyqueue=shift; my $goneclient=0; @@ -2698,13 +2698,13 @@ sub relay_fds { #Relays file descriptors from pipes to children to the SSL socke # This mostly happens when there are multiple plugins are called for certain command # So spkit the pipe error handle $pipeexpected=1; - foreach $rfh (@readyset) { #go through each child, extract a complete, atomic message + foreach $rfh (@readyset) { # go through each child, extract a complete, atomic message my $line; my $resp; eval { $resp = fd_retrieve($rfh); }; - if ($@ and $@ =~ /^Magic number checking on storable file/) { #this most likely means we ran over the end of available input + if ($@ and $@ =~ /^Magic number checking on storable file/) { # this most likely means we ran over the end of available input $fds->remove($rfh); close($rfh); } else { @@ -2735,15 +2735,15 @@ sub relay_fds { #Relays file descriptors from pipes to children to the SSL socke } xCAT::MsgUtils->message("S", "Client abort requested"); - #----used for command log start------- + # ----used for command log start------- $cmdlog_alllog .= "Client abort requested\n"; cmdlog_submitlog(); - #----used for command log end--------- + # ----used for command log end--------- exit(0); } } - yield; #Give other processes, including children, explicit control, to avoid uselessly aggressive looping + yield; # Give other processes, including children, explicit control, to avoid uselessly aggressive looping if ($goneclient) { xCAT::MsgUtils->message("S", "SIGPIPE $$progname encountered a broken pipe (Sudden client disconnect)"); die; @@ -2956,7 +2956,7 @@ sub disable_callingtrace { xCAT::MsgUtils->stop_logging(); } -#-------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------- =head3 cmdlog_collectlog Used by recording command output feature. @@ -2967,7 +2967,7 @@ sub disable_callingtrace { 0 -> successful 1 -> failed =cut -#-------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------- sub cmdlog_collectlog(){ my $rsponse= shift; my $rsp_log=""; @@ -2985,8 +2985,8 @@ sub cmdlog_collectlog(){ foreach my $tmprsp (@{$rsp}) { $rsp = $tmprsp; - #handle response - #Handle errors + # handle response + # Handle errors if ($rsp->{error}) { if (ref($rsp->{error}) eq 'ARRAY') { foreach my $text (@{$rsp->{error}}) { @@ -3045,7 +3045,7 @@ sub cmdlog_collectlog(){ } } - #Handle {node} structure + # Handle {node} structure my $errflg=0; my $nodes=($rsp->{node}); unless (ref $nodes eq 'ARRAY') { @@ -3144,7 +3144,7 @@ sub cmdlog_collectlog(){ return 0; } -#-------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------- =head3 cmdlog_submitlog Used by recording command output feature. @@ -3167,7 +3167,7 @@ sub cmdlog_collectlog(){ When connect with 'Command log writer' process by tcp, cmdlog_submitlog is only try 3 times. If all 3 times are failed, cmdlog_submitlog will drop the command output log and issue a trace information to systemd to record this drop event. =cut -#-------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------- sub cmdlog_submitlog() { my $tmpreq; my $mysocket;