… | |
… | |
63 | |
63 | |
64 | # configure various modules to our taste |
64 | # configure various modules to our taste |
65 | # |
65 | # |
66 | $Storable::canonical = 1; # reduce rsync transfers |
66 | $Storable::canonical = 1; # reduce rsync transfers |
67 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
67 | Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator |
|
|
68 | |
|
|
69 | $Coro::main->prio (Coro::PRIO_MAX); # run main coroutine ("the server") with very high priority |
|
|
70 | |
|
|
71 | # make sure c-lzf reinitialises itself |
|
|
72 | Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; |
68 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
73 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
69 | |
|
|
70 | $Coro::main->prio (Coro::PRIO_MAX); # run main coroutine ("the server") with very high priority |
|
|
71 | |
74 | |
72 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
75 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
73 | |
76 | |
74 | our %COMMAND = (); |
77 | our %COMMAND = (); |
75 | our %COMMAND_TIME = (); |
78 | our %COMMAND_TIME = (); |
… | |
… | |
81 | our %EXT_MAP = (); # pluggable maps |
84 | our %EXT_MAP = (); # pluggable maps |
82 | |
85 | |
83 | our $RELOAD; # number of reloads so far |
86 | our $RELOAD; # number of reloads so far |
84 | our @EVENT; |
87 | our @EVENT; |
85 | |
88 | |
86 | our $CONFDIR = confdir; |
89 | our $CONFDIR = confdir; |
87 | our $DATADIR = datadir; |
90 | our $DATADIR = datadir; |
88 | our $LIBDIR = "$DATADIR/ext"; |
91 | our $LIBDIR = "$DATADIR/ext"; |
89 | our $PODDIR = "$DATADIR/pod"; |
92 | our $PODDIR = "$DATADIR/pod"; |
90 | our $MAPDIR = "$DATADIR/" . mapdir; |
93 | our $MAPDIR = "$DATADIR/" . mapdir; |
91 | our $LOCALDIR = localdir; |
94 | our $LOCALDIR = localdir; |
92 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
95 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
93 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
96 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
94 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
97 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
95 | our $RANDOMDIR = "$LOCALDIR/random"; |
98 | our $RANDOMDIR = "$LOCALDIR/random"; |
96 | our $BDBDIR = "$LOCALDIR/db"; |
99 | our $BDBDIR = "$LOCALDIR/db"; |
|
|
100 | our $PIDFILE = "$LOCALDIR/pid"; |
|
|
101 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
|
|
102 | |
97 | our %RESOURCE; |
103 | our %RESOURCE; |
98 | |
104 | |
99 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
105 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
100 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
106 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
101 | our $NEXT_TICK; |
107 | our $NEXT_TICK; |
… | |
… | |
126 | |
132 | |
127 | binmode STDOUT; |
133 | binmode STDOUT; |
128 | binmode STDERR; |
134 | binmode STDERR; |
129 | |
135 | |
130 | # read virtual server time, if available |
136 | # read virtual server time, if available |
131 | unless ($RUNTIME || !-e "$LOCALDIR/runtime") { |
137 | unless ($RUNTIME || !-e $RUNTIMEFILE) { |
132 | open my $fh, "<", "$LOCALDIR/runtime" |
138 | open my $fh, "<", $RUNTIMEFILE |
133 | or die "unable to read runtime file: $!"; |
139 | or die "unable to read $RUNTIMEFILE file: $!"; |
134 | $RUNTIME = <$fh> + 0.; |
140 | $RUNTIME = <$fh> + 0.; |
135 | } |
141 | } |
136 | |
142 | |
137 | mkdir $_ |
143 | mkdir $_ |
138 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
144 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
… | |
… | |
727 | |
733 | |
728 | ############################################################################# |
734 | ############################################################################# |
729 | |
735 | |
730 | =head2 ATTACHABLE OBJECTS |
736 | =head2 ATTACHABLE OBJECTS |
731 | |
737 | |
732 | Many objects in crossfire are so-called attachable objects. That means you can |
738 | Many objects in deliantra are so-called attachable objects. That means you can |
733 | attach callbacks/event handlers (a collection of which is called an "attachment") |
739 | attach callbacks/event handlers (a collection of which is called an "attachment") |
734 | to it. All such attachable objects support the following methods. |
740 | to it. All such attachable objects support the following methods. |
735 | |
741 | |
736 | In the following description, CLASS can be any of C<global>, C<object> |
742 | In the following description, CLASS can be any of C<global>, C<object> |
737 | C<player>, C<client> or C<map> (i.e. the attachable objects in |
743 | C<player>, C<client> or C<map> (i.e. the attachable objects in |
… | |
… | |
787 | =item cf::CLASS::attachment $name, ... |
793 | =item cf::CLASS::attachment $name, ... |
788 | |
794 | |
789 | Register an attachment by C<$name> through which attachable objects of the |
795 | Register an attachment by C<$name> through which attachable objects of the |
790 | given CLASS can refer to this attachment. |
796 | given CLASS can refer to this attachment. |
791 | |
797 | |
792 | Some classes such as crossfire maps and objects can specify attachments |
798 | Some classes such as deliantra maps and objects can specify attachments |
793 | that are attached at load/instantiate time, thus the need for a name. |
799 | that are attached at load/instantiate time, thus the need for a name. |
794 | |
800 | |
795 | These calls expect any number of the following handler/hook descriptions: |
801 | These calls expect any number of the following handler/hook descriptions: |
796 | |
802 | |
797 | =over 4 |
803 | =over 4 |
… | |
… | |
1385 | |
1391 | |
1386 | =back |
1392 | =back |
1387 | |
1393 | |
1388 | =head2 CORE EXTENSIONS |
1394 | =head2 CORE EXTENSIONS |
1389 | |
1395 | |
1390 | Functions and methods that extend core crossfire objects. |
1396 | Functions and methods that extend core deliantra objects. |
1391 | |
1397 | |
1392 | =cut |
1398 | =cut |
1393 | |
1399 | |
1394 | package cf::player; |
1400 | package cf::player; |
1395 | |
1401 | |
… | |
… | |
1523 | my ($pl) = @_; |
1529 | my ($pl) = @_; |
1524 | |
1530 | |
1525 | my $name = $pl->ob->name; |
1531 | my $name = $pl->ob->name; |
1526 | |
1532 | |
1527 | $pl->{deny_save} = 1; |
1533 | $pl->{deny_save} = 1; |
1528 | $pl->password ("*"); # this should lock out the player until we nuked the dir |
1534 | $pl->password ("*"); # this should lock out the player until we have nuked the dir |
1529 | |
1535 | |
1530 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1536 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1531 | $pl->deactivate; |
1537 | $pl->deactivate; |
1532 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
1538 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
1533 | $pl->ob->check_score; |
1539 | $pl->ob->check_score; |
… | |
… | |
1619 | } |
1625 | } |
1620 | |
1626 | |
1621 | \@paths |
1627 | \@paths |
1622 | } |
1628 | } |
1623 | |
1629 | |
1624 | =item $protocol_xml = $player->expand_cfpod ($crossfire_pod) |
1630 | =item $protocol_xml = $player->expand_cfpod ($cfpod) |
1625 | |
1631 | |
1626 | Expand crossfire pod fragments into protocol xml. |
1632 | Expand deliantra pod fragments into protocol xml. |
1627 | |
|
|
1628 | =cut |
|
|
1629 | |
|
|
1630 | use re 'eval'; |
|
|
1631 | |
|
|
1632 | my $group; |
|
|
1633 | my $interior; $interior = qr{ |
|
|
1634 | # match a pod interior sequence sans C<< >> |
|
|
1635 | (?: |
|
|
1636 | \ (.*?)\ (?{ $group = $^N }) |
|
|
1637 | | < (??{$interior}) > |
|
|
1638 | ) |
|
|
1639 | }x; |
|
|
1640 | |
|
|
1641 | sub expand_cfpod { |
|
|
1642 | my ($self, $pod) = @_; |
|
|
1643 | |
|
|
1644 | my $xml; |
|
|
1645 | |
|
|
1646 | while () { |
|
|
1647 | if ($pod =~ /\G( (?: [^BCGHITU]+ | .(?!<) )+ )/xgcs) { |
|
|
1648 | $group = $1; |
|
|
1649 | |
|
|
1650 | $group =~ s/&/&/g; |
|
|
1651 | $group =~ s/</</g; |
|
|
1652 | |
|
|
1653 | $xml .= $group; |
|
|
1654 | } elsif ($pod =~ m%\G |
|
|
1655 | ([BCGHITU]) |
|
|
1656 | < |
|
|
1657 | (?: |
|
|
1658 | ([^<>]*) (?{ $group = $^N }) |
|
|
1659 | | < $interior > |
|
|
1660 | ) |
|
|
1661 | > |
|
|
1662 | %gcsx |
|
|
1663 | ) { |
|
|
1664 | my ($code, $data) = ($1, $group); |
|
|
1665 | |
|
|
1666 | if ($code eq "B") { |
|
|
1667 | $xml .= "<b>" . expand_cfpod ($self, $data) . "</b>"; |
|
|
1668 | } elsif ($code eq "I") { |
|
|
1669 | $xml .= "<i>" . expand_cfpod ($self, $data) . "</i>"; |
|
|
1670 | } elsif ($code eq "U") { |
|
|
1671 | $xml .= "<u>" . expand_cfpod ($self, $data) . "</u>"; |
|
|
1672 | } elsif ($code eq "C") { |
|
|
1673 | $xml .= "<tt>" . expand_cfpod ($self, $data) . "</tt>"; |
|
|
1674 | } elsif ($code eq "T") { |
|
|
1675 | $xml .= "<big><b>" . expand_cfpod ($self, $data) . "</b></big>"; |
|
|
1676 | } elsif ($code eq "G") { |
|
|
1677 | my ($male, $female) = split /\|/, $data; |
|
|
1678 | $data = $self->gender ? $female : $male; |
|
|
1679 | $xml .= expand_cfpod ($self, $data); |
|
|
1680 | } elsif ($code eq "H") { |
|
|
1681 | $xml .= ("<fg name=\"lightblue\">[" . expand_cfpod ($self, $data) . " (Use hintmode to suppress hints)]</fg>", |
|
|
1682 | "<fg name=\"lightblue\">[Hint suppressed, see hintmode]</fg>", |
|
|
1683 | "") |
|
|
1684 | [$self->{hintmode}]; |
|
|
1685 | } else { |
|
|
1686 | $xml .= "error processing '$code($data)' directive"; |
|
|
1687 | } |
|
|
1688 | } else { |
|
|
1689 | if ($pod =~ /\G(.+)/) { |
|
|
1690 | warn "parse error while expanding $pod (at $1)"; |
|
|
1691 | } |
|
|
1692 | last; |
|
|
1693 | } |
|
|
1694 | } |
|
|
1695 | |
|
|
1696 | for ($xml) { |
|
|
1697 | # create single paragraphs (very hackish) |
|
|
1698 | s/(?<=\S)\n(?=\w)/ /g; |
|
|
1699 | |
|
|
1700 | # compress some whitespace |
|
|
1701 | s/\s+\n/\n/g; # ws line-ends |
|
|
1702 | s/\n\n+/\n/g; # double lines |
|
|
1703 | s/^\n+//; # beginning lines |
|
|
1704 | s/\n+$//; # ending lines |
|
|
1705 | } |
|
|
1706 | |
|
|
1707 | $xml |
|
|
1708 | } |
|
|
1709 | |
|
|
1710 | no re 'eval'; |
|
|
1711 | |
|
|
1712 | sub hintmode { |
|
|
1713 | $_[0]{hintmode} = $_[1] if @_ > 1; |
|
|
1714 | $_[0]{hintmode} |
|
|
1715 | } |
|
|
1716 | |
1633 | |
1717 | =item $player->ext_reply ($msgid, @msg) |
1634 | =item $player->ext_reply ($msgid, @msg) |
1718 | |
1635 | |
1719 | Sends an ext reply to the player. |
1636 | Sends an ext reply to the player. |
1720 | |
1637 | |
… | |
… | |
2534 | |
2451 | |
2535 | =item $player_object->enter_link |
2452 | =item $player_object->enter_link |
2536 | |
2453 | |
2537 | Freezes the player and moves him/her to a special map (C<{link}>). |
2454 | Freezes the player and moves him/her to a special map (C<{link}>). |
2538 | |
2455 | |
2539 | The player should be reasonably safe there for short amounts of time. You |
2456 | The player should be reasonably safe there for short amounts of time (e.g. |
2540 | I<MUST> call C<leave_link> as soon as possible, though. |
2457 | for loading a map). You I<MUST> call C<leave_link> as soon as possible, |
|
|
2458 | though, as the palyer cannot control the character while it is on the link |
|
|
2459 | map. |
2541 | |
2460 | |
2542 | Will never block. |
2461 | Will never block. |
2543 | |
2462 | |
2544 | =item $player_object->leave_link ($map, $x, $y) |
2463 | =item $player_object->leave_link ($map, $x, $y) |
2545 | |
2464 | |
… | |
… | |
2603 | |
2522 | |
2604 | $map->load; |
2523 | $map->load; |
2605 | $map->load_neighbours; |
2524 | $map->load_neighbours; |
2606 | |
2525 | |
2607 | return unless $self->contr->active; |
2526 | return unless $self->contr->active; |
|
|
2527 | $self->flag (cf::FLAG_DEBUG, 0);#d# temp |
2608 | $self->activate_recursive; |
2528 | $self->activate_recursive; |
2609 | |
2529 | |
2610 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2530 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2611 | $self->enter_map ($map, $x, $y); |
2531 | $self->enter_map ($map, $x, $y); |
2612 | } |
2532 | } |
… | |
… | |
2775 | $self->contr->savebed ($map, $x, $y) |
2695 | $self->contr->savebed ($map, $x, $y) |
2776 | if $exit->flag (cf::FLAG_DAMNED); |
2696 | if $exit->flag (cf::FLAG_DAMNED); |
2777 | |
2697 | |
2778 | 1 |
2698 | 1 |
2779 | }) { |
2699 | }) { |
2780 | $self->message ("Something went wrong deep within the crossfire server. " |
2700 | $self->message ("Something went wrong deep within the deliantra server. " |
2781 | . "I'll try to bring you back to the map you were before. " |
2701 | . "I'll try to bring you back to the map you were before. " |
2782 | . "Please report this to the dungeon master!", |
2702 | . "Please report this to the dungeon master!", |
2783 | cf::NDI_UNIQUE | cf::NDI_RED); |
2703 | cf::NDI_UNIQUE | cf::NDI_RED); |
2784 | |
2704 | |
2785 | warn "ERROR in enter_exit: $@"; |
2705 | warn "ERROR in enter_exit: $@"; |
… | |
… | |
2851 | id => "infobox", |
2771 | id => "infobox", |
2852 | title => "Body Parts", |
2772 | title => "Body Parts", |
2853 | reply => undef, |
2773 | reply => undef, |
2854 | tooltip => "Shows which body parts you posess and are available", |
2774 | tooltip => "Shows which body parts you posess and are available", |
2855 | }, |
2775 | }, |
|
|
2776 | "c/skills" => { |
|
|
2777 | id => "infobox", |
|
|
2778 | title => "Skills", |
|
|
2779 | reply => undef, |
|
|
2780 | tooltip => "Shows your experience per skill and item power", |
|
|
2781 | }, |
2856 | "c/uptime" => { |
2782 | "c/uptime" => { |
2857 | id => "infobox", |
2783 | id => "infobox", |
2858 | title => "Uptime", |
2784 | title => "Uptime", |
2859 | reply => undef, |
2785 | reply => undef, |
2860 | tooltip => "How long the server has been running since last restart", |
2786 | tooltip => "How long the server has been running since last restart", |
… | |
… | |
2874 | ); |
2800 | ); |
2875 | |
2801 | |
2876 | sub cf::client::send_msg { |
2802 | sub cf::client::send_msg { |
2877 | my ($self, $channel, $msg, $color, @extra) = @_; |
2803 | my ($self, $channel, $msg, $color, @extra) = @_; |
2878 | |
2804 | |
2879 | $msg = $self->pl->expand_cfpod ($msg); |
2805 | $msg = $self->pl->expand_cfpod ($msg) |
|
|
2806 | unless $color & cf::NDI_VERBATIM; |
2880 | |
2807 | |
2881 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2808 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2882 | |
2809 | |
2883 | # check predefined channels, for the benefit of C |
2810 | # check predefined channels, for the benefit of C |
2884 | if ($CHANNEL{$channel}) { |
2811 | if ($CHANNEL{$channel}) { |
… | |
… | |
2905 | if ($self->can_msg) { |
2832 | if ($self->can_msg) { |
2906 | # default colour, mask it out |
2833 | # default colour, mask it out |
2907 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2834 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2908 | if $color & cf::NDI_DEF; |
2835 | if $color & cf::NDI_DEF; |
2909 | |
2836 | |
2910 | $self->send_packet ("msg " . $self->{json_coder}->encode ( |
2837 | my $pkt = "msg " |
|
|
2838 | . $self->{json_coder}->encode ( |
2911 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra])); |
2839 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
|
|
2840 | ); |
|
|
2841 | |
|
|
2842 | # try lzf for large packets |
|
|
2843 | $pkt = "lzf " . Compress::LZF::compress $pkt |
|
|
2844 | if 1024 <= length $pkt and $self->{can_lzf}; |
|
|
2845 | |
|
|
2846 | # split very large packets |
|
|
2847 | if (8192 < length $pkt and $self->{can_lzf}) { |
|
|
2848 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
|
|
2849 | $pkt = "frag"; |
|
|
2850 | } |
|
|
2851 | |
|
|
2852 | $self->send_packet ($pkt); |
2912 | } else { |
2853 | } else { |
2913 | if ($color >= 0) { |
2854 | if ($color >= 0) { |
2914 | # replace some tags by gcfclient-compatible ones |
2855 | # replace some tags by gcfclient-compatible ones |
2915 | for ($msg) { |
2856 | for ($msg) { |
2916 | 1 while |
2857 | 1 while |
… | |
… | |
3428 | }; |
3369 | }; |
3429 | warn $@ if $@; |
3370 | warn $@ if $@; |
3430 | } |
3371 | } |
3431 | } |
3372 | } |
3432 | |
3373 | |
|
|
3374 | sub pidfile() { |
|
|
3375 | sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT |
|
|
3376 | or die "$PIDFILE: $!"; |
|
|
3377 | flock $fh, &Fcntl::LOCK_EX |
|
|
3378 | or die "$PIDFILE: flock: $!"; |
|
|
3379 | $fh |
|
|
3380 | } |
|
|
3381 | |
|
|
3382 | # make sure only one server instance is running at any one time |
|
|
3383 | sub atomic { |
|
|
3384 | my $fh = pidfile; |
|
|
3385 | |
|
|
3386 | my $pid = <$fh>; |
|
|
3387 | kill 9, $pid if $pid > 0; |
|
|
3388 | |
|
|
3389 | seek $fh, 0, 0; |
|
|
3390 | print $fh $$; |
|
|
3391 | } |
|
|
3392 | |
3433 | sub main { |
3393 | sub main { |
|
|
3394 | atomic; |
|
|
3395 | |
3434 | # we must not ever block the main coroutine |
3396 | # we must not ever block the main coroutine |
3435 | local $Coro::idle = sub { |
3397 | local $Coro::idle = sub { |
3436 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3398 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3437 | (async { |
3399 | (async { |
3438 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3400 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
… | |
… | |
3447 | load_extensions; |
3409 | load_extensions; |
3448 | |
3410 | |
3449 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3411 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3450 | } |
3412 | } |
3451 | |
3413 | |
|
|
3414 | utime time, time, $RUNTIMEFILE; |
|
|
3415 | |
|
|
3416 | # no (long-running) fork's whatsoever before this point(!) |
|
|
3417 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
|
|
3418 | |
3452 | EV::loop; |
3419 | EV::loop; |
3453 | } |
3420 | } |
3454 | |
3421 | |
3455 | ############################################################################# |
3422 | ############################################################################# |
3456 | # initialisation and cleanup |
3423 | # initialisation and cleanup |
… | |
… | |
3464 | }; |
3431 | }; |
3465 | } |
3432 | } |
3466 | } |
3433 | } |
3467 | |
3434 | |
3468 | sub write_runtime_sync { |
3435 | sub write_runtime_sync { |
3469 | my $runtime = "$LOCALDIR/runtime"; |
|
|
3470 | |
|
|
3471 | # first touch the runtime file to show we are still running: |
3436 | # first touch the runtime file to show we are still running: |
3472 | # the fsync below can take a very very long time. |
3437 | # the fsync below can take a very very long time. |
3473 | |
3438 | |
3474 | IO::AIO::aio_utime $runtime, undef, undef; |
3439 | IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; |
3475 | |
3440 | |
3476 | my $guard = cf::lock_acquire "write_runtime"; |
3441 | my $guard = cf::lock_acquire "write_runtime"; |
3477 | |
3442 | |
3478 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
3443 | my $fh = aio_open "$RUNTIMEFILE~", O_WRONLY | O_CREAT, 0644 |
3479 | or return; |
3444 | or return; |
3480 | |
3445 | |
3481 | my $value = $cf::RUNTIME + 90 + 10; |
3446 | my $value = $cf::RUNTIME + 90 + 10; |
3482 | # 10 is the runtime save interval, for a monotonic clock |
3447 | # 10 is the runtime save interval, for a monotonic clock |
3483 | # 60 allows for the watchdog to kill the server. |
3448 | # 60 allows for the watchdog to kill the server. |
… | |
… | |
3493 | aio_utime $fh, undef, undef; |
3458 | aio_utime $fh, undef, undef; |
3494 | |
3459 | |
3495 | close $fh |
3460 | close $fh |
3496 | or return; |
3461 | or return; |
3497 | |
3462 | |
3498 | aio_rename "$runtime~", $runtime |
3463 | aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE |
3499 | and return; |
3464 | and return; |
3500 | |
3465 | |
3501 | warn "runtime file written.\n"; |
3466 | warn "runtime file written.\n"; |
3502 | |
3467 | |
3503 | 1 |
3468 | 1 |
… | |
… | |
3587 | sub post_cleanup { |
3552 | sub post_cleanup { |
3588 | my ($make_core) = @_; |
3553 | my ($make_core) = @_; |
3589 | |
3554 | |
3590 | warn Carp::longmess "post_cleanup backtrace" |
3555 | warn Carp::longmess "post_cleanup backtrace" |
3591 | if $make_core; |
3556 | if $make_core; |
|
|
3557 | |
|
|
3558 | my $fh = pidfile; |
|
|
3559 | unlink $PIDFILE if <$fh> == $$; |
3592 | } |
3560 | } |
3593 | |
3561 | |
3594 | # a safer delete_package, copied from Symbol |
3562 | # a safer delete_package, copied from Symbol |
3595 | sub clear_package($) { |
3563 | sub clear_package($) { |
3596 | my $pkg = shift; |
3564 | my $pkg = shift; |
… | |
… | |
3877 | $msg =~ s/\n//; |
3845 | $msg =~ s/\n//; |
3878 | |
3846 | |
3879 | # limit the # of concurrent backtraces |
3847 | # limit the # of concurrent backtraces |
3880 | if ($_log_backtrace < 2) { |
3848 | if ($_log_backtrace < 2) { |
3881 | ++$_log_backtrace; |
3849 | ++$_log_backtrace; |
|
|
3850 | my $perl_bt = Carp::longmess $msg; |
3882 | async { |
3851 | async { |
3883 | $Coro::current->{desc} = "abt $msg"; |
3852 | $Coro::current->{desc} = "abt $msg"; |
3884 | |
3853 | |
3885 | my @bt = fork_call { |
3854 | my @bt = fork_call { |
3886 | @addr = map { sprintf "%x", $_ } @addr; |
3855 | @addr = map { sprintf "%x", $_ } @addr; |
… | |
… | |
3897 | } |
3866 | } |
3898 | |
3867 | |
3899 | @funcs |
3868 | @funcs |
3900 | }; |
3869 | }; |
3901 | |
3870 | |
3902 | LOG llevInfo, "[ABT] $msg\n"; |
3871 | LOG llevInfo, "[ABT] $perl_bt\n"; |
|
|
3872 | LOG llevInfo, "[ABT] --- C backtrace follows ---\n"; |
3903 | LOG llevInfo, "[ABT] $_\n" for @bt; |
3873 | LOG llevInfo, "[ABT] $_\n" for @bt; |
3904 | --$_log_backtrace; |
3874 | --$_log_backtrace; |
3905 | }; |
3875 | }; |
3906 | } else { |
3876 | } else { |
3907 | LOG llevInfo, "[ABT] $msg\n"; |
3877 | LOG llevInfo, "[ABT] $msg\n"; |