Commit 7f3e12f3 by Stéphane Graber

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 2e74d6f3
...@@ -301,7 +301,7 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>]) ...@@ -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]) 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 # 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 # Check for some functions
AC_CHECK_LIB(util, openpty) AC_CHECK_LIB(util, openpty)
......
...@@ -288,7 +288,6 @@ static char *mkifname(char *template) ...@@ -288,7 +288,6 @@ static char *mkifname(char *template)
int i = 0; int i = 0;
FILE *urandom; FILE *urandom;
unsigned int seed; unsigned int seed;
char randstate[2048];
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int ifexists = 0; int ifexists = 0;
...@@ -304,7 +303,10 @@ static char *mkifname(char *template) ...@@ -304,7 +303,10 @@ static char *mkifname(char *template)
} }
else else
seed = time(0); 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 */ /* Generate random names until we find one that doesn't exist */
while(1) { while(1) {
...@@ -316,7 +318,11 @@ static char *mkifname(char *template) ...@@ -316,7 +318,11 @@ static char *mkifname(char *template)
for (i = 0; i < strlen(name); i++) { for (i = 0; i < strlen(name); i++) {
if (name[i] == 'X') { 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
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment