Skip to content

Commit d9fec4c

Browse files
authored
Merge pull request #1065 from keloyang/remove-ps-workaround
Remove the workaround which add a -- flag to runc ps command
2 parents 1359131 + cc0e2d5 commit d9fec4c

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

exec.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var execCommand = cli.Command{
1919
Name: "exec",
2020
Usage: "execute new process inside the container",
21-
ArgsUsage: `<container-id> -- <container command> [command options]
21+
ArgsUsage: `<container-id> <container command> [command options]
2222
2323
Where "<container-id>" is the name for the instance of the container and
2424
"<container command>" is the command to be executed in the container.
@@ -158,9 +158,6 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) {
158158
}
159159
p := spec.Process
160160
p.Args = context.Args()[1:]
161-
if len(p.Args) > 1 && p.Args[0] == "--" {
162-
p.Args = p.Args[1:]
163-
}
164161
// override the cwd, if passed
165162
if context.String("cwd") != "" {
166163
p.Cwd = context.String("cwd")

ps.go

Lines changed: 1 addition & 6 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",
@@ -47,11 +47,6 @@ var psCommand = cli.Command{
4747
// psArgs: [ps_arg1 ps_arg2 ...]
4848
//
4949
psArgs := context.Args()[1:]
50-
51-
if len(psArgs) > 0 && psArgs[0] == "--" {
52-
psArgs = psArgs[1:]
53-
}
54-
5550
if len(psArgs) == 0 {
5651
psArgs = []string{"-ef"}
5752
}

tests/integration/exec.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ function teardown() {
4343
[ "$status" -eq 0 ]
4444
[[ ${lines[0]} =~ [0-9]+ ]]
4545
}
46+
47+
@test "runc exec ls -la" {
48+
# run busybox detached
49+
runc run -d --console /dev/pts/ptmx test_busybox
50+
[ "$status" -eq 0 ]
51+
52+
wait_for_container 15 1 test_busybox
53+
54+
runc exec test_busybox ls -la
55+
[ "$status" -eq 0 ]
56+
[[ ${lines[0]} == *"total"* ]]
57+
[[ ${lines[1]} == *"."* ]]
58+
[[ ${lines[2]} == *".."* ]]
59+
}

tests/integration/ps.bats

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
teardown_busybox
7+
setup_busybox
8+
}
9+
10+
function teardown() {
11+
teardown_busybox
12+
}
13+
14+
@test "ps -eaf" {
15+
# start busybox detached
16+
runc run -d --console /dev/pts/ptmx test_busybox
17+
[ "$status" -eq 0 ]
18+
19+
# check state
20+
wait_for_container 15 1 test_busybox
21+
22+
testcontainer test_busybox running
23+
24+
runc ps test_busybox -eaf
25+
[ "$status" -eq 0 ]
26+
[[ ${lines[0]} =~ UID\ +PID\ +PPID\ +C\ +STIME\ +TTY\ +TIME\ +CMD+ ]]
27+
[[ "${lines[1]}" == *"root"*[0-9]* ]]
28+
}

0 commit comments

Comments
 (0)