-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Set initial console size based on process spec #1275
Conversation
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? |
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), |
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.
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).
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.
Yeh this seems reasonable. Have updated the PR - let me know if you think this is an appropriate solution. Thanks.
libcontainer/console_linux.go
Outdated
@@ -5,18 +5,23 @@ import ( | |||
"os" | |||
"syscall" | |||
"unsafe" | |||
|
|||
"github.com/docker/docker/pkg/term" |
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 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.
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.
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.
c6ceb09
to
b3f43f4
Compare
The build failed because of the flake fixed by: #1237
Can someone kick off again please. |
cc: @crosbymichael since it's on janky |
For future reference, anyone inside the |
@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? |
@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 |
When the caller of runc gets it |
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 |
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 |
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? |
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. |
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]
b3f43f4
to
c1f9411
Compare
@crosbymichael now that #1302 is resolved, do you have any thoughts on this? |
c1f9411
to
8cc84aa
Compare
8cc84aa
to
00d99ae
Compare
This PR is a little smaller after our most recent rebase now that runc uses a pty library. Does this change anything? Craig & @jszroberto |
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 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 | ||
} |
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.
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.
libcontainer/process.go
Outdated
@@ -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 |
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.
Since we have to use uint16
in the Resize
why not just make these uint16
in the first place?
tests/integration/tty.bats
Outdated
wait_for_container 15 1 test_busybox | ||
|
||
# make sure we're running | ||
testcontainer test_busybox running |
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 believe we've stopped using this pattern in tests (wait_for_container
and testcontainer
), but I might be mistaken.
tests/integration/tty.bats
Outdated
"args": [ | ||
"/bin/sh", | ||
"-c", | ||
"/bin/stty -a > $BATS_TMPDIR/tty-info" |
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.
$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.
tests/integration/tty.bats
Outdated
{ | ||
"args": [ | ||
"/bin/cat", | ||
"$BATS_TMPDIR/tty-info" |
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.
Same here.
tests/integration/tty.bats
Outdated
|
||
# clean process.jsons | ||
rm $BATS_TMPDIR/write-tty-info.json | ||
rm $BATS_TMPDIR/read-tty-info.json |
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.
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>
00d99ae
to
605dc5c
Compare
@crosbymichael We have made the suggested changes above, let us know what you think. Tom and @jszroberto |
LGTM Thanks @williammartin |
Set initial console size based on process spec LGTMs: @crosbymichael @cyphar Closes #1275
Thanks all |
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 theterm
package all the way up the stack, or the runtime-specBox
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 arunc exec
invocation callingstty -a
but there seems to be no convention for doing this and working around the existingrecvtty
infrastructure to allow these kind of tests seemed like a fairly sizable change, that might be best as its own PR.