Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions cmd/oci-runtime-tool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,32 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
if context.IsSet("prestart") {
preStartHooks := context.StringSlice("prestart")
for _, hook := range preStartHooks {
path, args := parseHook(hook)
path, args, err := parseHook(hook)
if err != nil {
return err
}
g.AddPreStartHook(path, args)
}
}

if context.IsSet("poststop") {
postStopHooks := context.StringSlice("poststop")
for _, hook := range postStopHooks {
path, args := parseHook(hook)
path, args, err := parseHook(hook)
if err != nil {
return err
}
g.AddPostStopHook(path, args)
}
}

if context.IsSet("poststart") {
postStartHooks := context.StringSlice("poststart")
for _, hook := range postStartHooks {
path, args := parseHook(hook)
path, args, err := parseHook(hook)
if err != nil {
return err
}
g.AddPostStartHook(path, args)
}
}
Expand Down Expand Up @@ -524,21 +533,24 @@ func parseIDMapping(idms string) (uint32, uint32, uint32, error) {
return uint32(hid), uint32(cid), uint32(size), nil
}

func parseHook(s string) (string, []string) {
parts := strings.Split(s, ":")
func parseHook(s string) (string, []string, error) {
args := []string{}
parts := strings.Split(s, ":")
if len(parts) > 1 && parts[0] == "" {
return "", args, fmt.Errorf("invalid hook value: %s", s)
}
path := parts[0]
if len(parts) > 1 {
args = parts[1:]
}
return path, args
return path, args, nil
}

func parseNetworkPriority(np string) (string, int32, error) {
var err error

parts := strings.Split(np, ":")
if len(parts) != 2 {
if len(parts) != 2 || parts[0] == "" {
return "", 0, fmt.Errorf("invalid value %v for --linux-network-priorities", np)
}
priority, err := strconv.Atoi(parts[1])
Expand All @@ -555,14 +567,14 @@ func parseTmpfsMount(s string) (string, []string, error) {
var err error

parts := strings.Split(s, ":")
if len(parts) == 2 {
if len(parts) == 2 && parts[0] != "" {
dest = parts[0]
options = strings.Split(parts[1], ",")
} else if len(parts) == 1 {
dest = parts[0]
options = []string{"rw", "noexec", "nosuid", "nodev", "size=65536k"}
} else {
err = fmt.Errorf("invalid value for --tmpfs")
err = fmt.Errorf("invalid -- tmpfs value: %s", s)
}

return dest, options, err
Expand All @@ -582,12 +594,15 @@ func parseBindMount(s string) (string, string, []string, error) {
return source, dest, options, fmt.Errorf("--bind should have format src:dest[:options...]")
}

if source == "" || dest == "" {
return source, dest, options, fmt.Errorf("--bind should have format src:dest[:options...]")
}
return source, dest, options, nil
}

func parseRlimit(rlimit string) (string, uint64, uint64, error) {
parts := strings.Split(rlimit, ":")
if len(parts) != 3 {
if len(parts) != 3 || parts[0] == "" {
return "", 0, 0, fmt.Errorf("invalid rlimits value: %s", rlimit)
}

Expand Down