#!/usr/bin/perl -w use sigtrap 'handler' => \&shutdown, 'INT', 'ABRT', 'QUIT', 'TERM'; sub shutdown{ print logTime." INT|ABRT|QUIT|TERM received....shutting down service.\n"; # # HOW DO I KILL MY ASYNC BLOCK / LOGIN THREADS FROM HERE # # close(LOOK_FOR_LEASE) if fileno(LOOK_FOR_LEASE); close(OUTPUT) if fileno(OUTPUT); close(ERROR) if fileno(ERROR); threads->exit(); } # Opening log file. # Redirecting OUTPUT and ERR to log file for all threads open OUTPUT, '>>', "/usr/local/xxx/log/lease.log" or die $!; open ERROR, '>>', "/usr/local/xxx/log/lease.log" or die $!; STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; STDERR->fdopen( \*ERROR, 'w' ) or die $!; # Declare shared variables here ... ... $sharedMAChash :shared; ################ MAC watch Thread1################## $thread300 = async { while(sleep 300){ # Checking done here. # Contact server. Get status of all macs from server # Note : Hash value 1 = Authenticated device. 0 = Failed Login device. # Parse server response here. # Is online ? $sharedMAChash{$mac} = 1 # No change # Is online && $sharedMAChash{$mac} = 0? # Del from hash # Is offline? # Del from hash } }; ################## Main Thread ################## while(usleep 250000){ while(){ # Found a new IP lease . Parse MAC # Launch Login thread $allmac{$mac} = threads->create(\&loginmac); } } ################## Login thread ################## sub loginmac{ # Use HTTP::Request and contact server and Auth this device. # Login Success? $sharedMAChash{$mac} = 1; # Authentication Success # Login Fail $sharedMAChash{$mac} = 0; # Authenticatication Fail.Hold MAC in hash until Timeout threads drops it from hash. }