From e589f678e1ed5efa8dd4450f37bee0486caa3504 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 3 Apr 2000 13:45:40 +0000 Subject: [PATCH] ChangeLog, gen_uuid.c: gen_uuid.c (get_random_bytes): Make more paranoid about misbehaving /dev/urandom. If we get a return of zero without an error more than 8 times in a row, we break out and return an error. Also, if /dev/urandom doesn't exist, try /dev/random. ChangeLog, ext2fs.h: ext2fs.h: Use AUTOCONF SIZEOF_* macros if available to determine how to define __s64 and __u64. Turn off "compression is experimental" warning if the cpp macro I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL is defined. --- lib/ext2fs/ChangeLog | 7 +++++++ lib/ext2fs/ext2fs.h | 16 +++++++++++++--- lib/uuid/ChangeLog | 8 ++++++++ lib/uuid/gen_uuid.c | 15 +++++++++++---- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 0653db8..92bfa82 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,10 @@ +2000-04-03 Theodore Ts'o + + * ext2fs.h: Use AUTOCONF SIZEOF_* macros if available to determine + how to define __s64 and __u64. Turn off "compression is + experimental" warning if the cpp macro + I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL is defined. + 2000-02-11 * ext2fs.h: Define EXT2FS_COMPRESSED_BLKADDR and HOLE_BLKADDR. diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 489fc50..5436ab2 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -45,12 +45,17 @@ #include "e2_types.h" #else #include -#if defined(__GNUC__) && defined(__STRICT_ANSI__) && \ - (((~0UL) == 0xffffffff) || defined(__i386__)) +#if !defined(__GNUC__) || defined(__STRICT_ANSI__) /* asm/types.h already defines __s64 and __u64 otherwise */ +#if SIZEOF_LONG == 8 +typedef __signed__ long __s64; +typedef unsigned long __u64; +#elif SIZEOF_LONG_LONG == 8 || \ + defined(__GNUC__) && (((~0UL) == 0xffffffff) || defined(__i386__)) typedef __signed__ long long __s64; typedef unsigned long long __u64; +#endif /* SIZEOF_LONG == 8 */ #endif -#endif +#endif /* EXT2_FLAT_INCLUDES */ typedef __u32 blk_t; typedef __u32 dgrp_t; @@ -485,7 +490,12 @@ struct ext2fs_sb { EXT3_FEATURE_COMPAT_HAS_JOURNAL) /* This #ifdef is temporary until compression is fully supported */ #ifdef ENABLE_COMPRESSION +#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL +/* If the below warning bugs you, then have + `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your + environment at configure time. */ #warning "Compression support is experimental" +#endif #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ EXT2_FEATURE_INCOMPAT_COMPRESSION) #else diff --git a/lib/uuid/ChangeLog b/lib/uuid/ChangeLog index 38e3149..c3944af 100644 --- a/lib/uuid/ChangeLog +++ b/lib/uuid/ChangeLog @@ -1,3 +1,11 @@ +2000-03-12 Theodore Ts'o + + * gen_uuid.c (get_random_bytes): Make more paranoid about + misbehaving /dev/urandom. If we get a return of zero + without an error more than 8 times in a row, we break out + and return an error. Also, if /dev/urandom doesn't exist, + try /dev/random. + 2000-01-18 Theodore Ts'o * Makefile.in: Since LIBUUID can sometimes include diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c index 0ed1a91..eb25bed 100644 --- a/lib/uuid/gen_uuid.c +++ b/lib/uuid/gen_uuid.c @@ -49,22 +49,29 @@ static void get_random_bytes(void *buf, int nbytes) { static int fd = -2; int i; + int lose_counter = 0; char *cp = (char *) buf; if (fd == -2) { fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) + fd = open("/dev/random", O_RDONLY); srand((getpid() << 16) ^ getuid() ^ time(0)); } if (fd >= 0) { while (nbytes > 0) { i = read(fd, cp, nbytes); - if (i < 0) { - if ((errno == EINTR) || (errno == EAGAIN)) - continue; - break; + if ((i < 0) && + ((errno == EINTR) || (errno == EAGAIN))) + continue; + if (i <= 0) { + if (lose_counter++ == 8) + break; + continue; } nbytes -= i; cp += i; + lose_counter = 0; } } if (nbytes == 0) -- 1.8.3.1