diff --git a/perl-xCAT-2.0/xCAT/NotifHandler.pm b/perl-xCAT-2.0/xCAT/NotifHandler.pm index 445e7f0d4..86148565a 100644 --- a/perl-xCAT-2.0/xCAT/NotifHandler.pm +++ b/perl-xCAT-2.0/xCAT/NotifHandler.pm @@ -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, "|$_")) { diff --git a/perl-xCAT-2.0/xCAT/Table.pm b/perl-xCAT-2.0/xCAT/Table.pm index 8a47c4535..83d262cb3 100644 --- a/perl-xCAT-2.0/xCAT/Table.pm +++ b/perl-xCAT-2.0/xCAT/Table.pm @@ -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 } diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index 2fd2eb214..fe2a1654a 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -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 diff --git a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm index f2618aebe..daf7376a4 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/monitorctrl.pm @@ -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; } diff --git a/xCAT-server-2.0/lib/xcat/plugins/tabutils.pm b/xCAT-server-2.0/lib/xcat/plugins/tabutils.pm index 9a53fe9b1..cea531c26 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/tabutils.pm @@ -467,7 +467,9 @@ sub tabgrep { if ($tab->getNodeAttribs($node->[0],["node"])) { $callback->({data=>[$_]}); } + $tab->close; } + }