package Cochrane; use Cochrane::Store; use IO::File; use IO::Pipe; use IO::Select; use strict; use warnings; my $logfile; use constant { DAY => 24 * 60 * 60, START => [ 'Cochrane::Input::GPSD', 'Cochrane::Input::SMTP', 'Cochrane::Output::HTTP', 'Cochrane::Output::DNS', ], YEAR => 365 * 24 * 60 * 60, }; sub new { my ($class) = @_; my $self = {}; mkdir Cochrane::Store::PATH_RUN().'/log'; return bless($self, $class); } sub run { my ($self) = @_; $SIG{CHLD} = 'IGNORE'; my $select = IO::Select->new; for my $start (@{START()}) { my $pipe = IO::Pipe->new(); my $pid = fork(); if (0 == $pid) { $pipe->writer; open(STDOUT, '>&', $pipe); while (1) { eval "use $start; $start->new->run();"; } } elsif ($pid > 0) { $pipe->reader; $pipe->blocking(0); $select->add($pipe); } else { STDOUT->print("Failed to fork: $!"); } } while (1) { my @data; for my $pipe ($select->can_read) { push @data, <$pipe>; } STDOUT->print(@data); my $logfile = sprintf("%s/log/%s", Cochrane::Store::PATH_RUN(), int(time()/3600)*3600, ); $logfile = IO::File->new($logfile, ">"); $logfile->print(@data); } } 1;