[Libvir] [patch 1/3] Add UUID generation to qemud

Richard W.M. Jones rjones at redhat.com
Mon Feb 26 14:49:18 UTC 2007


Mark McLoughlin wrote:

> +static int
> +qemudGenerateRandomBytes(unsigned char *buf,
> +                         int buflen)
> +{
> +    int fd;
> +
> +    if ((fd = open("/dev/urandom", O_RDONLY)) < 0)
> +        return errno;
> +
> +    while (buflen > 0) {
> +        int n;
> +
> +        if ((n = read(fd, buf, buflen)) <= 0) {
> +            if (errno == EINTR)
> +                continue;
> +            close(fd);
> +            return n < 0 ? errno : ENODATA;
> +        }
> +
> +        buf += n;
> +        buflen -= n;
> +    }
> +
> +    close(fd);
> +
> +    return 0;
> +}

This function would actually be quite useful as a generally available 
function.  In the remote patch I have added the following to configure.in:

dnl /dev/urandom
AC_CHECK_FILES([/dev/urandom])

and then in C code I can write:

#if HAVE__DEV_URANDOM      /* NB double underscore */
  // random blah blah
#else
  // pseudorandom blah blah
#endif

Rich.

-- 
Emerging Technologies, Red Hat  http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF     Mobile: +44 7866 314 421
  "[Negative numbers] darken the very whole doctrines of the equations
  and make dark of the things which are in their nature excessively
  obvious and simple" (Francis Maseres FRS, mathematician, 1759)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070226/a46abf92/attachment-0001.bin>


More information about the libvir-list mailing list