]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: use access(2) when checking /dev/random availability
authorSami Kerola <kerolasa@iki.fi>
Sun, 30 Jul 2017 11:33:12 +0000 (12:33 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 5 Aug 2017 08:58:25 +0000 (09:58 +0100)
The access(2) is more lightwight than stat(2), and tells whether random
device(s) can be read or not, unlike the earlier stat() call.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
libuuid/src/gen_uuid.c

index 21e361293e8e6f47aea5ee252b826b22ded63765..7dafcaeedd8cca3d4505b397f3b778555d52075a 100644 (file)
@@ -534,9 +534,8 @@ void uuid_generate_random(uuid_t out)
  */
 static int have_random_source(void)
 {
-       struct stat s;
-
-       return (!stat("/dev/random", &s) || !stat("/dev/urandom", &s));
+       return (access("/dev/random", R_OK) == 0 ||
+               access("/dev/urandom", R_OK) == 0);
 }