… | |
… | |
53 | # load modules we will use later anyways |
53 | # load modules we will use later anyways |
54 | use common::sense; |
54 | use common::sense; |
55 | |
55 | |
56 | use Carp (); |
56 | use Carp (); |
57 | |
57 | |
58 | our $VERSION = '0.1'; |
58 | our $VERSION = '0.9'; |
59 | |
59 | |
60 | our $PID; # child pid |
60 | our $PID; # child pid |
61 | our $ENABLED = 1; |
61 | our $ENABLED = 1; |
62 | our $AUTORESTART; # actually exit |
62 | our $AUTORESTART; # actually exit |
63 | our $HEARTBEAT; |
63 | our $HEARTBEAT; |
… | |
… | |
118 | |
118 | |
119 | } elsif ($cmd eq chr 3) { |
119 | } elsif ($cmd eq chr 3) { |
120 | sysread $P, my $interval, 1 |
120 | sysread $P, my $interval, 1 |
121 | or last; |
121 | or last; |
122 | |
122 | |
123 | $heartbeat = ord $interval |
123 | $heartbeat = ord $interval; |
124 | unless defined $heartbeat; |
|
|
125 | |
124 | |
126 | } elsif ($cmd eq chr 4) { |
125 | } elsif ($cmd eq chr 4) { |
127 | # heartbeat |
126 | # heartbeat |
128 | # TODO: should only reset heartbeat timeout with \005 |
127 | # TODO: should only reset heartbeat timeout with \005 |
129 | |
128 | |
… | |
… | |
165 | |
164 | |
166 | our %SEEKPOS; |
165 | our %SEEKPOS; |
167 | # due to bugs in perl, try to remember file offsets for all fds, and restore them later |
166 | # due to bugs in perl, try to remember file offsets for all fds, and restore them later |
168 | # (the parser otherwise exhausts the input files) |
167 | # (the parser otherwise exhausts the input files) |
169 | |
168 | |
170 | # this causes perlio to flush it's handles internally, so |
169 | # this causes perlio to flush its handles internally, so |
171 | # seek offsets become correct. |
170 | # seek offsets become correct. |
172 | exec "."; # toi toi toi |
171 | exec "."; # toi toi toi |
173 | #{ |
172 | #{ |
174 | # local $SIG{CHLD} = 'DEFAULT'; |
173 | # local $SIG{CHLD} = 'DEFAULT'; |
175 | # my $pid = fork; |
174 | # my $pid = fork; |
… | |
… | |
179 | # } else { |
178 | # } else { |
180 | # kill 9, $$; |
179 | # kill 9, $$; |
181 | # } |
180 | # } |
182 | #} |
181 | #} |
183 | |
182 | |
184 | # now records all fd positions |
183 | # now record "all" fd positions, assuming 1023 is more than enough. |
185 | for (0 .. 1023) { |
184 | for (0 .. 1023) { |
186 | open my $fh, "<&$_" or next; |
185 | open my $fh, "<&$_" or next; |
187 | $SEEKPOS{$_} = (sysseek $fh, 0, 1 or next); |
186 | $SEEKPOS{$_} = (sysseek $fh, 0, 1 or next); |
188 | } |
187 | } |
189 | |
188 | |
… | |
… | |
269 | twice as often. |
268 | twice as often. |
270 | |
269 | |
271 | Exit behaviour isn't changed, so if you want a restart instead of an exit, |
270 | Exit behaviour isn't changed, so if you want a restart instead of an exit, |
272 | you have to call C<autorestart>. |
271 | you have to call C<autorestart>. |
273 | |
272 | |
274 | Once enabled, the heartbeat cannot be switched off. |
273 | The heartbeat frequency can be changed as often as you want, an interval |
|
|
274 | of C<0> disables the heartbeat check again. |
275 | |
275 | |
276 | =cut |
276 | =cut |
277 | |
277 | |
278 | sub heartbeat(;$) { |
278 | sub heartbeat(;$) { |
279 | my ($interval) = @_; |
279 | my ($interval) = @_; |