ps: Support muitiple ps arguments

Before patch:
 | # ./runc ps test -- -e -f
 |   PID TTY          TIME CMD
 | 29046 pts/2    00:00:00 sh  <-- The -f option was skipped
 | #

After patch:
 | # ./runc ps test -- -e -f
 | UID        PID  PPID  C STIME TTY          TIME CMD
 | root     29046 29038  0 Jul06 pts/2    00:00:00 sh
 | #

Reported-by: Qiang Huang <h.huangqiang@huawei.com>

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
This commit is contained in:
Zhao Lei
2016-07-07 18:36:26 +08:00
parent f5a95fa244
commit cdb552d341
+13 -7
View File
@@ -42,15 +42,21 @@ var psCommand = cli.Command{
return nil
}
psArgs := context.Args().Get(1)
if psArgs == "--" {
psArgs = context.Args().Get(2)
}
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
}