From af3245ca0a3d0b0c7c7ee39287b567e6eec2189c Mon Sep 17 00:00:00 2001 From: Mark Buechler Date: Fri, 25 Sep 2009 14:11:43 +0000 Subject: [PATCH] - Only retry creating a temp group name the max possible names to prevent an infinite loop. Since we're using rand() here, it's possible we could exit the loop with no unique name. However, this is pretty unlikely considering thousands if temp group names would have to already exist. - Fail out if we can't come up with a temp group name and just use the original specified. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1143 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scstadmin/scstadmin b/scstadmin/scstadmin index 3989fe1a7..e465c2048 100755 --- a/scstadmin/scstadmin +++ b/scstadmin/scstadmin @@ -972,11 +972,17 @@ sub applyConfiguration { if ($group =~ /^$_TGT_DEF_PREFIX_/) { my $tmp_group = randomGroup(); - print "\t-> Using temporary group '$tmp_group' for group '$group'.\n"; + if (!defined($tmp_group)) { + print "\t-> WARNING: Unable to find a free temporary group for '$group', ". + "using the original group name instead.\n"; - $rename_group{$tmp_group} = $group; - $used_users{$tmp_group} = $used_users{$group}; - $group = $tmp_group; + } else { + print "\t-> Using temporary group '$tmp_group' for group '$group'.\n"; + + $rename_group{$tmp_group} = $group; + $used_users{$tmp_group} = $used_users{$group}; + $group = $tmp_group; + } } if ($check) { @@ -1955,13 +1961,17 @@ sub validHandlerTypes { sub randomGroup { my $tmp_group; + my $retry = 0; - while (!$tmp_group || $SCST->groupExists($tmp_group)) { + while (($retry < 10000) && (!$tmp_group || $SCST->groupExists($tmp_group))) { my $id = int(rand(10000)); $tmp_group = $_TGT_TMP_PREFIX_.$id; + + $retry++; } + return undef if ($SCST->groupExists($tmp_group)); return $tmp_group; }