Merge pull request #68 from mtesselH/master

Enable build on unsupported platforms
This commit is contained in:
Michael Crosby 2015-06-30 10:00:23 -07:00
commit fd6564b8e4
10 changed files with 72 additions and 33 deletions

View File

@ -1,3 +1,5 @@
// +build linux
package main
import (

View File

@ -1,3 +1,5 @@
// +build linux
package main
import (
@ -56,7 +58,7 @@ var eventsCommand = cli.Command{
return
}
go func() {
for _ = range time.Tick(context.Duration("interval")) {
for range time.Tick(context.Duration("interval")) {
s, err := container.Stats()
if err != nil {
logrus.Error(err)

33
main.go
View File

@ -2,11 +2,9 @@ package main
import (
"os"
"runtime"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/opencontainers/runc/libcontainer"
)
const (
@ -27,18 +25,6 @@ After creating a spec for your root filesystem with runc, you can execute a simp
`
)
func init() {
if len(os.Args) > 1 && os.Args[1] == "init" {
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
factory, _ := libcontainer.New("")
if err := factory.StartInitialization(); err != nil {
fatal(err)
}
panic("--this line should never been executed, congratulations--")
}
}
func main() {
app := cli.NewApp()
app.Name = "runc"
@ -77,23 +63,8 @@ func main() {
}
return nil
}
// default action is to execute a container
app.Action = func(context *cli.Context) {
spec, err := loadSpec(context.Args().First())
if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := execContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}
app.Action = runAction
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)

22
main_unsupported.go Normal file
View File

@ -0,0 +1,22 @@
// +build !linux
package main
import (
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
func getDefaultID() string {
return ""
}
var (
checkpointCommand cli.Command
eventsCommand cli.Command
restoreCommand cli.Command
)
func runAction(*cli.Context) {
logrus.Fatal("Current OS is not supported yet")
}

View File

@ -1,3 +1,5 @@
// +build linux
package main
import (

33
run.go
View File

@ -1,14 +1,29 @@
// +build linux
package main
import (
"fmt"
"os"
"runtime"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/opencontainers/runc/libcontainer"
)
func init() {
if len(os.Args) > 1 && os.Args[1] == "init" {
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
factory, _ := libcontainer.New("")
if err := factory.StartInitialization(); err != nil {
fatal(err)
}
panic("--this line should never been executed, congratulations--")
}
}
func execContainer(context *cli.Context, spec *Spec) (int, error) {
config, err := createLibcontainerConfig(spec)
if err != nil {
@ -48,6 +63,24 @@ func execContainer(context *cli.Context, spec *Spec) (int, error) {
return handler.forward(process)
}
// default action is to execute a container
func runAction(context *cli.Context) {
spec, err := loadSpec(context.Args().First())
if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := execContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}
func destroy(container libcontainer.Container) {
status, err := container.Status()
if err != nil {

View File

@ -1,3 +1,5 @@
// +build linux
package main
import (

View File

@ -5,6 +5,7 @@ import (
"fmt"
"runtime"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
@ -111,7 +112,7 @@ var specCommand = cli.Command{
}
data, err := json.MarshalIndent(&spec, "", "\t")
if err != nil {
fatal(err)
logrus.Fatal(err)
}
fmt.Printf("%s", data)
},

2
tty.go
View File

@ -1,3 +1,5 @@
// +build linux
package main
import (

View File

@ -1,3 +1,5 @@
// +build linux
package main
import (