forked from nabla-containers/runnc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented StartInitialization, only require wait on exec.fifo
Signed-off-by: Brandon Lum <[email protected]>
- Loading branch information
Showing
5 changed files
with
194 additions
and
19 deletions.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package libcontainer | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
type initConfig struct { | ||
Args []string `json:"args"` | ||
} | ||
|
||
func initNabla() error { | ||
// Ricardo special | ||
time.Sleep(1 * time.Second) | ||
fmt.Println("HELLO CALLING FROM START_INITIALIZATION") | ||
|
||
var ( | ||
pipefd int | ||
envInitPipe = os.Getenv("_LIBCONTAINER_INITPIPE") | ||
) | ||
|
||
// Get the INITPIPE. | ||
pipefd, err := strconv.Atoi(envInitPipe) | ||
if err != nil { | ||
return fmt.Errorf("unable to convert _LIBCONTAINER_INITPIPE=%s to int: %s", envInitPipe, err) | ||
} | ||
|
||
fmt.Println("Reading config from parent:") | ||
pipe := os.NewFile(uintptr(pipefd), "pipe") | ||
defer pipe.Close() | ||
|
||
var config *initConfig | ||
if err := json.NewDecoder(pipe).Decode(&config); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Got config: %v\n", config) | ||
|
||
// clear the current process's environment to clean any libcontainer | ||
// specific env vars. | ||
os.Clearenv() | ||
|
||
// TODO: WAIT FOR EXEC.FIFO | ||
|
||
if err := syscall.Exec(config.Args[0], config.Args, os.Environ()); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime" | ||
|
||
"github.com/nabla-containers/runnc/libcontainer" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func init() { | ||
if len(os.Args) > 1 && os.Args[1] == "init" { | ||
runtime.GOMAXPROCS(1) | ||
runtime.LockOSThread() | ||
} | ||
} | ||
|
||
var initCommand = cli.Command{ | ||
Name: "init", | ||
Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`, | ||
Action: func(context *cli.Context) error { | ||
factory, _ := libcontainer.New("") | ||
if err := factory.StartInitialization(); err != nil { | ||
// as the error is sent back to the parent there is no need to log | ||
// or write it to stderr because the parent process will handle this | ||
fmt.Println("ERR: %v", err) | ||
os.Exit(1) | ||
} | ||
panic("libcontainer: container init failed to exec") | ||
}, | ||
} |
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