Fix bundle path for exec

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2016-02-24 11:19:30 -08:00
parent ac43d4a0ab
commit f23ff4d194
2 changed files with 11 additions and 14 deletions

17
exec.go
View File

@@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"path"
"strconv" "strconv"
"strings" "strings"
@@ -79,19 +78,17 @@ func execProcess(context *cli.Context) (int, error) {
if err != nil { if err != nil {
return -1, err return -1, err
} }
detach := context.Bool("detach")
var ( state, err := container.State()
detach = context.Bool("detach") if err != nil {
rootfs = container.Config().Rootfs return -1, err
) }
bundle := searchLabels(state.Config.Labels, "bundle")
p, err := getProcess(context, path.Dir(rootfs)) p, err := getProcess(context, bundle)
if err != nil { if err != nil {
return -1, err return -1, err
} }
return runProcess(container, p, nil, context.String("console"), context.String("pid-file"), detach) return runProcess(container, p, nil, context.String("console"), context.String("pid-file"), detach)
} }
func getProcess(context *cli.Context, bundle string) (*specs.Process, error) { func getProcess(context *cli.Context, bundle string) (*specs.Process, error) {

View File

@@ -117,20 +117,20 @@ func getContainers(context *cli.Context) ([]containerState, error) {
ID: state.BaseState.ID, ID: state.BaseState.ID,
InitProcessPid: state.BaseState.InitProcessPid, InitProcessPid: state.BaseState.InitProcessPid,
Status: containerStatus.String(), Status: containerStatus.String(),
Bundle: getBundlePath(state.Config.Labels), Bundle: searchLabels(state.Config.Labels, "bundle"),
Created: state.BaseState.Created}) Created: state.BaseState.Created})
} }
} }
return s, nil return s, nil
} }
func getBundlePath(labels []string) string { func searchLabels(labels []string, query string) string {
for _, l := range labels { for _, l := range labels {
parts := strings.SplitN(l, "=", 2) parts := strings.SplitN(l, "=", 2)
if len(parts) < 1 { if len(parts) < 2 {
continue continue
} }
if parts[0] == "bundle" { if parts[0] == query {
return parts[1] return parts[1]
} }
} }