aboutsummaryrefslogtreecommitdiff
path: root/backends/rng-random.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-12-20 23:21:06 +0100
committerLuiz Capitulino <lcapitulino@redhat.com>2014-01-06 13:45:46 -0500
commit513b8c74c4c899cd940a79131e76c5568aa11381 (patch)
tree18f3615a938cf8aad4ce06b9dc9ab35d8af0d07a /backends/rng-random.c
parentabf233294bc8a4d2c7d5f428f1408d7bdd0c02e0 (diff)
rng: initialize file descriptor to -1
The file descriptor is never initialized to -1, which makes rng-random close stdin if an object is created and immediately destroyed. If we change it to -1, we also need to protect qemu_set_fd_handler from receiving a bogus file descriptor. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Tested-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'backends/rng-random.c')
-rw-r--r--backends/rng-random.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 68dfc8a9c6..136499d305 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -123,15 +123,15 @@ static void rng_random_init(Object *obj)
NULL);
s->filename = g_strdup("/dev/random");
+ s->fd = -1;
}
static void rng_random_finalize(Object *obj)
{
RndRandom *s = RNG_RANDOM(obj);
- qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
-
if (s->fd != -1) {
+ qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
qemu_close(s->fd);
}