diff --git a/checkpoint.go b/checkpoint.go index e7664a13..ecf89ea1 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -1,3 +1,5 @@ +// +build linux + package main import ( diff --git a/events.go b/events.go index 174af906..eb53d1bc 100644 --- a/events.go +++ b/events.go @@ -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) diff --git a/main.go b/main.go index f4793d39..72958a76 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/main_unsupported.go b/main_unsupported.go new file mode 100644 index 00000000..7cb1e9ab --- /dev/null +++ b/main_unsupported.go @@ -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") +} diff --git a/restore.go b/restore.go index 511588b7..8170bfca 100644 --- a/restore.go +++ b/restore.go @@ -1,3 +1,5 @@ +// +build linux + package main import ( diff --git a/run.go b/run.go index 7645d4c3..80d2b748 100644 --- a/run.go +++ b/run.go @@ -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 { diff --git a/signals.go b/signals.go index 4c1463e8..8ea56014 100644 --- a/signals.go +++ b/signals.go @@ -1,3 +1,5 @@ +// +build linux + package main import ( diff --git a/spec.go b/spec.go index 153950c5..42f80c89 100644 --- a/spec.go +++ b/spec.go @@ -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) }, diff --git a/tty.go b/tty.go index 95d82c8b..d72957da 100644 --- a/tty.go +++ b/tty.go @@ -1,3 +1,5 @@ +// +build linux + package main import ( diff --git a/utils.go b/utils.go index 43da7fa5..7153c4d4 100644 --- a/utils.go +++ b/utils.go @@ -1,3 +1,5 @@ +// +build linux + package main import (