- 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
This commit is contained in:
Mark Buechler
2009-09-25 14:11:43 +00:00
parent 35a00370ae
commit af3245ca0a

View File

@@ -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;
}