File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,8 @@ following will output a list of processes running in the container:
101101 if err == nil {
102102 os .Exit (status )
103103 }
104- return fmt .Errorf ("exec failed: %w" , err )
104+ fatalWithCode (fmt .Errorf ("exec failed: %w" , err ), 255 )
105+ return nil // to satisfy the linter
105106 },
106107 SkipArgReorder : true ,
107108}
Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ multiple times.
5959: Pass _ N_ additional file descriptors to the container (** stdio** +
6060** $LISTEN_FDS** + _ N_ in total). Default is ** 0** .
6161
62+ # EXIT STATUS
63+
64+ Exits with a status of _ command_ (unless ** -d** is used), or ** 255** if
65+ an error occurred.
66+
6267# EXAMPLES
6368If the container can run ** ps** (1) command, the following
6469will output a list of processes running in the container:
Original file line number Diff line number Diff line change @@ -21,6 +21,26 @@ function teardown() {
2121 [[ " ${output} " == * " Hello from exec" * ]]
2222}
2323
24+ @test " runc exec [exit codes]" {
25+ runc run -d --console-socket " $CONSOLE_SOCKET " test_busybox
26+ [ " $status " -eq 0 ]
27+
28+ runc exec test_busybox false
29+ [ " $status " -eq 1 ]
30+
31+ runc exec test_busybox sh -c " exit 42"
32+ [ " $status " -eq 42 ]
33+
34+ runc exec --pid-file /non-existent/directory test_busybox true
35+ [ " $status " -eq 255 ]
36+
37+ runc exec test_busybox no-such-binary
38+ [ " $status " -eq 255 ]
39+
40+ runc exec no_such_container true
41+ [ " $status " -eq 255 ]
42+ }
43+
2444@test " runc exec --pid-file" {
2545 # run busybox detached
2646 runc run -d --console-socket " $CONSOLE_SOCKET " test_busybox
Original file line number Diff line number Diff line change @@ -53,13 +53,17 @@ func logrusToStderr() bool {
5353// fatal prints the error's details if it is a libcontainer specific error type
5454// then exits the program with an exit status of 1.
5555func fatal (err error ) {
56- // make sure the error is written to the logger
56+ fatalWithCode (err , 1 )
57+ }
58+
59+ func fatalWithCode (err error , ret int ) {
60+ // Make sure the error is written to the logger.
5761 logrus .Error (err )
5862 if ! logrusToStderr () {
5963 fmt .Fprintln (os .Stderr , err )
6064 }
6165
62- os .Exit (1 )
66+ os .Exit (ret )
6367}
6468
6569// setupSpec performs initial setup based on the cli.Context for the container
You can’t perform that action at this time.
0 commit comments