Skip to content

Commit

Permalink
libct/dmz: Print execve() errors
Browse files Browse the repository at this point in the history
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 <rodrigoca@microsoft.com>
  • Loading branch information
rata committed Jan 21, 2024
1 parent 10754b3 commit ad57a33
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 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,15 @@ 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] = "exec "; // "exec " + argv[0]

strncpy(err_msg + strlen(err_msg), argv[0], PATH_MAX);
err_msg[sizeof(err_msg) - 1] = '\0';

perror(err_msg);
}
return ret;
}

0 comments on commit ad57a33

Please sign in to comment.