package POEDaemon::WheelRun::NTPdc; use strict; use warnings FATAL => 'all'; no warnings 'redefine'; use POE; use POEDaemon; sub states { return $_[0], [qw( ntpdc_start ntpdc_stop ntpdc_childexit ntpdc ntpdc_stdout_line )]; } sub ntpdc_start { my $kernel = $_[KERNEL]; $kernel->yield(wheelrun_exec => { prog => [ 'util/ntpdc.sh' ], name => 'ntpdc', stdout_event => 'ntpdc_stdout_line', }); } sub ntpdc_stop { my $kernel = $_[KERNEL]; $kernel->yield(wheelrun_kill => { wheel_name => 'ntpdc' }); } sub ntpdc_childexit { my ($kernel, $heap) = @_[KERNEL, HEAP]; unless ($heap->{shutdown}) { $kernel->yield(shutdown => 'ntpdc child abnormally terminated'); } } sub ntpdc { my ($heap, $args) = @_[HEAP, ARG0]; my $cmd = $args->{cmd}; return unless $cmd; $heap->{ntpdc}->{source_wheel_id} = $args->{source_tcpclient_wheel_id} || $args->{source_tcpclient_readwrite_wheel_id} || $args->{source_wheel_id} || return; $heap->{ntpdc}->{source_type} = $args->{source_type} || return; $heap->{ntpdc}->{cmd} = $cmd || return; my $wheel = $heap->{wheel_run}->{children_by_name}->{ntpdc}->{wheel}; return unless $wheel; #log_enabled && logline "put '%s'", $cmd; $wheel->put($cmd); } sub ntpdc_stdout_line { my ($kernel, $session, $heap, $line) = @_[KERNEL, SESSION, HEAP, ARG0]; #log_enabled && logline "line = '%s'", $line; if ($line =~ /^\s*(system\s+peer):\s+(\S+)\s*$/i) { my $name = lc $1; my $value = $2; $name =~ s/\s+/\x20/g; delete $heap->{ntpdc}->{source_wheel_id}; delete $heap->{ntpdc}->{source_type}; my $cmd = delete $heap->{ntpdc}->{cmd}; $heap->{ntpdc}->{cmd_results}->{$cmd}->{$name}->{value} = $value if $cmd; my $output_per_target; $output_per_target->{tcpserver} = sprintf "NTPSYSPEER %s", $value; $output_per_target->{tcpclient} = sprintf "%s ntpsyspeer %s", POECLIENT_CMD_PREFIX, $value; #my $wheel_id = delete $heap->{ntpdc}->{source_wheel_id}; #my $type = delete $heap->{ntpdc}->{source_type}; #my $cmd = delete $heap->{ntpdc}->{cmd}; # # #if ($wheel_id && $cmd) #{ # $heap->{ntpdc}->{cmd_results}->{$cmd}->{$name}->{value} = $value; # # # my $output = $value; # # # if ($name eq 'system peer' && $type && $type eq 'poeclient') # { # $output = sprintf "%s ntpsyspeer %s", # POECLIENT_CMD_PREFIX, # $output; # # # $kernel->yield(tcpclient_output => # { # wheel_id => $wheel_id, # output => $output, # }); # } # else # { # if ($heap->{tcpserver}->{connections}->{$wheel_id}->{wheel}) # { # $kernel->yield(tcpserver_output => # { # wheel_id => $wheel_id, # output => $output, # }); # } # } #} $kernel->call($session => wheelrun_send_network_reply => { output_per_target => $output_per_target, }); } } 1;