From 8ebeeaa3d44c9da01694984a42c4d27215383969 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sun, 17 Sep 2017 15:55:41 +0200 Subject: [PATCH] ndk-patches: Use bin/login in getpwd() --- build-package.sh | 2 +- ndk-patches/pwd.h.patch | 24 ++++++------------------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/build-package.sh b/build-package.sh index 0d7b6eb6..b02d1e64 100755 --- a/build-package.sh +++ b/build-package.sh @@ -365,7 +365,7 @@ termux_step_start_build() { TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/${TERMUX_NDK_VERSION}-${TERMUX_ARCH}-${TERMUX_PKG_API_LEVEL}" # Bump the below version if a change is made in toolchain setup to ensure # that everyone gets an updated toolchain: - TERMUX_STANDALONE_TOOLCHAIN+="-v12" + TERMUX_STANDALONE_TOOLCHAIN+="-v13" if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" diff --git a/ndk-patches/pwd.h.patch b/ndk-patches/pwd.h.patch index 2d39b85b..5575a19d 100644 --- a/ndk-patches/pwd.h.patch +++ b/ndk-patches/pwd.h.patch @@ -1,15 +1,6 @@ diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h ./usr/include/pwd.h --- /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h 2017-06-20 17:41:56.000000000 +0200 +++ ./usr/include/pwd.h 2017-06-26 11:45:26.036064547 +0200 -@@ -63,6 +63,8 @@ - #include - #include - -+#include /* For realpath() */ -+ - __BEGIN_DECLS - - struct passwd { @@ -89,7 +91,6 @@ struct passwd* getpwent(void) __INTRODUCED_IN(26); @@ -18,23 +9,20 @@ diff -u -r /home/fornwall/lib/android-ndk/sysroot/usr/include/pwd.h ./usr/includ #endif /* __ANDROID_API__ >= 26 */ -@@ -99,6 +100,54 @@ +@@ -99,6 +100,51 @@ int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**) __INTRODUCED_IN(12); #endif /* __ANDROID_API__ >= 12 */ +int access(const char* __path, int __mode); + +static void android_setup_pwd(struct passwd* pw) { -+ static char realpath_buffer[4096/*PATH_MAX*/]; -+ char* result = realpath("/data/data/com.termux/files/home/.termux/shell", realpath_buffer); -+ if (result == NULL || access(realpath_buffer, /*X_OK*/1) == -1) { -+ char const* bash_path = "/data/data/com.termux/files/usr/bin/bash"; -+ if (access(bash_path, /*X_OK*/1) != -1) pw->pw_shell = (char*) bash_path; -+ else pw->pw_shell = "/data/data/com.termux/files/usr/bin/sh"; ++ char const* result = "@TERMUX_PREFIX@/bin/login"; ++ if (result == NULL || access(result, /*X_OK*/1) == -1) { ++ pw->pw_shell = "@TERMUX_PREFIX@/bin/bash"; + } else { -+ pw->pw_shell = realpath_buffer; ++ pw->pw_shell = result; + } -+ pw->pw_dir = "/data/data/com.termux/files/home"; ++ pw->pw_dir = "@TERMUX_HOME@"; + pw->pw_passwd = "*"; +#ifdef __LP64__ + pw->pw_gecos = ""; /* Avoid NULL field. */ -- 2.11.0