E
Eric
We inherited the block of code below, which is used to register a
specific mount point with a threadsafe hash. The input for this code
is sent from a calling function. Note that this sub is supposed to
output to file $mountsDBFile. The file is created, but is not
readable; it is nothing but cryptic characters. None of us are that
experienced (yet) with hash ties. So I have the following questions:
Based on the code below, is is apparent why the output file is not
readable?
Is the code below even supposed to output into a humanly readable
file?
Since the output file needs to be humanly readable, should we abandon
what we've inherited and start from scratch, and if so, should we
abandon the tie hash approach in favor of something else?
I realize I have a lot to learn about ties, and am in the progress of
doing so.
Thanks in advance to all that respond.
Eric
=======================================
sub RequestMountPoint {
my $self = shift;
my $protocol = shift;
my $bldNum = shift;
my $mntPnt = undef;
my $mountsDBFile = $self->Env->HomeDir()."/mountsDB";
my $mntsDB = {};
unless (open SEMAPHORE, "> /tmp/mounts.lock") {
$self->Env->ReleaseMachines();
die "unexpected problem allocating semaphore";
}
flock SEMAPHORE, Fcntl::LOCK_EX;
tie( %$mntsDB, "MLDBM", $mountsDBFile, O_CREAT|O_RDWR, 0666,
$DB_File:B_BTREE );
my $mountPoint = $self->Config->MountPointCount();
for (my $label = 0; $label < $mountPoint; $label++){
$mntPnt = "xmnt".$label;
unless (defined($mntsDB->{$mntPnt})){
$mntsDB->{$mntPnt} = {
BldNum => $bldNum,
Protocol => $protocol,
RefCnt => 1,
};
last;
}
if (($mntsDB->{$mntPnt}->{BldNum} == $bldNum) and
($mntsDB->{$mntPnt}->{Protocol} eq $protocol)) {
$mntsDB->{$mntPnt}->{RefCnt}++;
last;
}
$mntPnt = undef;
}
my $ref = $mntsDB->{$mntPnt}->{RefCnt};
untie(%$mntsDB);
close(SEMAPHORE);
return $mntPnt, $ref;
}
specific mount point with a threadsafe hash. The input for this code
is sent from a calling function. Note that this sub is supposed to
output to file $mountsDBFile. The file is created, but is not
readable; it is nothing but cryptic characters. None of us are that
experienced (yet) with hash ties. So I have the following questions:
Based on the code below, is is apparent why the output file is not
readable?
Is the code below even supposed to output into a humanly readable
file?
Since the output file needs to be humanly readable, should we abandon
what we've inherited and start from scratch, and if so, should we
abandon the tie hash approach in favor of something else?
I realize I have a lot to learn about ties, and am in the progress of
doing so.
Thanks in advance to all that respond.
Eric
=======================================
sub RequestMountPoint {
my $self = shift;
my $protocol = shift;
my $bldNum = shift;
my $mntPnt = undef;
my $mountsDBFile = $self->Env->HomeDir()."/mountsDB";
my $mntsDB = {};
unless (open SEMAPHORE, "> /tmp/mounts.lock") {
$self->Env->ReleaseMachines();
die "unexpected problem allocating semaphore";
}
flock SEMAPHORE, Fcntl::LOCK_EX;
tie( %$mntsDB, "MLDBM", $mountsDBFile, O_CREAT|O_RDWR, 0666,
$DB_File:B_BTREE );
my $mountPoint = $self->Config->MountPointCount();
for (my $label = 0; $label < $mountPoint; $label++){
$mntPnt = "xmnt".$label;
unless (defined($mntsDB->{$mntPnt})){
$mntsDB->{$mntPnt} = {
BldNum => $bldNum,
Protocol => $protocol,
RefCnt => 1,
};
last;
}
if (($mntsDB->{$mntPnt}->{BldNum} == $bldNum) and
($mntsDB->{$mntPnt}->{Protocol} eq $protocol)) {
$mntsDB->{$mntPnt}->{RefCnt}++;
last;
}
$mntPnt = undef;
}
my $ref = $mntsDB->{$mntPnt}->{RefCnt};
untie(%$mntsDB);
close(SEMAPHORE);
return $mntPnt, $ref;
}