namespaces: send config, network state and other arguments in one packet

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin
2015-01-28 12:11:19 +03:00
parent ca633b2f29
commit df52d63854
2 changed files with 20 additions and 44 deletions
+10 -27
View File
@@ -68,18 +68,8 @@ func executeSetupCmd(args []string, ppid int, container *configs.Config, process
return terr
}
encoder := json.NewEncoder(parent)
if err := encoder.Encode(container); err != nil {
return terminate(err)
}
if err := encoder.Encode(process); err != nil {
return terminate(err)
}
// send the state to the container's init process then shutdown writes for the parent
if err := encoder.Encode(networkState); err != nil {
if err := json.NewEncoder(parent).Encode(process); err != nil {
return terminate(err)
}
@@ -158,21 +148,6 @@ func Exec(args []string, env []string, console string, command *exec.Cmd, contai
return terr
}
encoder := json.NewEncoder(parent)
if err := encoder.Encode(container); err != nil {
return terminate(err)
}
process := processArgs{
Env: append(env[0:], container.Env...),
Args: args,
ConsolePath: console,
}
if err := encoder.Encode(process); err != nil {
return terminate(err)
}
started, err := system.GetProcessStartTime(command.Process.Pid)
if err != nil {
return terminate(err)
@@ -195,6 +170,14 @@ func Exec(args []string, env []string, console string, command *exec.Cmd, contai
return terminate(err)
}
process := processArgs{
Env: append(env[0:], container.Env...),
Args: args,
ConsolePath: console,
Config: container,
NetworkState: &networkState,
}
// Start the setup process to setup the init process
if container.Namespaces.Contains(configs.NEWUSER) {
if err = executeSetupCmd(command.Args, command.Process.Pid, container, &process, &networkState); err != nil {
@@ -203,7 +186,7 @@ func Exec(args []string, env []string, console string, command *exec.Cmd, contai
}
// send the state to the container's init process then shutdown writes for the parent
if err := encoder.Encode(networkState); err != nil {
if err := json.NewEncoder(parent).Encode(process); err != nil {
return terminate(err)
}
// shutdown writes for the parent side of the pipe
+10 -17
View File
@@ -26,9 +26,11 @@ import (
// Process is used for transferring parameters from Exec() to Init()
type processArgs struct {
Args []string `json:"args,omitempty"`
Env []string `json:"environment,omitempty"`
ConsolePath string `json:"console_path,omitempty"`
Args []string `json:"args,omitempty"`
Env []string `json:"environment,omitempty"`
ConsolePath string `json:"console_path,omitempty"`
Config *configs.Config `json:"config,omitempty"`
NetworkState *network.NetworkState `json:"network_state,omitempty"`
}
// TODO(vishh): This is part of the libcontainer API and it does much more than just namespaces related work.
@@ -55,29 +57,20 @@ func Init(pipe *os.File, setupUserns bool) (err error) {
pipe.Close()
}()
decoder := json.NewDecoder(pipe)
var container *configs.Config
if err := decoder.Decode(&container); err != nil {
return err
}
var process *processArgs
if err := decoder.Decode(&process); err != nil {
return err
}
uncleanRootfs, err := os.Getwd()
if err != nil {
return err
}
var process *processArgs
// We always read this as it is a way to sync with the parent as well
var networkState *network.NetworkState
if err := decoder.Decode(&networkState); err != nil {
if err := json.NewDecoder(pipe).Decode(&process); err != nil {
return err
}
container := process.Config
networkState := process.NetworkState
if setupUserns {
err = SetupContainer(container, networkState, process.ConsolePath)
if err == nil {