On Thu, Jun 16, 2011 at 03:59:37PM +0200, Ludwig Nussel wrote: > uuid_generate_random_safe() cannot really fail but it may use a weak > random number generator as fallback. > --- > libuuid/src/gen_uuid.c | 32 +++++++++++++++++++++++++++++--- > libuuid/src/uuid.h | 4 +++- > libuuid/src/uuid.sym | 2 ++ > misc-utils/uuidgen.c | 10 ++++++++-- > 4 files changed, 42 insertions(+), 6 deletions(-) > > diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c > index f4c8997..0c81a5c 100644 > --- a/libuuid/src/gen_uuid.c > +++ b/libuuid/src/gen_uuid.c > @@ -693,6 +693,18 @@ void uuid_generate_random(uuid_t out) > __uuid_generate_random(out, &num); > } > > +int uuid_generate_random_safe(uuid_t out) > +{ > + int num = 1; > + /* No real reason to use the daemon for random uuid's -- yet */ > + > + if (get_random_fd() < 0) > + return -1; > + > + __uuid_generate_random(out, &num); > + return 0; > +} > + It would be nice to use the same concept for the *_random functions as we already use for the *_time functions. It means to rename __uuid_generate_random() to uuid_generate_random_generic(). > /* > * This is the generic front-end to uuid_generate_random and > @@ -700,10 +712,24 @@ void uuid_generate_random(uuid_t out) > * /dev/urandom is available, since otherwise we won't have > * high-quality randomness. > */ > -void uuid_generate(uuid_t out) > +static int _uuid_generate(uuid_t out) rename to: static int uuid_generate_genetic() > +void uuid_generate(uuid_t out) > +{ > + (void)_uuid_generate(out); Don't use "(void)" in the code :-) It's unnecessary. > +int uuid_generate_time_safe(uuid_t out) __attribute__((warn_unused_result)); > +int uuid_generate_random_safe(uuid_t out) __attribute__((warn_unused_result)); > +int uuid_generate_safe(uuid_t out) __attribute__((warn_unused_result)); Good idea, but is warn_unused_result supported in old gcc versions? See include/c.h where we have __GNUC_PREREQ stuff. Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html