| 72 | | my $self = shift; |
| 73 | | |
| 74 | | unless (POSIX::setsid) { |
| 75 | | EBox::debug ('Cannot start new session for ', $self->{'name'}); |
| 76 | | exit 1; |
| 77 | | } |
| 78 | | |
| 79 | | foreach my $fd (0 .. 64) { POSIX::close($fd); } |
| 80 | | |
| 81 | | my $tmp = EBox::Config::tmp(); |
| 82 | | open(STDIN, "+<$tmp/stdin"); |
| 83 | | if (EBox::Config::configkey('debug') eq 'yes') { |
| 84 | | open(STDOUT, "+>$tmp/stout"); |
| 85 | | open(STDERR, "+>$tmp/stderr"); |
| 86 | | } |
| 87 | | |
| | 71 | my ($self) = @_; |
| | 72 | |
| | 73 | unless (POSIX::setsid) { |
| | 74 | EBox::debug ('Cannot start new session for ', $self->{'name'}); |
| | 75 | exit 1; |
| | 76 | } |
| | 77 | |
| | 78 | foreach my $fd (0 .. 64) { POSIX::close($fd); } |
| | 79 | |
| | 80 | my $tmp = EBox::Config::tmp(); |
| | 81 | open(STDIN, "+<$tmp/stdin"); |
| | 82 | if (EBox::Config::configkey('debug') eq 'yes') { |
| | 83 | open(STDOUT, "+>$tmp/stout"); |
| | 84 | open(STDERR, "+>$tmp/stderr"); |
| | 85 | } |
| | 86 | |
| 101 | | pipe $piperd, $pipewr; |
| 102 | | $SIG {"INT"} = \&int_handler; |
| 103 | | |
| 104 | | my @loghelpers = @{$self->{'loghelpers'}}; |
| 105 | | for my $obj (@loghelpers) { |
| 106 | | for my $file (@{$obj->logFiles()}) { |
| 107 | | my $tail; |
| 108 | | eval { $tail = File::Tail->new(name => $file, |
| 109 | | interval => 1, maxinterval => 1, |
| 110 | | ignore_nonexistant => 1)}; |
| 111 | | |
| 112 | | if ($@) { |
| 113 | | EBox::warn($@); |
| 114 | | next; |
| 115 | | } |
| 116 | | push @{$self->{'filetails'}}, $tail; |
| 117 | | push @{$self->{'objects'}->{$file}}, $obj; |
| 118 | | } |
| 119 | | } |
| | 111 | if ($@) { |
| | 112 | EBox::warn($@); |
| | 113 | next; |
| | 114 | } |
| | 115 | push @{$self->{'filetails'}}, $tail; |
| | 116 | push @{$self->{'objects'}->{$file}}, $obj; |
| | 117 | } |
| | 118 | } |
| 125 | | my $self = shift; |
| 126 | | my $rin; |
| 127 | | |
| 128 | | my @files = @{$self->{'filetails'}}; |
| 129 | | while(@files) { |
| 130 | | vec($rin, fileno($piperd), 1) = 1; |
| 131 | | my ($nfound, $timeleft, @pending)= |
| 132 | | File::Tail::select($rin, undef, undef, undef , @files); |
| 133 | | if ($nfound > @pending) { |
| 134 | | EBox::info "Exiting Loggerd\n"; |
| 135 | | exit 0; |
| 136 | | } |
| 137 | | foreach my $file (@pending) { |
| 138 | | my $path = $file->{'input'}; |
| 139 | | my $buffer = $file->read(); |
| 140 | | if (defined($buffer) and length ($buffer) > 0) { |
| 141 | | for my $obj (@{$self->{'objects'}->{$path}}) { |
| 142 | | foreach my $line (split(/\n/, $buffer)) { |
| 143 | | eval {$obj->processLine($path, $line, |
| 144 | | $self->{'dbengine'})}; |
| 145 | | } |
| 146 | | } |
| 147 | | } |
| 148 | | } |
| 149 | | |
| 150 | | } |
| 151 | | |
| | 124 | my ($self) = @_; |
| | 125 | my $rin; |
| | 126 | |
| | 127 | my @files = @{$self->{'filetails'}}; |
| | 128 | while(@files) { |
| | 129 | vec($rin, fileno($piperd), 1) = 1; |
| | 130 | my ($nfound, $timeleft, @pending)= |
| | 131 | File::Tail::select($rin, undef, undef, undef , @files); |
| | 132 | if ($nfound > @pending) { |
| | 133 | EBox::info "Exiting Loggerd\n"; |
| | 134 | exit 0; |
| | 135 | } |
| | 136 | foreach my $file (@pending) { |
| | 137 | my $path = $file->{'input'}; |
| | 138 | my $buffer = $file->read(); |
| | 139 | if (defined($buffer) and length ($buffer) > 0) { |
| | 140 | for my $obj (@{$self->{'objects'}->{$path}}) { |
| | 141 | foreach my $line (split(/\n/, $buffer)) { |
| | 142 | eval {$obj->processLine($path, $line, |
| | 143 | $self->{'dbengine'})}; |
| | 144 | } |
| | 145 | } |
| | 146 | } |
| | 147 | } |
| | 148 | |
| | 149 | } |
| | 150 | |