summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2006-01-06 18:10:02 -0500
committerTheodore Ts'o <tytso@mit.edu>2006-01-06 18:10:02 -0500
commit2adc320f01906cce0b55fa7bc9fccb24b5640cee (patch)
tree51d9c18a0b964138ddf418b4ae82582392fd6d9d
parent22fe674da4bdec2ff1c1abb7ad074df3a641377b (diff)
downloade2fsprogs-2adc320f01906cce0b55fa7bc9fccb24b5640cee.tar.gz
Set FD_CLOEXEC on the /dev/random file descriptor used by libuuid
This avoids a fd leak across an execve() which was causing problems for the LVM tools. (Addresses Debian Bug: #345832) Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--lib/uuid/ChangeLog6
-rw-r--r--lib/uuid/gen_uuid.c5
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/uuid/ChangeLog b/lib/uuid/ChangeLog
index 26a96993..1a1a9e8a 100644
--- a/lib/uuid/ChangeLog
+++ b/lib/uuid/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-06 Theodore Ts'o <tytso@mit.edu>
+
+ * gen_uuid.c (get_random_fd): Set the FD_CLOEXEC flag on the file
+ descriptor so that it will get closed across an execve().
+ (Addresses Debian Bug #345832)
+
2005-12-10 Theodore Ts'o <tytso@mit.edu>
* Makefile.in: Add a dependency to make sure that the
diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 42942aa5..421314a0 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -88,6 +88,11 @@ static int get_random_fd(void)
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
+ if (fd >= 0) {
+ i = fcntl(fd, F_GETFD);
+ if (i >= 0)
+ fcntl(fd, F_SETFD, i | FD_CLOEXEC);
+ }
srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
}
/* Crank the random number generator a few times */