diff --git a/libcontainer/dmz/_dmz.c b/libcontainer/dmz/_dmz.c index 2855e60d5cd..e4cfcf087e7 100644 --- a/libcontainer/dmz/_dmz.c +++ b/libcontainer/dmz/_dmz.c @@ -1,4 +1,7 @@ #ifdef RUNC_USE_STDLIB +# include +# include +# include # include #else # include "xstat.h" @@ -11,5 +14,14 @@ int main(int argc, char **argv) { if (argc < 1) return 127; - return execve(argv[0], argv, environ); + int ret = execve(argv[0], argv, environ); + if (ret) { + /* NOTE: This error message format MUST match Go's format. */ + char err_msg[5 + PATH_MAX + 1] = "exec "; // "exec " + argv[0] + '\0' + strncat(err_msg, argv[0], PATH_MAX); + err_msg[sizeof(err_msg) - 1] = '\0'; + + perror(err_msg); + } + return ret; } diff --git a/tests/integration/run.bats b/tests/integration/run.bats index f6bd3c86500..bf23d22a103 100644 --- a/tests/integration/run.bats +++ b/tests/integration/run.bats @@ -230,3 +230,20 @@ function teardown() { grep -E '^monotonic\s+7881\s+2718281$' <<<"$output" grep -E '^boottime\s+1337\s+3141519$' <<<"$output" } + +@test "runc run [exec error]" { + cat <rootfs/run.sh +#!/mmnnttbb foo bar +sh +EOF + chmod +x rootfs/run.sh + update_config '.process.args = [ "/run.sh" ]' + runc run test_hello + + # Ensure that the output contains the right error message. For runc-dmz, both + # nolibc and libc have the same formatting string (but libc will print the + # errno description rather than just the number), and for runc_nodmz the error + # message from Go starts with the same string. + [ "$status" -ne 0 ] + [[ "$output" = *"exec /run.sh: "* ]] +}