Make sure to seed the random number generator for uuids

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
This commit is contained in:
Neil Brown 2005-06-07 23:03:48 +00:00
parent 892debc820
commit dfe47e008e
3 changed files with 22 additions and 8 deletions

View File

@ -93,6 +93,8 @@ int main(int argc, char *argv[])
int mdfd = -1;
srandom(time(0) ^ getpid());
ident.uuid_set=0;
ident.level = UnSet;
ident.raid_disks = UnSet;

View File

@ -326,6 +326,7 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
{
mdp_super_t *sb = malloc(MD_SB_BYTES);
int spares;
int rfd;
memset(sb, 0, MD_SB_BYTES);
if (info->major_version == -1) {
@ -340,12 +341,14 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
return 0;
}
rfd = open("/dev/urandom", O_RDONLY);
sb->md_magic = MD_SB_MAGIC;
sb->major_version = 0;
sb->minor_version = 90;
sb->patch_version = 0;
sb->gvalid_words = 0; /* ignored */
sb->set_uuid0 = random();
if (rfd < 0 || read(rfd, &sb->set_uuid0, 4) != 4)
sb->set_uuid0 = random();
sb->ctime = time(0);
sb->level = info->level;
sb->size = info->size;
@ -353,9 +356,13 @@ static int init_super0(void **sbp, mdu_array_info_t *info)
sb->raid_disks = info->raid_disks;
sb->md_minor = info->md_minor;
sb->not_persistent = 0;
sb->set_uuid1 = random();
sb->set_uuid2 = random();
sb->set_uuid3 = random();
if (rfd < 0 || read(rfd, &sb->set_uuid1, 12) != 12) {
sb->set_uuid1 = random();
sb->set_uuid2 = random();
sb->set_uuid3 = random();
}
if (rfd >= 0)
close(rfd);
sb->utime = sb->ctime;
sb->state = info->state;

View File

@ -466,6 +466,7 @@ static int write_init_super1(struct supertype *st, void *sbv, mdu_disk_info_t *d
struct mdp_superblock_1 *sb = sbv;
struct mdp_superblock_1 *refsb = NULL;
int fd = open(devname, O_RDWR | O_EXCL);
int rfd;
int rv;
long size;
@ -480,10 +481,14 @@ static int write_init_super1(struct supertype *st, void *sbv, mdu_disk_info_t *d
sb->dev_number = __cpu_to_le32(dinfo->number);
*(__u32*)(sb->device_uuid) = random();
*(__u32*)(sb->device_uuid+4) = random();
*(__u32*)(sb->device_uuid+8) = random();
*(__u32*)(sb->device_uuid+12) = random();
if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
read(rfd, sb->device_uuid, 16) != 16) {
*(__u32*)(sb->device_uuid) = random();
*(__u32*)(sb->device_uuid+4) = random();
*(__u32*)(sb->device_uuid+8) = random();
*(__u32*)(sb->device_uuid+12) = random();
}
if (rfd >= 0) close(rfd);
sb->events = 0;
if (load_super1(st, fd, (void**)&refsb, NULL)==0) {