From: Stefan Schantl Date: Fri, 22 Jan 2016 13:55:41 +0000 (+0100) Subject: Rename and move InitFileposition function. X-Git-Tag: 2.0~42 X-Git-Url: http://git.ipfire.org/?p=people%2Fstevee%2Fguardian.git;a=commitdiff_plain;h=7a6a268295054bdde300e10e10db13d61c82db62;ds=sidebyside Rename and move InitFileposition function. Signed-off-by: Stefan Schantl --- diff --git a/modules/Base.pm b/modules/Base.pm index fbda49a..2f5e737 100644 --- a/modules/Base.pm +++ b/modules/Base.pm @@ -6,35 +6,6 @@ use Exporter qw(import); our @EXPORT_OK = qw(GenerateMonitoredFiles FilePositions); -# -## Function for fileposition initialization. -# -## This function is used to get the cursor position of the end of file (EOF) of -## a specified file. -# -## In order to prevent from permanently read and keep files opened, or dealing -## with huge logfiles, at initialization time of the worker processes, the file will -## be opened once and the cursor position of the end of file (EOF) get stored. -# -sub InitFileposition ($) { - my $file = $_[0]; - - # Open the file. - open(FILE, $file) or die "Could not open $file. $!"; - - # Just seek to the end of the file (EOF). - seek(FILE, 0, 2); - - # Get and store the position. - my $position = tell(FILE), - - # Close the file again. - close(FILE); - - # Return the position. - return $position; -} - # ## Function to generate a hash of monitored files and their file positions. # @@ -134,7 +105,7 @@ sub FilePositions (\%\%) { $new_file_positions{$file} = $current_file_positions{$file}; } else { # Call function to obtain the file position. - my $position = &InitFileposition($file); + my $position = &_initFileposition($file); # Add filename and position to the temporary hash. $new_file_positions{$file} = $position; @@ -145,4 +116,33 @@ sub FilePositions (\%\%) { return %new_file_positions; } +# +## Function for fileposition initialization. +# +## This function is used to get the cursor position of the end of file (EOF) of +## a specified file. +# +## In order to prevent from permanently read and keep files opened, or dealing +## with huge logfiles, at initialization time of the worker processes, the file will +## be opened once and the cursor position of the end of file (EOF) get stored. +# +sub _initFileposition ($) { + my $file = $_[0]; + + # Open the file. + open(FILE, $file) or die "Could not open $file. $!"; + + # Just seek to the end of the file (EOF). + seek(FILE, 0, 2); + + # Get and store the position. + my $position = tell(FILE), + + # Close the file again. + close(FILE); + + # Return the position. + return $position; +} + 1;