public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: wysochanski@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2 ./WHATS_NEW lib/misc/lvm-wrappers.c lib/m ...
Date: Sun, 07 Dec 2008 04:23:00 -0000	[thread overview]
Message-ID: <20081207042338.19010.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2008-12-07 04:23:37

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-wrappers.c lvm-wrappers.h 
	lib/uuid       : uuid.c 

Log message:
	Add generic function to read /dev/urandom, used in uuid calculation.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1004&r2=1.1005
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-wrappers.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-wrappers.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/uuid/uuid.c.diff?cvsroot=lvm2&r1=1.28&r2=1.29

--- LVM2/WHATS_NEW	2008/12/04 15:54:26	1.1004
+++ LVM2/WHATS_NEW	2008/12/07 04:23:37	1.1005
@@ -1,5 +1,6 @@
 Version 2.02.44 - 
 ====================================
+  Add generic function to read /dev/urandom, used in uuid calculation.
   Use displayable_lvs_in_vg and lv_is_displayable for consistency throughout.
   Fix race in vgcreate that would result in second caller overwriting first.
   Fix uninitialised lv_count in vgdisplay -c.
--- LVM2/lib/misc/lvm-wrappers.c	2007/08/20 20:55:27	1.2
+++ LVM2/lib/misc/lvm-wrappers.c	2008/12/07 04:23:37	1.3
@@ -15,8 +15,34 @@
 #include "lib.h"
 
 #include <unistd.h>
+#include <fcntl.h>
 
 int lvm_getpagesize(void)
 {
 	return getpagesize();
 }
+
+int read_urandom(void *buf, size_t len)
+{
+	int fd;
+
+	/* FIXME: we should stat here, and handle other cases */
+	/* FIXME: use common _io() routine's open/read/close */
+	if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
+		log_sys_error("open", "read_urandom: /dev/urandom");
+		return 0;
+	}
+
+	if (read(fd, buf, len) != (ssize_t) len) {
+		log_sys_error("read", "read_urandom: /dev/urandom");
+		if (close(fd))
+			stack;
+		return 0;
+	}
+
+	if (close(fd))
+		stack;
+
+	return 1;
+}
+
--- LVM2/lib/misc/lvm-wrappers.h	2007/08/20 20:55:27	1.2
+++ LVM2/lib/misc/lvm-wrappers.h	2008/12/07 04:23:37	1.3
@@ -18,4 +18,9 @@
 
 int lvm_getpagesize(void);
 
+/*
+ * Read 'len' bytes of entropy from /dev/urandom and store in 'buf'.
+ */
+int read_urandom(void *buf, size_t len);
+
 #endif
--- LVM2/lib/uuid/uuid.c	2008/11/04 15:07:45	1.28
+++ LVM2/lib/uuid/uuid.c	2008/12/07 04:23:37	1.29
@@ -15,6 +15,7 @@
 
 #include "lib.h"
 #include "uuid.h"
+#include "lvm-wrappers.h"
 
 #include <assert.h>
 #include <sys/stat.h>
@@ -94,25 +95,14 @@
 
 int id_create(struct id *id)
 {
-	int randomfile;
 	unsigned i;
 	size_t len = sizeof(id->uuid);
 
 	memset(id->uuid, 0, len);
-	if ((randomfile = open("/dev/urandom", O_RDONLY)) < 0) {
-		log_sys_error("open", "id_create: /dev/urandom");
+	if (!read_urandom(&id->uuid, len)) {
 		return 0;
 	}
 
-	if (read(randomfile, id->uuid, len) != (ssize_t) len) {
-		log_sys_error("read", "id_create: /dev/urandom");
-		if (close(randomfile))
-			stack;
-		return 0;
-	}
-	if (close(randomfile))
-		stack;
-
 	/*
 	 * Skip out the last 2 chars in randomized creation for LVM1
 	 * backwards compatibility.


                 reply	other threads:[~2008-12-07  4:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20081207042338.19010.qmail@sourceware.org \
    --to=wysochanski@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).