share variables in perl script (rlm_perl)

laurent.feron at free.fr laurent.feron at free.fr
Tue Dec 4 15:30:14 CET 2012


Hello, thanks for your respond. I tried memcached as suggested by John Denins. Seems working very well.
i thought of Redis, if memcached does not satisfied me (i don't see), Redis could be an option.
In term of security, i have to be sure that information in memcached can be secured, and not public.
Regards,
Laurent

----- Mail original -----
De: "Iliya Peregoudov" <iperegudov at cboss.ru>
À: "FreeRadius users mailing list" <freeradius-users at lists.freeradius.org>
Envoyé: Mardi 4 Décembre 2012 08:14:13
Objet: Re: share variables in perl script (rlm_perl)

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.

-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


More information about the Freeradius-Users mailing list