Skip to content

Commit

Permalink
Enable build on unsupported platforms
Browse files Browse the repository at this point in the history
Should compile now without errors but changes needed to be added for each system so it actually works.
main_unsupported.go is a new file with all the unsupported commands
Fixes #9

Signed-off-by: Marianna <mtesselh@gmail.com>
  • Loading branch information
mtesselH committed Jun 30, 2015
1 parent 85e264d commit 5aa82c9
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 33 deletions.
2 changes: 2 additions & 0 deletions checkpoint.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down
4 changes: 3 additions & 1 deletion events.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 2 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package main

import (
"os"
"runtime"

"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/opencontainers/runc/libcontainer"
)

const (
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions main_unsupported.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 2 additions & 0 deletions restore.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down
33 changes: 33 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions signals.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down
3 changes: 2 additions & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"runtime"

"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)

Expand Down Expand Up @@ -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)
},
Expand Down
2 changes: 2 additions & 0 deletions tty.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux

package main

import (
Expand Down

0 comments on commit 5aa82c9

Please sign in to comment.