From b8b4e74f04d42457dbc51b33073a16300d455c39 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Mon, 21 Jan 2008 19:49:59 +0000 Subject: [PATCH] Fix most instances of fork by replacing with xfork, name xfork correctly git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@306 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/DSHCore.pm | 2 +- perl-xCAT-2.0/xCAT/MacMap.pm | 3 ++- perl-xCAT-2.0/xCAT/PPC.pm | 3 ++- perl-xCAT-2.0/xCAT/Utils.pm | 4 ++-- xCAT-server-2.0/lib/xcat/plugins/blade.pm | 3 ++- xCAT-server-2.0/lib/xcat/plugins/ipmi.pm | 3 ++- xCAT-server-2.0/sbin/xcatd | 14 +++++++------- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/DSHCore.pm b/perl-xCAT-2.0/xCAT/DSHCore.pm index bbd47e6ee..ff8bb594d 100644 --- a/perl-xCAT-2.0/xCAT/DSHCore.pm +++ b/perl-xCAT-2.0/xCAT/DSHCore.pm @@ -47,7 +47,7 @@ sub fork_no_output my $pid; - if ($pid = fork) + if ($pid = xCAT::Utils->xfork) { } diff --git a/perl-xCAT-2.0/xCAT/MacMap.pm b/perl-xCAT-2.0/xCAT/MacMap.pm index f5eab1449..3ef3aa00b 100755 --- a/perl-xCAT-2.0/xCAT/MacMap.pm +++ b/perl-xCAT-2.0/xCAT/MacMap.pm @@ -2,6 +2,7 @@ # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html package xCAT::MacMap; use xCAT::Table; +use xCAT::Utils; use IO::Select; use IO::Handle; use Sys::Syslog; @@ -140,7 +141,7 @@ sub refresh_table { $child->autoflush(1); $parent->autoflush(1); $children++; - $cpid = fork; + $cpid = xCAT::Utils->xfork; unless (defined $cpid) { die "Cannot fork" }; if ($cpid == 0) { close($child); diff --git a/perl-xCAT-2.0/xCAT/PPC.pm b/perl-xCAT-2.0/xCAT/PPC.pm index 9609a4fe9..604682b2c 100644 --- a/perl-xCAT-2.0/xCAT/PPC.pm +++ b/perl-xCAT-2.0/xCAT/PPC.pm @@ -3,6 +3,7 @@ package xCAT::PPC; use strict; use xCAT::Table; +use xCAT::Utils; use POSIX "WNOHANG"; use Storable qw(freeze thaw); use Time::HiRes qw(gettimeofday); @@ -464,7 +465,7 @@ sub fork_cmd { my $parent; my $child; pipe $parent, $child; - my $pid = fork; + my $pid = xCAT::Utils->xfork; if ( !defined($pid) ) { ################################### diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index fe2a1654a..597d66a92 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -97,14 +97,14 @@ sub isAIX #------------------------------------------------------------------------------- -=head3 tfork +=head3 xfork forks, safely coping with open database handles Argumens: none Returns: same as fork =cut -sub tfork { +sub xfork { my $rc=fork; unless (defined($rc)) { return $rc; diff --git a/xCAT-server-2.0/lib/xcat/plugins/blade.pm b/xCAT-server-2.0/lib/xcat/plugins/blade.pm index 1907827ad..6ee94ac8e 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/blade.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/blade.pm @@ -3,6 +3,7 @@ package xCAT_plugin::blade; #use Net::SNMP qw(:snmp INTEGER); use xCAT::Table; +use xCAT::Utils; use IO::Socket; use SNMP; use strict; @@ -948,7 +949,7 @@ sub process_request { pipe $cfd, $pfd; $cfd->autoflush(1); $pfd->autoflush(1); - my $cpid = fork; + my $cpid = xCAT::Utils->fork; unless (defined($cpid)) { die "Fork error"; } unless ($cpid) { close($cfd); diff --git a/xCAT-server-2.0/lib/xcat/plugins/ipmi.pm b/xCAT-server-2.0/lib/xcat/plugins/ipmi.pm index 1fcbad962..fabec9f9f 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/ipmi.pm @@ -7,6 +7,7 @@ $xcat_plugins{ipmi}="this"; package xCAT_plugin::ipmi; use Storable qw(store_fd retrieve_fd thaw freeze); +use xCAT::Utils; require Exporter; @ISA = qw(Exporter); @@ -558,7 +559,7 @@ sub ipmicmd { mkfifo("/tmp/.sol.$pid",0666); - my $child = fork(); + my $child = xCAT::Utils->xfork(); if(!defined $child) { die; } diff --git a/xCAT-server-2.0/sbin/xcatd b/xCAT-server-2.0/sbin/xcatd index ff111ebd8..7177938f4 100755 --- a/xCAT-server-2.0/sbin/xcatd +++ b/xCAT-server-2.0/sbin/xcatd @@ -71,7 +71,7 @@ sub daemonize { chdir('/'); umask 0; my $pid; - defined($pid = fork) or die "Can't fork: $!"; + defined($pid = xCAT::Utils->xfork) or die "Can't fork: $!"; if ($pid) { if ($pidfile) { open(PFILE, '>', $pidfile); @@ -152,7 +152,7 @@ if (xCAT::Utils->isLinux()) { arg => [ 'next' ], ); close($conn); - my $pid=fork(); + my $pid=xCAT::Utils->xfork(); unless ($pid) { #fork off the nodeset and potential slowness plugin_command(\%request,undef,\&convey_response); exit(0); @@ -185,7 +185,7 @@ if (xCAT::Utils->isLinux()) { node => [ $node ], arg => [ 'enact' ], ); - my $pid=fork(); + my $pid=xCAT::Utils->xfork(); unless ($pid) { #fork off the nodeset and potential slowness plugin_command(\%request,undef,\&convey_response); exit(0); @@ -322,14 +322,14 @@ daemonize; $SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) {} }; $SIG{TERM} = $SIG{INT} = sub { printf("Asked to quit...\n"); $quit++ }; -my $pid = fork; +my $pid = xCAT::Utils->xfork; defined $pid or die "Unable to fork for UDP/TCP"; unless ($pid) { $$progname="xcatd: UDP listener"; do_udp_service; exit(0); } -$pid = fork; +$pid = xCAT::Utils->xfork; defined $pid or die "Unable to fork installmonitor"; unless ($pid) { $$progname="xcatd: install monitor"; @@ -365,7 +365,7 @@ xCAT_monitoring::monitorctrl::start($$); my $peername; until ($quit) { next unless my $connection=$listener->accept; - my $child = fork(); #Yes we fork, IO::Socket::SSL is not threadsafe.. + my $child = xCAT::Utils->xfork(); #Yes we fork, IO::Socket::SSL is not threadsafe.. unless (defined $child) { die "xCATd cannot fork"; @@ -521,7 +521,7 @@ sub plugin_command { #pipe($pfd,$cfd); $parent_fd->autoflush(1); $pfd->autoflush(1); - $child = fork; + $child = xCAT::Utils->xfork; } else { $child = 0; }