Merge pull request #933 from zhaoleidd/workaround_for_ps

cli: Workaround for ps's argument
This commit is contained in:
Qiang Huang 2016-08-27 10:57:17 +08:00 committed by GitHub
commit dc9be6cab1
2 changed files with 15 additions and 6 deletions

View File

@ -2,7 +2,7 @@
runc ps - ps displays the processes running inside a container
# SYNOPSIS
runc ps [command options] <container-id> [ps options]
runc ps [command options] <container-id> [-- ps options]
# OPTIONS
--format value, -f value select one of: table(default) or json

19
ps.go
View File

@ -16,7 +16,7 @@ import (
var psCommand = cli.Command{
Name: "ps",
Usage: "ps displays the processes running inside a container",
ArgsUsage: `<container-id> [ps options]`,
ArgsUsage: `<container-id> [-- ps options]`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
@ -42,12 +42,21 @@ var psCommand = cli.Command{
return nil
}
psArgs := context.Args().Get(1)
if psArgs == "" {
psArgs = "-ef"
// [1:] is to remove command name, ex:
// context.Args(): [containet_id ps_arg1 ps_arg2 ...]
// psArgs: [ps_arg1 ps_arg2 ...]
//
psArgs := context.Args()[1:]
if len(psArgs) > 0 && psArgs[0] == "--" {
psArgs = psArgs[1:]
}
output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output()
if len(psArgs) == 0 {
psArgs = []string{"-ef"}
}
output, err := exec.Command("ps", psArgs...).Output()
if err != nil {
return err
}