Skip to content

Commit dc9be6c

Browse files
authored
Merge pull request #933 from zhaoleidd/workaround_for_ps
cli: Workaround for ps's argument
2 parents 9b53b36 + cdb552d commit dc9be6c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

man/runc-ps.8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
runc ps - ps displays the processes running inside a container
33

44
# SYNOPSIS
5-
runc ps [command options] <container-id> [ps options]
5+
runc ps [command options] <container-id> [-- ps options]
66

77
# OPTIONS
88
--format value, -f value select one of: table(default) or json

ps.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var psCommand = cli.Command{
1717
Name: "ps",
1818
Usage: "ps displays the processes running inside a container",
19-
ArgsUsage: `<container-id> [ps options]`,
19+
ArgsUsage: `<container-id> [-- ps options]`,
2020
Flags: []cli.Flag{
2121
cli.StringFlag{
2222
Name: "format, f",
@@ -42,12 +42,21 @@ var psCommand = cli.Command{
4242
return nil
4343
}
4444

45-
psArgs := context.Args().Get(1)
46-
if psArgs == "" {
47-
psArgs = "-ef"
45+
// [1:] is to remove command name, ex:
46+
// context.Args(): [containet_id ps_arg1 ps_arg2 ...]
47+
// psArgs: [ps_arg1 ps_arg2 ...]
48+
//
49+
psArgs := context.Args()[1:]
50+
51+
if len(psArgs) > 0 && psArgs[0] == "--" {
52+
psArgs = psArgs[1:]
53+
}
54+
55+
if len(psArgs) == 0 {
56+
psArgs = []string{"-ef"}
4857
}
4958

50-
output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output()
59+
output, err := exec.Command("ps", psArgs...).Output()
5160
if err != nil {
5261
return err
5362
}

0 commit comments

Comments
 (0)