mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
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>
This commit is contained in:
parent
12c09b8ce2
commit
40ff6d7e8d
20 changed files with 178 additions and 34 deletions
11
vl.c
11
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, ¤t_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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue