aboutsummaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2009-12-02 12:24:42 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-12-03 11:45:50 -0600
commit40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4 (patch)
tree98d560a0de229f27a66f637cfcadbb1672e68cc3 /vl.c
parent12c09b8ce22d74f78ff50f95676cbe4f501752ae (diff)
Don't leak file descriptors
We're leaking file descriptors to child processes. Set FD_CLOEXEC on file descriptors that don't need to be passed to children to stop this misbehaviour. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/vl.c b/vl.c
index 0816ed7012..d6f196cff5 100644
--- a/vl.c
+++ b/vl.c
@@ -1243,7 +1243,7 @@ static int hpet_start_timer(struct qemu_alarm_timer *t)
struct hpet_info info;
int r, fd;
- fd = open("/dev/hpet", O_RDONLY);
+ fd = qemu_open("/dev/hpet", O_RDONLY);
if (fd < 0)
return -1;
@@ -1292,7 +1292,7 @@ static int rtc_start_timer(struct qemu_alarm_timer *t)
int rtc_fd;
unsigned long current_rtc_freq = 0;
- TFR(rtc_fd = open("/dev/rtc", O_RDONLY));
+ TFR(rtc_fd = qemu_open("/dev/rtc", O_RDONLY));
if (rtc_fd < 0)
return -1;
ioctl(rtc_fd, RTC_IRQP_READ, &current_rtc_freq);
@@ -3337,7 +3337,7 @@ static int qemu_event_init(void)
int err;
int fds[2];
- err = pipe(fds);
+ err = qemu_pipe(fds);
if (err == -1)
return -errno;
@@ -5507,6 +5507,9 @@ int main(int argc, char **argv, char **envp)
} else if (pid < 0)
exit(1);
+ close(fds[0]);
+ qemu_set_cloexec(fds[1]);
+
setsid();
pid = fork();
@@ -5907,7 +5910,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
chdir("/");
- TFR(fd = open("/dev/null", O_RDWR));
+ TFR(fd = qemu_open("/dev/null", O_RDWR));
if (fd == -1)
exit(1);
}