-
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
*: Avoid creation panics when 'process' and 'linux' are unset #1726
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f2628a7
utils_linux: Avoid panic when process is unset
wking e32d0d9
libcontainer/specconv/spec_linux: Avoid panic when Process is unset
wking ed4b83c
libcontainer/specconv/spec_linux: Avoid panic when Linux is unset
wking 0cd9a7e
libcontainer/standard_init_linux: Move LookPath to post-wait
wking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,10 @@ func getDefaultImagePath(context *cli.Context) string { | |
|
||
// newProcess returns a new libcontainer Process with the arguments from the | ||
// spec and stdio from the current process. | ||
func newProcess(p specs.Process) (*libcontainer.Process, error) { | ||
func newProcess(p *specs.Process) (*libcontainer.Process, error) { | ||
if p == nil { | ||
return &libcontainer.Process{}, nil | ||
} | ||
lp := &libcontainer.Process{ | ||
Args: p.Args, | ||
Env: p.Env, | ||
|
@@ -261,7 +264,7 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
r.destroy() | ||
return -1, err | ||
} | ||
process, err := newProcess(*config) | ||
process, err := newProcess(config) | ||
if err != nil { | ||
r.destroy() | ||
return -1, err | ||
|
@@ -291,7 +294,8 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
// with detaching containers, and then we get a tty after the container has | ||
// started. | ||
handler := newSignalHandler(r.enableSubreaper, r.notifySocket) | ||
tty, err := setupIO(process, rootuid, rootgid, config.Terminal, detach, r.consoleSocket) | ||
terminal := config != nil && config.Terminal | ||
tty, err := setupIO(process, rootuid, rootgid, terminal, detach, r.consoleSocket) | ||
if err != nil { | ||
r.destroy() | ||
return -1, err | ||
|
@@ -353,17 +357,21 @@ func (r *runner) terminate(p *libcontainer.Process) { | |
|
||
func (r *runner) checkTerminal(config *specs.Process) error { | ||
detach := r.detach || (r.action == CT_ACT_CREATE) | ||
terminal := config != nil && config.Terminal | ||
// Check command-line for sanity. | ||
if detach && config.Terminal && r.consoleSocket == "" { | ||
if detach && terminal && r.consoleSocket == "" { | ||
return fmt.Errorf("cannot allocate tty if runc will detach without setting console socket") | ||
} | ||
if (!detach || !config.Terminal) && r.consoleSocket != "" { | ||
if (!detach || !terminal) && r.consoleSocket != "" { | ||
return fmt.Errorf("cannot use console socket if runc will not detach or allocate tty") | ||
} | ||
return nil | ||
} | ||
|
||
func validateProcessSpec(spec *specs.Process) error { | ||
if spec == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be an error case |
||
return nil | ||
} | ||
if spec.Cwd == "" { | ||
return fmt.Errorf("Cwd property must not be empty") | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We want to validate this on creation not after we have done all this work. Change the above code to if process == nil error out
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.
In other words, there is no reason to do 90% of container creation if we get to the end and we cannot run the container because process == nil
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 point of this PR is allowing
create
for containers with noprocess
(catching up with opencontainers/runtime-spec#701). You can'tstart
those containers, which is why we have this check here, but we certainly don't want to error those out duringcreate
.