From 1ae303df55b1b9c631ac27e60d3bd3550fee7041 Mon Sep 17 00:00:00 2001 From: realraum Date: Thu, 4 Nov 2010 14:24:32 +0000 Subject: [PATCH] add/remove card ids without restarting checkcard.pl --- checkcard.pl | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/checkcard.pl b/checkcard.pl index cc1d1b7..fb576be 100755 --- a/checkcard.pl +++ b/checkcard.pl @@ -5,20 +5,29 @@ use strict; my $fh; my $socketfile = $ARGV[0] || "/var/run/tuer/door_cmd.socket"; +my $keysfile = '/flash/keys'; + sleep(1) while (! -S $socketfile); my $socketaddr = sockaddr_un($socketfile); -my $keys; my %good; +my $keys_last_read=0; -open $keys,'/flash/keys'; -while (<$keys>) +sub read_keys { - chomp; - if ($_ =~ /^([0-9A-Fa-f]{8})\s+(.+)$/) - { - $good{$1}=$2; - } + %good=(); + my $keys; + open $keys,$keysfile; + while (<$keys>) + { + chomp; + if ($_ =~ /^([0-9A-Fa-f]{8})\s+(.+)$/) + { + $good{$1}=$2; + } + } + close $keys; + $keys_last_read = -M ($keysfile); } sub send_to_fifo @@ -29,9 +38,15 @@ sub send_to_fifo close($conn); } +read_keys(); + + while (sleep 1) { open $fh,'/flash/tuer/mifare-read 0 2>&1 |'; + + read_keys() unless ($keys_last_read == -M ($keysfile)); + while (<$fh>) { next unless /UID/; -- 1.7.10.4