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 it's perror() implementation translates the errno to
a message, it is printed like:

	exec /runc.armel: exec format error

Note that when not using nolibc, the error is printed in the same way as
before.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
  • Loading branch information
rata committed Jan 18, 2024
1 parent 0c5a735 commit 363b5cf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libcontainer/dmz/_dmz.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifdef RUNC_USE_STDLIB
# include <unistd.h>
# include <stdio.h>
# include <string.h>
#else
# include "xstat.h"
# include "nolibc/nolibc.h"
Expand All @@ -11,5 +13,17 @@ int main(int argc, char **argv)
{
if (argc < 1)
return 127;
return execve(argv[0], argv, environ);
int r = execve(argv[0], argv, environ);
if (r) {
char *prefix = "exec ";
int err_len = strlen(prefix) + strlen(argv[0]) + 1;
char err[err_len];

strcpy(err, prefix);
strcpy(err + strlen(prefix), argv[0]);
err[err_len - 1] = '\0';

perror(err);
}
return r;
}

0 comments on commit 363b5cf

Please sign in to comment.