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.254 by root, Thu Apr 19 11:12:45 2007 UTC vs.
Revision 1.263 by root, Sat May 5 05:40:27 2007 UTC

161 my $msg = join "", @_; 161 my $msg = join "", @_;
162 162
163 $msg .= "\n" 163 $msg .= "\n"
164 unless $msg =~ /\n$/; 164 unless $msg =~ /\n$/;
165 165
166 $msg =~ s/([\x00-\x09\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 166 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
167 167
168 utf8::encode $msg; 168 utf8::encode $msg;
169 LOG llevError, $msg; 169 LOG llevError, $msg;
170 }; 170 };
171} 171}
371sub write_runtime { 371sub write_runtime {
372 my $guard = cf::lock_acquire "write_runtime"; 372 my $guard = cf::lock_acquire "write_runtime";
373 373
374 my $runtime = "$LOCALDIR/runtime"; 374 my $runtime = "$LOCALDIR/runtime";
375 375
376 warn "starting to write runtime...\n";#d#
376 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 377 my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644
377 or return; 378 or return;
378 379
379 my $value = $cf::RUNTIME + 90 + 10; 380 my $value = $cf::RUNTIME + 90 + 10;
380 # 10 is the runtime save interval, for a monotonic clock 381 # 10 is the runtime save interval, for a monotonic clock
390 close $fh 391 close $fh
391 or return; 392 or return;
392 393
393 aio_rename "$runtime~", $runtime 394 aio_rename "$runtime~", $runtime
394 and return; 395 and return;
396
397 warn "... done writing runtime.\n";#d#
395 398
396 1 399 1
397} 400}
398 401
399=item cf::datalog type => key => value, ... 402=item cf::datalog type => key => value, ...
1490 my ($self) = @_; 1493 my ($self) = @_;
1491 1494
1492 local $self->{deny_reset} = 1; # loading can take a long time 1495 local $self->{deny_reset} = 1; # loading can take a long time
1493 1496
1494 my $path = $self->{path}; 1497 my $path = $self->{path};
1498
1499 {
1495 my $guard = cf::lock_acquire "map_load:$path"; 1500 my $guard = cf::lock_acquire "map_load:$path";
1496 1501
1497 return if $self->in_memory != cf::MAP_SWAPPED; 1502 return if $self->in_memory != cf::MAP_SWAPPED;
1498 1503
1499 $self->in_memory (cf::MAP_LOADING); 1504 $self->in_memory (cf::MAP_LOADING);
1500 1505
1501 $self->alloc; 1506 $self->alloc;
1502 1507
1503 $self->pre_load; 1508 $self->pre_load;
1504 Coro::cede;
1505
1506 $self->_load_objects ($self->{load_path}, 1)
1507 or return;
1508
1509 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1)
1510 if delete $self->{load_original};
1511
1512 if (my $uniq = $self->uniq_path) {
1513 utf8::encode $uniq;
1514 if (aio_open $uniq, O_RDONLY, 0) {
1515 $self->clear_unique_items;
1516 $self->_load_objects ($uniq, 0);
1517 }
1518 }
1519
1520 Coro::cede;
1521 # now do the right thing for maps
1522 $self->link_multipart_objects;
1523 Coro::cede;
1524
1525 unless ($self->{deny_activate}) {
1526 $self->decay_objects;
1527 $self->fix_auto_apply;
1528 $self->update_buttons;
1529 Coro::cede; 1509 Coro::cede;
1530 $self->set_darkness_map; 1510
1511 $self->_load_objects ($self->{load_path}, 1)
1512 or return;
1513
1514 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1)
1515 if delete $self->{load_original};
1516
1517 if (my $uniq = $self->uniq_path) {
1518 utf8::encode $uniq;
1519 if (aio_open $uniq, O_RDONLY, 0) {
1520 $self->clear_unique_items;
1521 $self->_load_objects ($uniq, 0);
1522 }
1523 }
1524
1525 Coro::cede;
1526 # now do the right thing for maps
1527 $self->link_multipart_objects;
1531 $self->difficulty ($self->estimate_difficulty) 1528 $self->difficulty ($self->estimate_difficulty)
1532 unless $self->difficulty; 1529 unless $self->difficulty;
1533 Coro::cede; 1530 Coro::cede;
1531
1532 unless ($self->{deny_activate}) {
1533 $self->decay_objects;
1534 $self->fix_auto_apply;
1535 $self->update_buttons;
1536 Coro::cede;
1537 $self->set_darkness_map;
1538 Coro::cede;
1534 $self->activate; 1539 $self->activate;
1535 Coro::cede; 1540 }
1541
1542 $self->in_memory (cf::MAP_IN_MEMORY);
1536 } 1543 }
1537 1544
1538 $self->post_load; 1545 $self->post_load;
1539 Coro::cede;
1540
1541 $self->in_memory (cf::MAP_IN_MEMORY);
1542} 1546}
1543 1547
1544sub customise_for { 1548sub customise_for {
1545 my ($self, $ob) = @_; 1549 my ($self, $ob) = @_;
1546 1550
2434 2438
2435 die $$res unless "ARRAY" eq ref $res; 2439 die $$res unless "ARRAY" eq ref $res;
2436 2440
2437 return wantarray ? @$res : $res->[-1]; 2441 return wantarray ? @$res : $res->[-1];
2438 } else { 2442 } else {
2443 reset_signals;
2439 local $SIG{__WARN__}; 2444 local $SIG{__WARN__};
2445 local $SIG{__DIE__};
2440 eval { 2446 eval {
2441 local $SIG{__DIE__};
2442 close $fh1; 2447 close $fh1;
2443 2448
2444 my @res = eval { $cb->(@args) }; 2449 my @res = eval { $cb->(@args) };
2445 syswrite $fh2, Coro::Storable::freeze +($@ ? \"$@" : \@res); 2450 syswrite $fh2, Coro::Storable::freeze +($@ ? \"$@" : \@res);
2446 }; 2451 };
2922 prio => 6, 2927 prio => 6,
2923 cb => \&IO::AIO::poll_cb, 2928 cb => \&IO::AIO::poll_cb,
2924 ); 2929 );
2925} 2930}
2926 2931
2932my $_log_backtrace;
2933
2934sub _log_backtrace {
2935 my ($msg, @addr) = @_;
2936
2937 $msg =~ s/\n//;
2938
2939 # limit the # of concurrent backtraces
2940 if ($_log_backtrace < 2) {
2941 ++$_log_backtrace;
2942 async {
2943 my @bt = fork_call {
2944 @addr = map { sprintf "%x", $_ } @addr;
2945 my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X;
2946 open my $fh, "exec addr2line -C -f -i -e \Q$self\E @addr 2>&1 |"
2947 or die "addr2line: $!";
2948
2949 my @funcs;
2950 my @res = <$fh>;
2951 chomp for @res;
2952 while (@res) {
2953 my ($func, $line) = splice @res, 0, 2, ();
2954 push @funcs, "[$func] $line";
2955 }
2956
2957 @funcs
2958 };
2959
2960 LOG llevInfo, "[ABT] $msg\n";
2961 LOG llevInfo, "[ABT] $_\n" for @bt;
2962 --$_log_backtrace;
2963 };
2964 } else {
2965 LOG llevInfo, "[ABT] $msg\n";
2966 LOG llevInfo, "[ABT] [suppressed]\n";
2967 }
2968}
2969
2927# load additional modules 2970# load additional modules
2928use cf::pod; 2971use cf::pod;
2929 2972
2930END { cf::emergency_save } 2973END { cf::emergency_save }
2931 2974

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines