Changeset 11607 for branches

Show
Ignore:
Timestamp:
11/10/08 11:24:25 (8 weeks ago)
Author:
javier.amor.garcia@…
Message:

indented and untabified refs #1149

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/pop-proxy-branch/ebox/src/EBox/Loggerd.pm

    r10436 r11607  
    3737sub int_handler 
    3838{ 
    39         syswrite $pipewr, 1, 1; 
     39    syswrite $pipewr, 1, 1; 
    4040} 
    4141 
    4242sub new  
    4343{ 
    44         my $class = shift; 
    45         my $self = {}; 
    46         my %opts = @_; 
    47         $self->{'filetails'} = [] ;  
    48         bless($self, $class); 
    49         return $self; 
     44    my $class = shift; 
     45    my $self = {}; 
     46    my %opts = @_; 
     47    $self->{'filetails'} = [] ;  
     48    bless($self, $class); 
     49    return $self; 
    5050} 
    5151 
    5252sub run  
    5353{ 
    54         my $self = shift; 
     54    my ($self) = @_; 
     55     
     56    EBox::init(); 
     57     
     58    $self->initDaemon(); 
    5559 
    56         EBox::init(); 
    57  
    58         $self->initDaemon(); 
    59  
    60         my $global = EBox::Global->getInstance(); 
    61         my $log = $global->modInstance('logs'); 
    62         $self->{'loghelpers'} = $log->allEnabledLogHelpers(); 
    63         $self->{'dbengine'} = EBox::DBEngineFactory::DBEngine(); 
    64         $self->_prepare(); 
    65         $self->_mainloop(); 
    66  
     60    my $global = EBox::Global->getInstance(); 
     61    my $log = $global->modInstance('logs'); 
     62    $self->{'loghelpers'} = $log->allEnabledLogHelpers(); 
     63    $self->{'dbengine'} = EBox::DBEngineFactory::DBEngine(); 
     64    $self->_prepare(); 
     65    $self->_mainloop(); 
    6766} 
    6867 
     
    7069sub initDaemon 
    7170{ 
    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     
    8887} 
    8988 
     
    9392# Method: _prepare 
    9493# 
    95 #       Init the necessary stuff, such as open fifos, use required classes, etc. 
     94#       Init the necessary stuff, such as open fifos, use required classes, etc. 
    9695# 
    9796sub _prepare # (fifo) 
    9897{ 
    99         my ($self) = @_; 
     98    my ($self) = @_; 
     99     
     100    pipe $piperd, $pipewr; 
     101    $SIG {"INT"} = \&int_handler; 
     102     
     103    my @loghelpers = @{$self->{'loghelpers'}}; 
     104    for my $obj (@loghelpers) { 
     105        for my $file (@{$obj->logFiles()}) { 
     106            my $tail; 
     107            eval { $tail = File::Tail->new(name => $file,  
     108                                           interval => 1, maxinterval => 1, 
     109                                           ignore_nonexistant => 1)}; 
    100110 
    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    } 
    120119 
    121120} 
     
    123122sub _mainloop 
    124123{ 
    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     
    152151} 
    153152