From cdb552d341368dca4be007d1967ccb930f8e27b6 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Thu, 7 Jul 2016 18:36:26 +0800 Subject: [PATCH] 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 Signed-off-by: Zhao Lei --- ps.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ps.go b/ps.go index e40a973f2..af2618360 100644 --- a/ps.go +++ b/ps.go @@ -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 }