share variables in perl script (rlm_perl)

Iliya Peregoudov iperegudov at cboss.ru
Tue Dec 4 08:14:13 CET 2012


Arran Cudbard-Bell wrote:
> On 29 Nov 2012, at 22:14, laurent.feron at free.fr wrote:
> 
>> Hello,
>>
>> In a perl script (where authorize() and authenticate() are defined), i was able to set a global variable. when a radius request comes, the script may modify the variable, and the next request has the new value. I test with radiusd -X, and everything is fine.
>>
>> when radiusd is started as a daemon, 5 threads (default value) are started. And now, i understood i have 5 different perl "environments".
>> Meaning, when i start the first radtest that modifies the global variable, only the sixth request can view the global variable modified by the first request( i guess the sixth one turns into the first thread).
>>
>> I hope my explanation is clear. I would like to know if it possible to have a unique sharing enviroment (the basic solution is maybe to have only one thread, but it should be good for performance)
> 
> No, submit patches if you want this functionality.

You can explicitly share data between perl interpreters. However you'll 
need to explicitly lock shared data. See perldoc threads::shared for 
details.

use threads;
# this module contains share() and lock()
use threads::shared;

# hashes get empty on share
my %sharedhash;
share(%sharedhash);

sub put($$) {
    my ($key, $value) = @_
    lock(%sharedhash);
    $sharedhash{$key} = share($value);
    return;
}
sub get($) {
    my ($key) = @_;
    lock(%sharedhash);
    my $value = $sharedhash{$key};
    return $value;
}

But I think it's better to store shared data in some sort of storage, 
for example redis or sql database.



More information about the Freeradius-Users mailing list