[libvirt] PATCH 1/4: More generic MAC address handling

Jim Meyering jim at meyering.net
Tue Oct 21 13:05:14 UTC 2008


"Daniel P. Berrange" <berrange at redhat.com> wrote:
...
>> Also, unless there's a guarantee that the random number state is
>> initialized elsewhere, it should be initialized here, like it was in
>> the now-removed xenXMAutoAssignMac function.
>>
>>        srand((unsigned)time(NULL));
>>
>> Or maybe just initialize it once at start-up?
>
> Could just add a call to srand() in virInitialize() i guess, although is
> that a reasonable thing for a shared library to be doing, rather than
> leaving it upto the application ?

You're right that it's not reasonable to call srand from library code.
One alternative is to use something like coreutils' gnulib-style randint
module.  I'm looking into whether we can relax it's GPL license to LGPLv2+.
Using it or any other library-safe random_r-like interface would mean
maintaining and reusing an internal-to-libvirt random state buffer.




More information about the libvir-list mailing list