Correct some unclosed table issues, implement a fork wrapper to clean DB handles, move NotifHandler and monitorctrl to use the aforementioned wrapper

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@304 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-01-21 19:39:09 +00:00
parent 1d2b000ef0
commit 4ff63ac90b
5 changed files with 41 additions and 5 deletions

View File

@ -8,6 +8,8 @@ BEGIN
use lib "$::XCATROOT/lib/perl";
use File::Basename qw(fileparse);
use xCAT::Utils;
use Data::Dumper;
#%notif is a cache that holds the info from the "notification" table.
#the format of it is:
@ -156,7 +158,7 @@ sub refreshNotification
} #end foreach
} #end foreach(@row_array)
}end if (@row_array)
}#end if (@row_array)
} #end if ($table)
return 1;
@ -297,7 +299,7 @@ sub notify {
# print "modname=$modname, path=$path, suffix=$suffix\n";
if ($suffix =~ /.pm/) { #it is a perl module
my $pid;
if ($pid=fork()) { }
if ($pid=xCAT::Utils->xfork()) { }
elsif (defined($pid)) {
my $fname;
if (($path eq "") || ($path eq ".\/")) {
@ -318,7 +320,7 @@ sub notify {
}
else { #it is a command
my $pid;
if ($pid=fork()) { }
if ($pid=xCAT::Utils->xfork()) { }
elsif (defined($pid)) {
# print "command=$_\n";
if (open(CMD, "|$_")) {

View File

@ -1628,7 +1628,8 @@ sub open
sub DESTROY
{
my $self = shift;
if ($self->{dbh}) { $self->{dbh}->disconnect(); undef $self->{dbh};}
undef $self->{dbh};
#if ($self->{dbh}) { $self->{dbh}->disconnect(); undef $self->{dbh};}
undef $self->{nodelist}; #Could be circular
}

View File

@ -5,6 +5,7 @@ use xCAT::Table;
use xCAT::Schema;
use Data::Dumper;
use xCAT::NodeRange;
use DBI;
#--------------------------------------------------------------------------------
@ -94,6 +95,35 @@ sub isAIX
else { return 0; }
}
#-------------------------------------------------------------------------------
=head3 tfork
forks, safely coping with open database handles
Argumens:
none
Returns:
same as fork
=cut
sub tfork {
my $rc=fork;
unless (defined($rc)) {
return $rc;
}
unless ($rc) {
my %drivers = DBI->installed_drivers;
foreach my $drh (values %drivers) {
foreach (@{$drh->{ChildHandles}}) {
$_->{InactiveDestroy} = 1;
}
foreach (@{$drh->{ChildHandles}}) {
undef $_;
}
}
}
return $rc;
}
#-------------------------------------------------------------------------------
=head3 isLinux

View File

@ -75,7 +75,7 @@ sub start {
#start monitoring for all the registered plug-ins in the monitoring table.
#better span a process so that it will not block the xcatd.
my $pid;
if ($pid=fork()) {#parent process
if ($pid=xCAT::Utils->xfork()) {#parent process
#print "parent done\n";
return 0;
}
@ -647,6 +647,7 @@ sub processNodeStatusChanges {
xCAT::MsgUtils->message("E", "Could not read the nodelist table\n");
}
$tab->close;
return 0;
}

View File

@ -467,7 +467,9 @@ sub tabgrep {
if ($tab->getNodeAttribs($node->[0],["node"])) {
$callback->({data=>[$_]});
}
$tab->close;
}
}