Browse Source

Wrap getpwuid_r (fixes psql history file location)

android-5
Fredrik Fornwall 8 years ago
parent
commit
f3e071d2f4
  1. 2
      build-package.sh
  2. 27
      ndk_patches/pwd.patch
  3. 1
      packages/ndk-sysroot/build.sh

2
build-package.sh

@ -218,7 +218,7 @@ termux_step_setup_variables() {
TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/toolchain-${TERMUX_ARCH}-ndk${TERMUX_NDK_VERSION}-api${TERMUX_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+="-v15"
TERMUX_STANDALONE_TOOLCHAIN+="-v16"
export TERMUX_TAR="tar"
export TERMUX_TOUCH="touch"

27
ndk_patches/pwd.patch

@ -1,6 +1,6 @@
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h ./usr/include/pwd.h
--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/include/pwd.h 2016-03-03 16:54:24.000000000 -0500
+++ ./usr/include/pwd.h 2016-03-10 08:11:16.795710172 -0500
diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h ./usr/include/pwd.h
--- /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm64/usr/include/pwd.h 2017-02-27 17:27:10.000000000 +0100
+++ ./usr/include/pwd.h 2017-03-05 13:28:19.227658358 +0100
@@ -65,6 +65,10 @@
#include <sys/cdefs.h>
#include <sys/types.h>
@ -12,7 +12,7 @@ diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/incl
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
@@ -119,7 +123,40 @@
@@ -119,7 +123,52 @@
int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
@ -23,9 +23,9 @@ diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/incl
+ if (result == NULL || access(realpath_buffer, X_OK) == -1) {
+ char const* bash_path = "@TERMUX_PREFIX@/bin/bash";
+ if (access(bash_path, X_OK) != -1) pw->pw_shell = (char*) bash_path;
+ else pw->pw_shell = "@TERMUX_PREFIX@/bin/ash";
+ else pw->pw_shell = "@TERMUX_PREFIX@/bin/sh";
+ } else {
+ pw->pw_shell = strcmp(realpath_buffer, "@TERMUX_PREFIX@/bin/busybox") == 0 ? (char*)"@TERMUX_PREFIX@/bin/ash" : realpath_buffer;
+ pw->pw_shell = realpath_buffer;
+ }
+ pw->pw_dir = "@TERMUX_HOME@";
+ pw->pw_passwd = "*";
@ -45,11 +45,24 @@ diff -u -r /home/fornwall/lib/android-ndk/platforms/android-21/arch-arm/usr/incl
+ struct passwd* pw = getpwnam(name);
+ if (pw == NULL) return NULL;
+ android_setup_pwd(pw);
+ return pw;
+ return pw;
+}
+
+static int android_polyfill_getpwuid_r(uid_t uid,
+ struct passwd *pwd,
+ char *buffer,
+ size_t bufsize,
+ struct passwd **result) {
+ int ret = getpwuid_r(uid, pwd, buffer, bufsize, result);
+ if (ret != 0) return ret;
+ android_setup_pwd(pwd);
+ return 0;
+}
+
+#define getpwnam android_polyfill_getpwnam
+#define getpwuid android_polyfill_getpwuid
+#define getpwuid_r android_polyfill_getpwuid_r
+static void endpwent(void) { /* Do nothing. */ }
struct passwd* getpwent(void);
int setpwent(void);

1
packages/ndk-sysroot/build.sh

@ -1,6 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://developer.android.com/tools/sdk/ndk/index.html
TERMUX_PKG_DESCRIPTION="System header and library files from the Android NDK needed for compiling C programs"
TERMUX_PKG_VERSION=$TERMUX_NDK_VERSION
TERMUX_PKG_REVISION=1
TERMUX_PKG_NO_DEVELSPLIT=yes
# Depend on libandroid-support-dev so that iconv.h and libintl.h are available:
TERMUX_PKG_DEPENDS="libandroid-support-dev"

Loading…
Cancel
Save