summaryrefslogtreecommitdiff
path: root/Assemble.c
diff options
context:
space:
mode:
authorJes Sorensen <Jes.Sorensen@redhat.com>2016-08-15 15:41:34 -0400
committerJes Sorensen <Jes.Sorensen@redhat.com>2016-08-15 15:41:34 -0400
commitc5f71c2417a53e097f6556e99027b7249d116a78 (patch)
treeb64dced365a9998f7953d5b95009213aff48c6f1 /Assemble.c
parent977d12d739deedd21ea3ca5a96d0ffd83bd5b4ea (diff)
downloadmdadm-c5f71c2417a53e097f6556e99027b7249d116a78.tar.gz
Introduce random_uuid() helper function
This gets rid of 5 nearly identical copies of the same code, and reduces the binary size of mdadm by over 700 bytes on x86_64. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Diffstat (limited to 'Assemble.c')
-rw-r--r--Assemble.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/Assemble.c b/Assemble.c
index d274e6e..3da0903 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -599,18 +599,9 @@ static int load_devices(struct devs *devices, char *devmap,
int err;
fstat(mdfd, &stb2);
- if (strcmp(c->update, "uuid")==0 &&
- !ident->uuid_set) {
- int rfd;
- if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
- read(rfd, ident->uuid, 16) != 16) {
- *(__u32*)(ident->uuid) = random();
- *(__u32*)(ident->uuid+1) = random();
- *(__u32*)(ident->uuid+2) = random();
- *(__u32*)(ident->uuid+3) = random();
- }
- if (rfd >= 0) close(rfd);
- }
+ if (strcmp(c->update, "uuid") == 0 && !ident->uuid_set)
+ random_uuid((__u8 *)ident->uuid);
+
dfd = dev_open(devname,
tmpdev->disposition == 'I'
? O_RDWR : (O_RDWR|O_EXCL));