[lvm-devel] [PATCH 1/2] Add generic function to read /dev/urandom, used in uuid calculation.
Alasdair G Kergon
agk at redhat.com
Sat Dec 6 17:04:40 UTC 2008
On Sat, Dec 06, 2008 at 11:12:45AM -0500, Dave Wysochanski wrote:
> --- a/lib/Makefile.in
> +++ b/lib/Makefile.in
> @@ -80,6 +80,7 @@ SOURCES =\
> misc/lvm-globals.c \
> misc/lvm-string.c \
> misc/lvm-wrappers.c \
> + misc/random.c \
> misc/timestamp.c \
> misc/util.c \
For the newer files I've been using an lvm- prefix.
But rather than adding a new file, just add it to either lvm-file.c
(it's doing file manipulation) or lvm-wrappers.c (it's wrapping
a random number generating function).
> + if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
> + log_sys_error("open", "get_random: /dev/urandom");
> + return 0;
> + }
(strictly we should stat it first and have a fallback if it doesn't exist -
a FIXME to suggest that? Not worth coding though till someone actually needs it.)
> + if (read(fd, buf, len) != (ssize_t) len) {
> + log_sys_error("read", "get_random: /dev/urandom");
> + if (close(fd))
> + stack;
> + return 0;
> + }
Again, a FIXME to handle the standard complexity of read()?
(Ideally we'd push this through the existing _io() function instead of having
another less-well-implemented open...read...close sequence.)
Alasdair
--
agk at redhat.com
More information about the lvm-devel
mailing list