[lxc-devel] [PATCH 11/17] Use srand/rand instead of initstate/random

Serge Hallyn serge.hallyn at ubuntu.com
Fri Aug 16 15:36:58 UTC 2013


Quoting Stéphane Graber (stgraber at ubuntu.com):
> initstate/random doesn't work on bionic, srand/rand works on everything,
> so let's use that.

Is rand_r available on bionic?

rand() isn't thread-safe.

> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
>  src/lxc/conf.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 867a150..3d99469 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -288,7 +288,6 @@ static char *mkifname(char *template)
>  	int i = 0;
>  	FILE *urandom;
>  	unsigned int seed;
> -	char randstate[2048];
>  	struct ifaddrs *ifaddr, *ifa;
>  	int ifexists = 0;
>  
> @@ -304,7 +303,7 @@ static char *mkifname(char *template)
>  	}
>  	else
>  		seed = time(0);
> -	initstate(seed, randstate, 256);
> +	srand(seed);
>  
>  	/* Generate random names until we find one that doesn't exist */
>  	while(1) {
> @@ -316,7 +315,7 @@ static char *mkifname(char *template)
>  
>  		for (i = 0; i < strlen(name); i++) {
>  			if (name[i] == 'X') {
> -				name[i] = padchar[random() % (strlen(padchar) - 1)];
> +				name[i] = padchar[rand() % (strlen(padchar) - 1)];
>  			}
>  		}
>  
> -- 
> 1.8.3.2
> 
> 
> ------------------------------------------------------------------------------
> Get 100% visibility into Java/.NET code with AppDynamics Lite!
> It's a free troubleshooting tool designed for production.
> Get down to code-level detail for bottlenecks, with <2% overhead. 
> Download for free and get started troubleshooting in minutes. 
> http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel




More information about the lxc-devel mailing list