]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
include: add fexecve() for Android's Bionic
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 11 Feb 2019 13:35:50 +0000 (14:35 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 12 Feb 2019 00:35:56 +0000 (01:35 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/include/fexecve.c [new file with mode: 0644]
src/include/fexecve.h [new file with mode: 0644]
src/lxc/Makefile.am
src/lxc/rexec.c

diff --git a/src/include/fexecve.c b/src/include/fexecve.c
new file mode 100644 (file)
index 0000000..21ccfe8
--- /dev/null
@@ -0,0 +1,68 @@
+/* liblxcapi
+ *
+ * Copyright © 2019 Christian Brauner <christian.brauner@ubuntu.com>.
+ * Copyright © 2019 Canonical Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; 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 <fcntl.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#include "config.h"
+
+static int lxc_raw_execveat(int dirfd, const char *pathname, char *const argv[],
+                           char *const envp[], int flags)
+{
+#ifdef __NR_execveat
+       syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
+#else
+       errno = ENOSYS;
+#endif
+       return -1;
+}
+
+int efexecve(int fd, char *const argv[], char *const envp[])
+{
+       char procfd[256];
+       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 (file)
index 0000000..14589d7
--- /dev/null
@@ -0,0 +1,27 @@
+/* liblxcapi
+ *
+ * Copyright © 2019 Christian Brauner <christian.brauner@ubuntu.com>.
+ * Copyright © 2019 Canonical Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; 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 efexecve(int fd, char *const argv[], char *const envp[]);
+
+#endif /* _LXC_FEXECVE_H */
index 96f139dacd5671a1b16994eece698ffaa505505c..c27c10505286676be50b6977869f2dd06e7f5ca4 100644 (file)
@@ -41,6 +41,7 @@ noinst_HEADERS = \
 
 if IS_BIONIC
 noinst_HEADERS += \
+       ../include/fexecve.h \
        ../include/ifaddrs.h \
        ../include/openpty.h \
        ../include/lxcmntent.h
@@ -137,6 +138,7 @@ endif
 
 if IS_BIONIC
 liblxc_la_SOURCES += \
+       ../include/fexecve.c ../include/fexecve.h \
        ../include/ifaddrs.c ../include/ifaddrs.h \
        ../include/openpty.c ../include/openpty.h \
        ../include/lxcmntent.c ../include/lxcmntent.h
index 7b55ff704d7ec3896bb23fba836904096811495c..29bfd859e0682468745510b59b4793b8b61ed489 100644 (file)
 #include "config.h"
 #include "utils.h"
 
+#if IS_BIONIC
+#include "../include/fexecve.h"
+#endif
+
 #define LXC_MEMFD_REXEC_SEALS \
        (F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE)