ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.65 by root, Tue Sep 12 22:18:55 2006 UTC vs.
Revision 1.68 by root, Tue Sep 12 23:45:16 2006 UTC

860 860
861=cut 861=cut
862 862
863{ 863{
864 my $db; 864 my $db;
865 my $path = cf::datadir . "/database.pst"; 865 my $path = cf::localdir . "/database.pst";
866 866
867 sub db_load() { 867 sub db_load() {
868 warn "loading database $path\n";#d# remove later 868 warn "loading database $path\n";#d# remove later
869 $db = stat $path ? Storable::retrieve $path : { }; 869 $db = stat $path ? Storable::retrieve $path : { };
870 } 870 }
872 my $pid; 872 my $pid;
873 873
874 sub db_save() { 874 sub db_save() {
875 warn "saving database $path\n";#d# remove later 875 warn "saving database $path\n";#d# remove later
876 waitpid $pid, 0 if $pid; 876 waitpid $pid, 0 if $pid;
877 unless ($pid = fork) { 877 if (0 == ($pid = fork)) {
878 $db->{_meta}{version} = 1; 878 $db->{_meta}{version} = 1;
879 Storable::nstore $db, "$path~"; 879 Storable::nstore $db, "$path~";
880 rename "$path~", $path; 880 rename "$path~", $path;
881 cf::_exit 0 if defined $pid; 881 cf::_exit 0 if defined $pid;
882 } 882 }
910 } else { 910 } else {
911 $db->{$_[0]} = $_[1]; 911 $db->{$_[0]} = $_[1];
912 } 912 }
913 db_dirty; 913 db_dirty;
914 } 914 }
915
916 attach_global
917 prio => 10000,
918 on_cleanup => sub {
919 db_sync;
920 },
921 ;
915} 922}
916 923
917############################################################################# 924#############################################################################
918# the server's main() 925# the server's main()
919 926

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines