From: Karel Zak <kzak@redhat.com>
To: Ludwig Nussel <ludwig.nussel@suse.de>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 2/4] uuid: implement uuid_generate_random_safe
Date: Thu, 16 Jun 2011 17:54:00 +0200 [thread overview]
Message-ID: <20110616155400.GB5352@nb.redhat.com> (raw)
In-Reply-To: <1308232779-21018-2-git-send-email-ludwig.nussel@suse.de>
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@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2011-06-16 15:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-16 13:59 [PATCH 1/4] uuidgen: fail if uuidd isn't running Ludwig Nussel
2011-06-16 13:59 ` [PATCH 2/4] uuid: implement uuid_generate_random_safe Ludwig Nussel
2011-06-16 15:54 ` Karel Zak [this message]
2011-06-17 2:15 ` Ted Ts'o
2011-06-17 7:37 ` Ludwig Nussel
2011-06-20 11:45 ` Theodore Tso
2011-06-16 13:59 ` [PATCH 3/4] uuid: use new functions by default Ludwig Nussel
2011-06-20 10:35 ` Karel Zak
2011-06-16 13:59 ` [PATCH 4/4] update manpage Ludwig Nussel
2011-06-16 15:38 ` [PATCH 1/4] uuidgen: fail if uuidd isn't running Karel Zak
2011-06-17 2:07 ` Ted Ts'o
2011-06-20 10:45 ` Karel Zak
2011-06-20 12:18 ` Ludwig Nussel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110616155400.GB5352@nb.redhat.com \
--to=kzak@redhat.com \
--cc=ludwig.nussel@suse.de \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox