[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Don't leak file descriptors

From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH] Don't leak file descriptors
Date: Tue, 17 Nov 2009 10:00:57 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20091014 Fedora/3.0-2.8.b4.fc11 Thunderbird/3.0b4

Am 17.11.2009 00:26, schrieb Anthony Liguori:
> Kevin Wolf wrote:
>> 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 <address@hidden>
>     pid = fork();
>     if (pid == 0) {
>         int open_max = sysconf(_SC_OPEN_MAX), i;
>         for (i = 0; i < open_max; i++) {
>             if (i != STDIN_FILENO &&
>                 i != STDOUT_FILENO &&
>                 i != STDERR_FILENO &&
>                 i != fd) {
>                 close(i);
>             }
> Handles this in a less invasive way.  I think the only problem we have 
> today is that we use popen() for exec: migration.  The solution to that 
> though should be to convert popen to a proper fork/exec() with a pipe.
> I'd prefer to introduce a single fork/exec helper that behaved properly 
> instead of having to deal with cloexec everywhere.

No, unfortunately this doesn't work because it requires knowledge of all
execs. However, the glibc people believe that they are free to fork/exec
whenever they want in any function. Actually, the bug report that led to
this fix was triggered by a hidden fork/exec in glibc. I'm not convinced
that it's right what they're doing, but it's the way it is.

If you like to read it up, you can use
https://bugzilla.redhat.com/show_bug.cgi?id=528134 as a starting point
and dig through the referenced bugs.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]