Re: [patch 7/9] Fix our FD_CLOEXEC usage

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

 



Mark McLoughlin <markmc@xxxxxxxxxx> wrote:

> Implement a sane policy around our use of FD_CLOEXEC:
>
>   1) Every descriptor which shouldn't be passed to
>      child processes should have the flag set
>
>   2) Let exec() do the descriptor closing, rather
>      than us doing it ourselves
...
> -        for (i = 0; i < open_max; i++) {
> -            if (i != STDOUT_FILENO &&
> -                i != STDERR_FILENO &&
> -                i != STDIN_FILENO)
> -                close(i);
> -        else if (errors == NO_ERRORS)
> -            dup2(null, i);
> +        if (errors == NO_ERRORS) {
> +            dup2(null, STDIN_FILENO);
> +            dup2(null, STDOUT_FILENO);
> +            dup2(null, STDERR_FILENO);
> +            close(null);
>          }

True, dup2 failure wasn't checked before either,
but it *can* fail.  Best to diagnose it, just in case.


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]