From 81064d29eca234e59271e82a1e29da7a359340b2 Mon Sep 17 00:00:00 2001 From: Dallas Strouse Date: Thu, 4 May 2023 12:14:35 -0500 Subject: [PATCH 1/2] Add get_current_dir_name from musl to fix building on Bionic libc get_current_dir_name is a GNU function, and is not supported on all C libraries. Bionic is the main one here, as musl provides the get_current_dir_name we're using here. We mostly copy-paste the musl implementation in order to fix building on the Bionic libc. Bubblewrap will now build and run successfully on Android. Note that Android currently prohibits user namespaces and suid programs, so this needs root access to function. Signed-off-by: Dallas Strouse --- bubblewrap.c | 8 ++++++++ get_current_dir_name.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 get_current_dir_name.c diff --git a/bubblewrap.c b/bubblewrap.c index 8322ea03..6686b2e4 100644 --- a/bubblewrap.c +++ b/bubblewrap.c @@ -53,6 +53,14 @@ __result; })) #endif +/* Bionic doesnt include this C function, so + * we pull it from the musl source tree for use here. + * Should be possible to add more checks for other libcs + * when needed. */ +#ifdef __BIONIC__ +#include "get_current_dir_name.c" +#endif + /* We limit the size of a tmpfs to half the architecture's address space, * to avoid hitting arbitrary limits in the kernel. * For example, on at least one x86_64 machine, the actual limit seems to be diff --git a/get_current_dir_name.c b/get_current_dir_name.c new file mode 100644 index 00000000..3b3f2340 --- /dev/null +++ b/get_current_dir_name.c @@ -0,0 +1,37 @@ +Copyright © 2005-2020 Rich Felker, et al., 2023 Dallas Strouse + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +#include +#include +#include +#include +#include + +static char *get_current_dir_name(void) { + struct stat a, b; + char *res = getenv("PWD"); + if (res && *res && !stat(res, &a) && !stat(".", &b) + && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino)) + return strdup(res); + return getcwd(0, 0); +} + From 47cf000f1a9d66eb9e6f001b8da5e4d323297c50 Mon Sep 17 00:00:00 2001 From: Dallas Strouse <93224879+orowith2os@users.noreply.github.com> Date: Thu, 4 May 2023 12:24:41 -0500 Subject: [PATCH 2/2] Forgot to comment the license --- get_current_dir_name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get_current_dir_name.c b/get_current_dir_name.c index 3b3f2340..f7416938 100644 --- a/get_current_dir_name.c +++ b/get_current_dir_name.c @@ -1,4 +1,4 @@ -Copyright © 2005-2020 Rich Felker, et al., 2023 Dallas Strouse +/* Copyright © 2005-2020 Rich Felker, et al., 2023 Dallas Strouse Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -18,7 +18,7 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - +*/ #include #include