1 # G-RIN database handling.
2 # Copyright (C) 1999 Ian Jackson <ijackson@chiark.greenend.org.uk
4 # This is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 2,
7 # or (at your option) any later version.
9 # This is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public
15 # License along with this file; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 @db_fields= qw(network prefix name contact email hiddenemail created changed);
20 sub read_database () {
21 print DEBUG "reading\n";
23 open DBF, "list" or die $!;
26 length or die "$_ $!";
33 foreach $f (@db_fields) { $v->{$f}= shift(@v).''; }
40 $db_lock_env= 'BCP5REGISTRY_LOCKED';
42 sub write_database () {
44 print DEBUG "writing\n";
45 die unless $ENV{$db_lock_env};
46 open DBF, ">list.new" or die $!;
47 while (($k,$v) = each %db) {
49 foreach $f (@db_fields) { $str.= "\1".$v->{$f}; }
50 print DBF $str,"\n" or die $!;
52 print DBF "\2\n" or die $!;
54 rename "list.new","list" or die $!;
57 sub lock_database () {
58 print DEBUG "locking\n";
60 return if $ENV{$db_lock_env};
61 $ENV{$db_lock_env}= '1';
62 exec 'with-lock-ex','-w','lockfile',"$0",@org_argv;
63 die "$ENV{'PATH'}: $!";