The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2841

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 8159340d4f56970bae783db1d6155ed93a71d9e4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Mon, 11 Feb 2019 14:35:50 +0100
Subject: [PATCH] include: add fexecve() for Android's Bionic

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 src/include/fexecve.c | 56 +++++++++++++++++++++++++++++++++++++++++++
 src/include/fexecve.h | 26 ++++++++++++++++++++
 src/lxc/Makefile.am   |  6 +++--
 3 files changed, 86 insertions(+), 2 deletions(-)
 create mode 100644 src/include/fexecve.c
 create mode 100644 src/include/fexecve.h

diff --git a/src/include/fexecve.c b/src/include/fexecve.c
new file mode 100644
index 000000000..de29da8c4
--- /dev/null
+++ b/src/include/fexecve.c
@@ -0,0 +1,56 @@
+/* liblxcapi
+ *
+ * Copyright © 2019 Christian Brauner <christian.brau...@ubuntu.com>.
+ * Copyright © 2019 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "macro.h"
+#include "raw_syscalls.h"
+
+int fexecve(int fd, char *const argv[], char *const envp[])
+{
+       char procfd[LXC_PROC_PID_FD_LEN];
+       int ret;
+
+       if (fd < 0 || !argv || !envp) {
+               errno = EINVAL;
+               return -1;
+       }
+
+#ifdef __NR_execveat
+       lxc_raw_execveat(fd, "", argv, envp, AT_EMPTY_PATH);
+       if (errno != ENOSYS)
+               return -1;
+#endif
+
+       ret = snprintf(procfd, sizeof(procfd), "/proc/self/fd/%d", fd);
+       if (ret < 0 || (size_t)ret >= sizeof(procfd)) {
+               errno = ENAMETOOLONG;
+               return -1;
+       }
+
+       execve(procfd, argv, envp);
+       return -1;
+}
diff --git a/src/include/fexecve.h b/src/include/fexecve.h
new file mode 100644
index 000000000..78bda0695
--- /dev/null
+++ b/src/include/fexecve.h
@@ -0,0 +1,26 @@
+/* liblxcapi
+ *
+ * Copyright © 2019 Christian Brauner <christian.brau...@ubuntu.com>.
+ * Copyright © 2019 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _LXC_FEXECVE_H
+#define _LXC_FEXECVE_H
+
+#include <stdio.h>
+extern int fexecve(int fd, char *const argv[], char *const envp[]);
+
+#endif /* _LXC_FEXECVE_H */
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index dc8aa3d77..e1499a7eb 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -47,7 +47,8 @@ noinst_HEADERS = api_extensions.h \
                 utils.h
 
 if IS_BIONIC
-noinst_HEADERS += ../include/lxcmntent.h \
+noinst_HEADERS += ../include/fexecve.h \
+                 ../include/lxcmntent.h \
                  ../include/openpty.h
 endif
 
@@ -145,7 +146,8 @@ liblxc_la_SOURCES = af_unix.c af_unix.h \
                    $(LSM_SOURCES)
 
 if IS_BIONIC
-liblxc_la_SOURCES += ../include/lxcmntent.c ../include/lxcmntent.h \
+liblxc_la_SOURCES += ../include/fexecve.c ../include/fexecve.h \
+                    ../include/lxcmntent.c ../include/lxcmntent.h \
                     ../include/openpty.c ../include/openpty.h
 endif
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to