Skip to content

Commit 4baaf18

Browse files
authored
Merge pull request #4172 from kinvolk/rata/runc-dmz
Fix runc-dmz error printing
2 parents 10754b3 + fe95a2a commit 4baaf18

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

libcontainer/dmz/_dmz.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#ifdef RUNC_USE_STDLIB
2+
# include <linux/limits.h>
3+
# include <stdio.h>
4+
# include <string.h>
25
# include <unistd.h>
36
#else
47
# include "xstat.h"
@@ -11,5 +14,14 @@ int main(int argc, char **argv)
1114
{
1215
if (argc < 1)
1316
return 127;
14-
return execve(argv[0], argv, environ);
17+
int ret = execve(argv[0], argv, environ);
18+
if (ret) {
19+
/* NOTE: This error message format MUST match Go's format. */
20+
char err_msg[5 + PATH_MAX + 1] = "exec "; // "exec " + argv[0] + '\0'
21+
strncat(err_msg, argv[0], PATH_MAX);
22+
err_msg[sizeof(err_msg) - 1] = '\0';
23+
24+
perror(err_msg);
25+
}
26+
return ret;
1527
}

tests/integration/run.bats

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,20 @@ function teardown() {
230230
grep -E '^monotonic\s+7881\s+2718281$' <<<"$output"
231231
grep -E '^boottime\s+1337\s+3141519$' <<<"$output"
232232
}
233+
234+
@test "runc run [exec error]" {
235+
cat <<EOF >rootfs/run.sh
236+
#!/mmnnttbb foo bar
237+
sh
238+
EOF
239+
chmod +x rootfs/run.sh
240+
update_config '.process.args = [ "/run.sh" ]'
241+
runc run test_hello
242+
243+
# Ensure that the output contains the right error message. For runc-dmz, both
244+
# nolibc and libc have the same formatting string (but libc will print the
245+
# errno description rather than just the number), and for runc_nodmz the error
246+
# message from Go starts with the same string.
247+
[ "$status" -ne 0 ]
248+
[[ "$output" = *"exec /run.sh: "* ]]
249+
}

0 commit comments

Comments
 (0)