Skip to content
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

Check IsTerminal before SetRawTerminal #527

Closed

Conversation

coolljt0725
Copy link
Member

Do not set raw terminal if stdin is not a terminal.
or else it will show this error Container start failed: failed to set the terminal from the stdin: inappropriate ioctl for device and failed to start if we call runc not via a terminal

Signed-off-by: Lei Jitang leijitang@huawei.com

Do not set raw terminal if stdin is not a terminal

Signed-off-by: Lei Jitang <leijitang@huawei.com>
@duglin
Copy link

duglin commented Feb 1, 2016

Is there a testcase that shows the failure w/o the fix?

@crosbymichael
Copy link
Member

But do we want the error if the user specified TTY and we are unable to create one?

if err != nil {
return nil, fmt.Errorf("failed to set the terminal from the stdin: %v", err)
var state *term.State
if term.IsTerminal(os.Stdin.Fd()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, isn't the newTty create testing the same thing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashahab-altiscale No, it's different, create is whether to create a tty to container or not. create is true, but the stdin could not be a terminal.

@coolljt0725
Copy link
Member Author

@duglin This is a simple test

package main
import (
        "bytes"
        "fmt"
        "os/exec"
)
func main() {
        stdout := bytes.NewBuffer(nil)
        stderr := bytes.NewBuffer(nil)
        stdin := bytes.NewReader(nil)
        cmd := exec.Command("runc", "start", "-b", "/home/lei/containers/busybox")
        cmd.Stdout = stdout
        cmd.Stderr = stderr
        cmd.Stdin = stdin
        err := cmd.Start()
        if err != nil {
                fmt.Printf("failed to start; %v\n", err)
        }
        err = cmd.Wait()
        if err != nil {
                fmt.Printf("failed to wait: %v\n, stdout is: %v, stderr is: %v\n", err, stdout, stderr)
        }
}

This will show the error

go run runc.go 
failed to wait: exit status 1
, stdout is: time="2016-02-01T20:32:18-05:00" level=fatal msg="Container start failed: failed to set the terminal from the stdin: inappropriate ioctl for device" 
, stderr is: 

@duglin
Copy link

duglin commented Feb 2, 2016

can you add an integration test with that?

@duglin
Copy link

duglin commented Feb 2, 2016

oops - forget that - sorry, I thought this was in docker/docker :-)

@coolljt0725
Copy link
Member Author

@crosbymichael I think we should return the error if user specify tty but unable to create one

@crosbymichael
Copy link
Member

@coolljt0725 that is that the ioctl error was doing. if you guard it with this if IsTerminal then the user will not get an error.

@coolljt0725
Copy link
Member Author

@crosbymichael I just a bit of confused :-)
From what I understand, if term.IsTerminal(os.Stdin.Fd()) is just to block
SetRawTerminal if the input is not a terminal, it's not related to create tty.
the tty is create by NewConsole(rootuid). correct me if I'm wrong :-)

@crosbymichael
Copy link
Member

@coolljt0725 that call is going to work but it's still going to fail when you copy from os.Stdin to the pty master because its not set as raw terminal and you are going to get weird output.

@crosbymichael crosbymichael modified the milestone: 0.0.9 Feb 10, 2016
@crosbymichael crosbymichael modified the milestone: 0.0.9 Feb 18, 2016
@crosbymichael crosbymichael removed this from the 0.0.9 milestone Mar 10, 2016
@crosbymichael
Copy link
Member

Lets close this one for now as we rework the tty handling

@cyphar
Copy link
Member

cyphar commented Aug 24, 2016

For those reading at home, currently the tty handling reworking is happening in this branch (it's still a WIP and I'll open a PR once the code stops segfaulting): https://github.com/cyphar/runc/tree/console-rewrite.

@coolljt0725 coolljt0725 deleted the isterminal_first branch August 24, 2016 08:47
@coolljt0725
Copy link
Member Author

@cyphar 👍

stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
Add language for compliance requirements around platforms
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
So that the semantics of the tags are clear.

The platform/protocol disconnect is unfortunate.  "Protocol" was
chosen in de3f1af (Remove language around Solaris being optional as
it is covered in compliance language, 2016-08-17, opencontainers#527) because we may
have compliance subsets that aren't linked to platforms [1].  I'd be
open to renaming the JSON tag from platform:"..." -> protocol:"...",
but that's probably more change than it's worth.  The approach taken
in this commit, on the other hand, renames "protocol" to "platform".
I think that unnecessarily limits (or sets up confusing semantics for)
the platform/protocol values you can use, but two maintainers both
prefer "platform" [2,3].

[1]: opencontainers/runtime-spec#527 (comment)
[2]: opencontainers/runtime-spec#570 (comment)
[3]: opencontainers/runtime-spec#570 (comment)

Signed-off-by: W. Trevor King <wking@tremily.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants