Use srand/rand instead of initstate/random

initstate/random doesn't work on bionic, srand/rand works on everything,
so let's use that.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2013-08-16 15:22:28 +02:00
parent 2e74d6f374
commit 7f3e12f3e5
2 changed files with 10 additions and 4 deletions

View File

@ -301,7 +301,7 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>])
AC_CHECK_HEADERS([sys/signalfd.h pty.h ifaddrs.h sys/capability.h sys/personality.h utmpx.h sys/timerfd.h])
# Check for some syscalls functions
AC_CHECK_FUNCS([setns pivot_root sethostname unshare])
AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r])
# Check for some functions
AC_CHECK_LIB(util, openpty)

View File

@ -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,10 @@ static char *mkifname(char *template)
}
else
seed = time(0);
initstate(seed, randstate, 256);
#ifndef HAVE_RAND_R
srand(seed);
#endif
/* Generate random names until we find one that doesn't exist */
while(1) {
@ -316,7 +318,11 @@ static char *mkifname(char *template)
for (i = 0; i < strlen(name); i++) {
if (name[i] == 'X') {
name[i] = padchar[random() % (strlen(padchar) - 1)];
#ifdef HAVE_RAND_R
name[i] = padchar[rand_r(&seed) % (strlen(padchar) - 1)];
#else
name[i] = padchar[rand() % (strlen(padchar) - 1)];
#endif
}
}