Skip to content

Commit 8afeccc

Browse files
committed
libct/dmz: Print execve() errors
This error code is using functions that are present in nolibc too. When using nolibc, the error is printed like: exec /runc.armel: errno=8 When using libc, as its perror() implementation translates the errno to a message, it is printed like: exec /runc.armel: exec format error Note that when using libc, the error is printed in the same way as before. Signed-off-by: Rodrigo Campos <[email protected]>
1 parent 10754b3 commit 8afeccc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-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
}

0 commit comments

Comments
 (0)