Merge pull request #933 from zhaoleidd/workaround_for_ps
cli: Workaround for ps's argument
This commit is contained in:
commit
dc9be6cab1
|
@ -2,7 +2,7 @@
|
||||||
runc ps - ps displays the processes running inside a container
|
runc ps - ps displays the processes running inside a container
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
runc ps [command options] <container-id> [ps options]
|
runc ps [command options] <container-id> [-- ps options]
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
--format value, -f value select one of: table(default) or json
|
--format value, -f value select one of: table(default) or json
|
||||||
|
|
19
ps.go
19
ps.go
|
@ -16,7 +16,7 @@ import (
|
||||||
var psCommand = cli.Command{
|
var psCommand = cli.Command{
|
||||||
Name: "ps",
|
Name: "ps",
|
||||||
Usage: "ps displays the processes running inside a container",
|
Usage: "ps displays the processes running inside a container",
|
||||||
ArgsUsage: `<container-id> [ps options]`,
|
ArgsUsage: `<container-id> [-- ps options]`,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "format, f",
|
Name: "format, f",
|
||||||
|
@ -42,12 +42,21 @@ var psCommand = cli.Command{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
psArgs := context.Args().Get(1)
|
// [1:] is to remove command name, ex:
|
||||||
if psArgs == "" {
|
// context.Args(): [containet_id ps_arg1 ps_arg2 ...]
|
||||||
psArgs = "-ef"
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue