From: Alan Kennedy Date: Sun, 24 Oct 2004 01:44:39 +0000 (+0000) Subject: Se agrega locking X-Git-Tag: svn_import~87 X-Git-Url: https://git.llucax.com/z.facultad/75.08/llamadas.git/commitdiff_plain/fbda2151a8f5f6e2e7fdf5b1d63a38b57fbac262?hp=1e1f3efdb3895228a4c60a9e0eb11e99355ac038 Se agrega locking --- diff --git a/inst/antifraude.pl b/inst/antifraude.pl index cc65421..47ffc42 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})/; @@ -130,6 +154,10 @@ if ((!$ARGV[0]) || (! -d $ARGV[0])) { print("No se ha ingresado un directorio fuente de llamadas\n"); exit 1; } + +# Lock file +lock(); + # Defino some GLOBALS $CONFDIR = shift; $CONFDATA{logdir} = getConfVar("$CONFDIR/afinstal.conf",12); @@ -188,3 +216,6 @@ FILE: foreach $filename (@archivos) { logEntry("Fin proceso de: $filename",1); } + +# Unlocking +unlock();