Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runc-dmz error printing #4172

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion libcontainer/dmz/_dmz.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#ifdef RUNC_USE_STDLIB
# include <linux/limits.h>
# include <stdio.h>
# include <string.h>
# include <unistd.h>
#else
# include "xstat.h"
Expand All @@ -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);
cyphar marked this conversation as resolved.
Show resolved Hide resolved
err_msg[sizeof(err_msg) - 1] = '\0';

perror(err_msg);
}
return ret;
}
17 changes: 17 additions & 0 deletions tests/integration/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF >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: "* ]]
}
Loading