[lxc-devel] create_run_template() - question

Stéphane Graber stgraber at ubuntu.com
Sat Dec 14 17:12:38 UTC 2013


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20131214/2f4b7a64/attachment.pgp>


More information about the lxc-devel mailing list