[lxc-devel] create_run_template() - question

Kevin Wilson wkevils at gmail.com
Sat Dec 14 17:30:25 UTC 2013


Hi,
Thanks!

Kevin

On Sat, Dec 14, 2013 at 7:12 PM, Stéphane Graber <stgraber at ubuntu.com> wrote:
> On Sat, Dec 14, 2013 at 12:04:24PM +0200, Kevin Wilson wrote:
>> Hello,
>> Could anybody please explain:
>> In  create_run_template() ,
>> https://github.com/lxc/lxc/blob/master/src/lxc/lxccontainer.c
>>
>> we have:
>>
>>  if (quiet) {
>>                         close(0);
>>                         close(1);
>>                         close(2);
>>                         open("/dev/zero", O_RDONLY);
>>                         open("/dev/null", O_RDWR);
>>                         open("/dev/null", O_RDWR);
>>                 }
>>
>> Why do we need twice to call  open("/dev/null", O_RDWR) ? Is it have
>> to do with running as daemon ? or is it redundant ?
>> We don't use the returned fd in both cases.
>>
>> Kevin
>
> The code above closes the 3 standard fds:
>  - 0 => stdin
>  - 1 => stdout
>  - 2 => stderr
>
> And then re-opens them with correct values to hide any output from the
> script.
>
> So that line isn't redundant at all, if it was missing, I'd expect the
> code to crash when something would try to write to stderr.
>
> --
> Stéphane Graber
> Ubuntu developer
> http://www.ubuntu.com
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
>


More information about the lxc-devel mailing list