NDBM_File file locking support? 
Author Message
 NDBM_File file locking support?

Please pardon this post if its question has been answered countless
times, if the answer is plainly obvious, or if the question is somehow
inappropriate to this branch of clp.  I've scanned any number of FAQs,
the camel and llama books and a sysadmin, so far to no avail.

I'm attempting to create a program which maintains a (relatively) large
set of data, to be accessed for read/write by a group of users.  Our
local installation of perl is 5.002 (outdated, I know), and DB modules
available to us are Any_DBM and NDBM_File.  This on a cluster of Alpha
stations running Digital UNIX V4.0D (rev. 878).

In the interests of keeping the data from being corrupt, I'm trying to
implement file locking on the data file.  Not having done this before,
I began consulting the available documentation.  Being a relative
stranger to C programming and UNIX programming, the Fcntl module and
file ideas were a bit foreign at first.

Programming Perl (2nd Edition) has very scant documentation for the
NDBM_File module, and refers the reader to DB_File, being a 'closely
related module'.  DB_File includes an entire page sample program for
performing file locking, which hinges on the fd function to grab
something which Perl can open and thus flock.

Well, replacing the lines from that program (p. 393) from

use DB_File;
$db_obj = tie(%db_hash, 'DB_File', '/tmp/foo.db', O_CREAT|O_RDWR, 0644)
                 or die "dbcreat /tmp/fee.db $!";

with

use NDBM_File;
$db_obj = tie(%db_hash, 'NDBM_File', '/tmp/foo.db', O_CREAT|O_RDWR,
0644)
                 or die "dbcreat /tmp/fee.db $!";

and subsequently running the program results in an error telling me the
function fd() does not exist.

I see that the Fcntl module has some flags for file locking, but the
documentation I've found is again unclear on setting those flags
(outside of calling them when the hash is initially tied to the database
file).

I would be installing the DB_File module from CPAN, but of course every
version there requires at least Perl 5.003 or greater.

My question(s), then, is this (are these):  is there a Good, Wholesome
way to extract a file descriptor number (other than fileno) from an
NDBM_File style hash?  Failing that, is there similarly a clean way to
do this with Fcntl?  Am I misguided on the abilities/design of these
modules?  Or, failing all these, should I just bother a sysadmin to
update Perl and install a local copy of DB_File?

Many thanks for any insights, and again, pardon these questions if
they're best directed elsewhere.

--john soares



Sat, 30 Sep 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How to lock a NDBM_File with a semaphore file

2. locking an NDBM_File with a semaphore file

3. PERLFUNC: flock - lock an entire file with an advisory lock

4. PERLFUNC: flock - lock an entire file with an advisory lock

5. File Locking and File Deletion

6. File altering in-place w/ file locking

7. File Locking with tied [GNS]?DBM files...

8. DBCS Support and corporate support for PERL

9. DBCS Support and corporate support for PERL

10. ".lock"-style locking module?

11. Emacs cperl-mode.el vs font-lock/lazy-lock

12. PERLFUNC: lock - get a thread lock on a variable, subroutine, or method

 

 
Powered by phpBB® Forum Software