-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/snap: proxy stdout when running app under strace #13501
cmd/snap: proxy stdout when running app under strace #13501
Conversation
cmd.Stdout = Stdout | ||
// note hijacking stdout, means it is no longer a tty and programs | ||
// expecting stdout to be on a terminal (eg. bash) may misbehave at this | ||
// point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should print a warning to stderr to make it clear that using --strace has this behavior, as it is a change from previous years explicitly meant to avoid a bug.
cmd/snap/cmd_run.go
Outdated
go func() { | ||
defer func() { filterDone <- true }() | ||
defer func() { close(filterDone) }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the func and just defer close(...)
cmd/snap/cmd_run.go
Outdated
@@ -1013,10 +1020,17 @@ func (x *cmdRun) runCmdUnderStrace(origCmd []string, envForExec envForExecFunc) | |||
} | |||
io.Copy(Stderr, r) | |||
}() | |||
|
|||
go func() { | |||
defer func() { close(stdoutProxyDone) }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on needless fuc
FYI filed sudo-project/sudo#349 |
Recent versions of sudo (1.9.14+) changed the terminal flags when switching to the child process which broke the output of some commands which had their output piped. This was addressed in the upstream in https://www.sudo.ws/repos/sudo/rev/faa06b1e8913 which added detection of whether a stdout is on a pipe, and thus preserved the terminal flags. In our case, when running a command under strace, we expect strace logs on stderr hence fd 2 is a pipe which isn't picked up by sudo auto detection, thus terminal flags are not being preserved and the output is garbled like so: [pid 838721] execve("/snap/hello-world/29/bin/echo", ["/snap/"...], ["DBUS_S"..., "DEBUGI"..., "DISPLA"..., "EDITOR"..., "HG=/us"..., "HOME=/"..., "INVOCA"..., "JOURNA"..., "KWIN_T"..., "LANG=e"..., "LC_MES"..., "LC_TIM"..., "LOGNAM"..., "MAIL=/"..., "MANAGE"..., "MEMORY"..., "MEMORY"..., "MOZ_EN"..., "MOZ_X1"..., "OLDPWD"..., "PAGER="..., "PATH=/"..., "PLASMA"..., "PWD=/h"..., "SHELL="..., "SHLVL="..., "SNAP=/"..., "SNAP_A"..., "SNAP_C"..., "SNAP_C"..., "SNAP_C"..., "SNAP_D"..., "SNAP_E"..., "SNAP_I"..., "SNAP_I"..., "SNAP_L"..., "SNAP_N"..., "SNAP_R"..., "SNAP_R"..., "SNAP_R"..., "SNAP_U"..., "SNAP_U"..., "SNAP_U"..., "SNAP_V"..., "SSH_AU"..., "SUDO_C"..., "SUDO_G"..., "SUDO_U"..., "SUDO_U"..., "SYSTEM"..., "TEMPDI"..., "TERM=t"..., "TERM_P"..., "TERM_P"..., "TMPDIR"..., "TMUX=/"..., "TMUX_P"..., "USER=r"..., "XAUTHO"..., "XDG_DA"..., "XDG_RU"..., "_=/usr"...] <unfinished ...> [pid 838725] <... futex resumed>) = ? [pid 838726] <... futex resumed>) = ? [pid 838727] <... futex resumed>) = ? [pid 838728] <... futex resumed>) = ? The patch makes stdout a pipe, which fixes the detection part. The obvious downside is that programs which now expect a tty on fd 1 will no longer work as expected. The issue is however limited to the cases when the app is running under strace. Signed-off-by: Maciej Borzecki <[email protected]>
…utput There are scenarios in which we are not processing the output of strace command, specifically when the user has passed `--raw`. The user can also redirect strace output to a file passing `-o` || `--output`, in which case processing is not possible either. In both scenarios it makes no sense to set up a pipe on stdout/stderr. Signed-off-by: Maciej Borzecki <[email protected]>
928f128
to
f64af84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good. It is unfortunate we have to work around bugs in sudo, as we won't be able to drop the workaround anytime soon, but the approach taken now is a good balance between doing the right thing and not looking broken for users/developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks
A bunch of unrelated failures in the tests. @pedronis @Meulengracht can you force merge? |
Recent versions of sudo (1.9.14+) changed the terminal flags when switching to the child process which broke the output of some commands which had their output piped. This was addressed in the upstream in
https://www.sudo.ws/repos/sudo/rev/faa06b1e8913 which added detection of whether a stdout is on a pipe, and thus preserved the terminal flags. In our case, when running a command under strace, we expect strace logs on stderr hence fd 2 is a pipe which isn't picked up by sudo auto detection, thus terminal flags are not being preserved and the output is garbled like so:
The patch makes stdout a pipe, which fixes the detection part. The obvious downside is that programs which now expect a tty on fd 1 will no longer work as expected. The issue is however limited to the cases when the app is running under strace.