termux-packages/root-packages/runc/libcontainer-nsenter-cloned...

44 lines
1.2 KiB
Diff

diff -uNr runc-1.0.0-rc8/libcontainer/nsenter/cloned_binary.c runc-1.0.0-rc8.mod/libcontainer/nsenter/cloned_binary.c
--- runc-1.0.0-rc8/libcontainer/nsenter/cloned_binary.c 2019-04-25 00:48:25.000000000 +0300
+++ runc-1.0.0-rc8.mod/libcontainer/nsenter/cloned_binary.c 2019-07-13 22:18:07.323813978 +0300
@@ -489,6 +489,30 @@
/* Get cheap access to the environment. */
extern char **environ;
+// __procfdname implementation from musl libc.
+static void musl_procfdname(char *buf, unsigned fd)
+{
+ unsigned i, j;
+ for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
+ if (!fd) {
+ buf[i] = '0';
+ buf[i+1] = 0;
+ return;
+ }
+ for (j=fd; j; j/=10, i++);
+ buf[i] = 0;
+ for (; fd; fd/=10) buf[--i] = '0' + fd%10;
+}
+
+// fexecve implementation based on one from musl libc.
+static int musl_fexecve(int fd, char *const argv[], char *const envp[]) {
+ char buf[15 + 3*sizeof(int)];
+ musl_procfdname(buf, fd);
+ execve(buf, argv, envp);
+ if (errno == ENOENT) errno = EBADF;
+ return -1;
+}
+
int ensure_cloned_binary(void)
{
int execfd;
@@ -509,7 +533,7 @@
if (putenv(CLONED_BINARY_ENV "=1"))
goto error;
- fexecve(execfd, argv, environ);
+ musl_fexecve(execfd, argv, environ);
error:
close(execfd);
return -ENOEXEC;