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

Set initial console size based on process spec #1275

Merged

Conversation

williammartin
Copy link

Signed-off-by: Petar Petrov pppepito86@gmail.com

This commit hopefully resolves issue #1269, setting the initial console size for TTYs based on the ConsoleSize properties in the process spec.

Two thoughts about this PR that would be good to get feedback on: Firstly, the height and width are passed through as separate primitives and turned into a term.WinSize right before use. We weren't sure of the pros and cons of this approach vs the term package all the way up the stack, or the runtime-spec Box or even whether we should define another process config struct.

Secondly, the bats test would ideally read the master fd from the $CONSOLE_SOCKET and read output directly from a runc exec invocation calling stty -a but there seems to be no convention for doing this and working around the existing recvtty infrastructure to allow these kind of tests seemed like a fairly sizable change, that might be best as its own PR.

@williammartin
Copy link
Author

Looks like the build failed with some bad packaging. Can't see how this is anything to do with us - is it possible to kick off again?

@cyphar
Copy link
Member

cyphar commented Jan 17, 2017

I've re-kicked off the CI and the tests now pass.

utils_linux.go Outdated
@@ -81,6 +81,8 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) {
Label: p.SelinuxLabel,
NoNewPrivileges: &p.NoNewPrivileges,
AppArmorProfile: p.ApparmorProfile,
ConsoleWidth: uint16(p.ConsoleSize.Width),
ConsoleHeight: uint16(p.ConsoleSize.Height),
Copy link
Contributor

Choose a reason for hiding this comment

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

This will silently take the lowest 16 bits of the specified value, which could be confusing. I think it is better to pass and store as int everywhere and error on console creation if it is too big (in future other platforms could have different limits).

Copy link
Author

Choose a reason for hiding this comment

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

Yeh this seems reasonable. Have updated the PR - let me know if you think this is an appropriate solution. Thanks.

@@ -5,18 +5,23 @@ import (
"os"
"syscall"
"unsafe"

"github.com/docker/docker/pkg/term"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a requirement to not depend on docker/docker to avoid circular dependencies. May be betetr to copy the one function into this repo.

Copy link
Author

Choose a reason for hiding this comment

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

Yeh we wondered about this but thought we saw it elsewhere (maybe some legacy that was needing to be removed, or just a mistake). Have just done a little copying and refactoring in the updated PR.

@williammartin williammartin force-pushed the 1269-initial-console-sizing branch 2 times, most recently from c6ceb09 to b3f43f4 Compare January 26, 2017 13:48
@williammartin
Copy link
Author

The build failed because of the flake fixed by: #1237

container_linux.go:247: starting container process caused "process_linux.go:272: running exec setns process for init caused \"exit status 26\""

Can someone kick off again please.

@caniszczyk
Copy link
Contributor

cc: @crosbymichael since it's on janky

@cyphar
Copy link
Member

cyphar commented Jan 27, 2017

For future reference, anyone inside the #docker-maintainers channel can restart the Janky jobs using the message !rebuild runc#<pr number>.

@crosbymichael
Copy link
Member

@williammartin just wondering, why do you have to do a resize at this point in time? Why can't you resize after receiving the master pty?

@williammartin
Copy link
Author

williammartin commented Feb 4, 2017

@crosbymichael Just to be clear on your question, when you say "receiving the master pty", you mean when the caller of runc receives it on the --console-socket rather than when runc exec gets it from runc init?

@crosbymichael
Copy link
Member

When the caller of runc gets it

@williammartin
Copy link
Author

Well, it's intuitive that if this is specified in the runtime-spec, that the runtime should apply it before the process starts. More importantly, software that expects particular tty sizings should expect it to be set.

I'm wondering if part of the pain here is because exec doesn't have a create/start split i.e. right now the process might be finished by the time I receive the master pty. I'd need some way to let runc know "ok, I've set the tty size, carry on", which feels less intuitive and more complicated than this PR.

@crosbymichael
Copy link
Member

Well if your issue is with exec that is kinda a separate problem because consoles don't work at all right now because its too fast.

See #1302

@williammartin
Copy link
Author

williammartin commented Feb 7, 2017

While it's true that the console stuff is currently broken, it still seems intuitive that the runtime should set the specification for a caller before the process starts. Do you have some other thoughts on solving that or is your feeling that this should be punted until #1302 resolves in some manner?

@crosbymichael
Copy link
Member

Yes I agree that it should be set before the process starts. I think it would be better to solve this how I want to fix the race for the exec case, if we can block until we receive the pty master, resize it, then close that connection causing runc to start the process I think that is a better flow than having to provide console sizes through runc.

craigfurman pushed a commit to cloudfoundry/garden-runc-release that referenced this pull request Feb 7, 2017
To the branch await-prs-from-138131099 in the fork in
cloudfoundry-incubator. We can get back onto a released version of runc
when the following PRs are merged:

* opencontainers/runc#1237
* opencontainers/runc#1275

dadoo was the main guardian component that had to change here, to
accomodate changes in runc for processes that have TTYs.

[#138131099]
@craigfurman craigfurman force-pushed the 1269-initial-console-sizing branch from b3f43f4 to c1f9411 Compare April 20, 2017 10:59
@craigfurman
Copy link

@crosbymichael now that #1302 is resolved, do you have any thoughts on this?

@craigfurman craigfurman force-pushed the 1269-initial-console-sizing branch from c1f9411 to 8cc84aa Compare July 25, 2017 10:42
@karampok karampok force-pushed the 1269-initial-console-sizing branch from 8cc84aa to 00d99ae Compare September 26, 2017 13:56
@craigfurman
Copy link

This PR is a little smaller after our most recent rebase now that runc uses a pty library. Does this change anything?

Craig & @jszroberto

Copy link
Member

@cyphar cyphar left a comment

Choose a reason for hiding this comment

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

I think this might be able to solve moby/moby#25450 (at least partially). This looks alright (bar my comments that need to be addressed), but I'd like to know whether @crosbymichael is okay with this new version of the patch (I don't remember what it used to look like to be honest).

utils_linux.go Outdated
if p.ConsoleSize != nil {
consoleWidth = p.ConsoleSize.Width
consoleHeight = p.ConsoleSize.Height
}
Copy link
Member

Choose a reason for hiding this comment

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

The defaults of 0 don't make sense given that you unconditionally set the console size when creating it. I don't know what the kernel will do when you tell it to resize a console to 0x0, but from my quick reading I expect that it isn't a no-op.

@@ -47,6 +47,10 @@ type Process struct {
// ExtraFiles specifies additional open files to be inherited by the container
ExtraFiles []*os.File

// Initial sizings for the console
ConsoleWidth uint
ConsoleHeight uint
Copy link
Member

Choose a reason for hiding this comment

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

Since we have to use uint16 in the Resize why not just make these uint16 in the first place?

wait_for_container 15 1 test_busybox

# make sure we're running
testcontainer test_busybox running
Copy link
Member

Choose a reason for hiding this comment

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

I believe we've stopped using this pattern in tests (wait_for_container and testcontainer), but I might be mistaken.

"args": [
"/bin/sh",
"-c",
"/bin/stty -a > $BATS_TMPDIR/tty-info"
Copy link
Member

Choose a reason for hiding this comment

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

$BATS_TMPDIR is on the host not in the container. Since it's generally /tmp this won't cause obvious issues, but just use /tmp inside the container.

{
"args": [
"/bin/cat",
"$BATS_TMPDIR/tty-info"
Copy link
Member

Choose a reason for hiding this comment

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

Same here.


# clean process.jsons
rm $BATS_TMPDIR/write-tty-info.json
rm $BATS_TMPDIR/read-tty-info.json
Copy link
Member

Choose a reason for hiding this comment

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

Also you could use process substitution to remove the need for temporary files, but that's not really a big issue.

Signed-off-by: Will Martin <wmartin@pivotal.io>
Signed-off-by: Petar Petrov <pppepito86@gmail.com>
Signed-off-by: Ed King <eking@pivotal.io>
Signed-off-by: Roberto Jimenez Sanchez <jszroberto@gmail.com>
Signed-off-by: Thomas Godkin <tgodkin@pivotal.io>
@BooleanCat BooleanCat force-pushed the 1269-initial-console-sizing branch from 00d99ae to 605dc5c Compare October 4, 2017 13:28
@BooleanCat
Copy link

@crosbymichael We have made the suggested changes above, let us know what you think.

Tom and @jszroberto

@crosbymichael
Copy link
Member

crosbymichael commented Oct 4, 2017

LGTM

Thanks @williammartin

Approved with PullApprove

@cyphar
Copy link
Member

cyphar commented Oct 4, 2017

LGTM. Thanks all.

Approved with PullApprove

@cyphar cyphar merged commit 605dc5c into opencontainers:master Oct 4, 2017
cyphar added a commit that referenced this pull request Oct 4, 2017
  Set initial console size based on process spec

LGTMs: @crosbymichael @cyphar
Closes #1275
@williammartin
Copy link
Author

Thanks all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants