X-Git-Url: https://git.llucax.com/z.facultad/75.08/llamadas.git/blobdiff_plain/de75f70bd685c8851fcf6ad66d86d53e4b2739ed..c73e52eb8d8b3798ac447fc5a851140a7472ed6c:/inst/antifraude.pl?ds=inline diff --git a/inst/antifraude.pl b/inst/antifraude.pl index 8417306..cdb843d 100644 --- a/inst/antifraude.pl +++ b/inst/antifraude.pl @@ -1,5 +1,29 @@ #!/usr/bin/perl +sub is_lock { + if ( -e "$ENV{'HOME'}/.antifraude/lock/antifraude.pid" ) { + # Lock file encontrado + return 1; + } + # No hay lock file! + return 0; +} + +sub unlock { + unlink ("$ENV{'HOME'}/.antifraude/lock/antifraude.pid"); +} + +sub lock { + if (!is_lock()) { + local $lfile = "$ENV{'HOME'}/.antifraude/lock/antifraude.pid"; + open(LOCKFILE,">>$lfile"); + print LOCKFILE $$; + close(LOCKFILE); + return 1; + } + return 0; +} + # Comparador de fecha para los archivos de llamada sub byDate { ($year1,$mon1,$day1,$hr1,$min1) = $a =~ /([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/; @@ -58,8 +82,18 @@ sub logEntry { open(LOGFILE,">>$log") or die "No se pudo abrir el archivo de log"; seek(LOGFILE,0,2); print LOGFILE "$commonstring - $logentry\n"; + $filesize = tell(LOGFILE); close(LOGFILE); + # Chequeo el logsize y su lo supero me quedo con 100 lineas + if ($filesize > ($CONFDATA{logsize} * 1024 * 1024)) + { + open(LOGFILE,"+<$log"); + do ($line = ) until $. == 100; + truncate(LOGFILE,tell(LOGFILE)); + close(LOGFILE); + } + if ($consoleout) { print("$logentry\n"); } } @@ -72,8 +106,8 @@ sub badCall { } sub checkUmbrales { - local(*callfields) = @_[0]; - my $callsfile = @_[1]; + local(*callfields) = $_[0]; + my $callsfile = $_[1]; my $matchedUmbral = 0; my $i = 0; @@ -128,6 +162,11 @@ if ((!$ARGV[0]) || (! -d $ARGV[0])) { print("No se ha ingresado un directorio fuente de llamadas\n"); exit 1; } + +# File locking.. +if (is_lock()) { exit 1; } +lock(); + # Defino some GLOBALS $CONFDIR = shift; $CONFDATA{logdir} = getConfVar("$CONFDIR/afinstal.conf",12); @@ -186,3 +225,6 @@ FILE: foreach $filename (@archivos) { logEntry("Fin proceso de: $filename",1); } + +# Unlocking +unlock();