lxc exec outputs stderr on host's stdout
Bug #1522755 reported by
Martin Pitt
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxd (Ubuntu) |
Fix Released
|
Undecided
|
Stéphane Graber |
Bug Description
lxc exec does not maintain stdout and stderr from the guest command, but
seems to put everything on stdout:
$ sh -c 'echo stderr >&2' 2>/dev/null
$
$ lxc exec x1 -- sh -c 'echo stderr >&2' 2>/dev/null
stderr
$
In the second command, you should not see "stderr".
ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: lxd 0.23-0ubuntu3
ProcVersionSign
Uname: Linux 4.2.0-19-generic x86_64
ApportVersion: 2.19.2-0ubuntu8
Architecture: amd64
CurrentDesktop: Unity
Date: Fri Dec 4 10:38:50 2015
EcryptfsInUse: Yes
SourcePackage: lxd
UpgradeStatus: No upgrade log present (probably fresh install)
To post a comment you must log in.
So that's actually expected behavior though I'll add a flag to force non-interactive mode.
The way exec works is:
- If stdin is a tty, use interactive mode
- If stdin isn't a tty, use non-interactive mode
In interactive mode, a pts device is allocated and used for stdin, stdout and stderr, same as an interactive ssh session.
In non-interactive mode, a pipe is allocated for each of stdin, stdout and stderr, same as a non-interactive ssh session.
The difference comes from the fact that ssh does know how to differentiate a shell from another command. LXD doesn't as the command must always be specified.
So I'll be adding a new --mode option which takes either interactive or non-interactive and overrides the detection code.
In the mean time, doing the following should work:
lxc exec x1 -- sh -c 'echo stderr >&2' 2>/dev/null < /dev/null