lxc exec outputs stderr on host's stdout

Bug #1522755 reported by Martin Pitt
12
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
ProcVersionSignature: Ubuntu 4.2.0-19.23-generic 4.2.6
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)

Revision history for this message
Martin Pitt (pitti) wrote :
tags: added: autopkgtest
Revision history for this message
Stéphane Graber (stgraber) wrote :

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

Revision history for this message
Stéphane Graber (stgraber) wrote :

I wrote a patch for the new --mode argument which I'll be submitting upstream very soon (want to bundle the other exec fix).

Changed in lxd (Ubuntu):
status: New → In Progress
assignee: nobody → Stéphane Graber (stgraber)
Revision history for this message
Stéphane Graber (stgraber) wrote :

I just sent the --mode change upstream: https://github.com/lxc/lxd/pull/1383

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package lxd - 0.24-0ubuntu2

---------------
lxd (0.24-0ubuntu2) xenial; urgency=medium

  * Cherry-pick the following upstream bugfixes: (LP: #1522755)
    - 0001-Introduce-a-new-mode-option-to-exec.patch
    - 0002-remove-extra-debugging-statement.patch
    - 0003-generate-a-better-error-message-for-legacy-image-imp.patch
    - 0004-hide-lxc-importer-from-help-output.patch
    - 0005-tests-Avoid-device-conflicts.patch
    - 0006-Use-the-mountpoint-command-when-available.patch
    - 0007-tests-Fix-mount-issues.patch
    - 0008-Apparently-IsMountPoint-is-never-very-reliable-with-.patch
  * Set wait timeout to 10 minutes in lxd job. This should be long
    enough for even the slowest hardware to generate a SSL key.
  * Update debian/rules to make it easier to flip between building with
    the embedded dependencies or not.

 -- Stéphane Graber <email address hidden> Wed, 09 Dec 2015 16:46:41 -0500

Changed in lxd (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.