Remove <sys/sem.h>

System V semaphores doesn't work for non-root, it's better to
point at unnamed POSIX semaphores in <semaphore.h>
This commit is contained in:
Fredrik Fornwall 2017-03-05 14:22:31 +01:00
parent f3e071d2f4
commit 67d2d61527
4 changed files with 6 additions and 26 deletions

View File

@ -126,9 +126,8 @@ Common porting problems
* Android uses a customized version of shared memory managemnt known as ashmem. libandroid-shmem wraps SYSV shared
memory calls to standard ashmem operations. Use it with `LDFLAGS+=" -landroid-shmem`.
* SYSV semaphore libc wrappers (semget(2), semop(2) and others) aren't available. Direct syscalls can be used with
`CFLAGS+=" -DTERMUX_SEMOPS_STUBS=1"`. Using this requires privelege escalation i.e. only root can do it. Use
unnamed POSIX semaphores instead (named semaphores are unimplemented).
* SYSV semaphores (semget(2), semop(2) and others) aren't available.
Use unnamed POSIX semaphores instead (named semaphores are unimplemented).
dlopen() and RTLD&#95;&#42; flags
=================================

View File

@ -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+="-v16"
TERMUX_STANDALONE_TOOLCHAIN+="-v17"
export TERMUX_TAR="tar"
export TERMUX_TOUCH="touch"
@ -564,8 +564,9 @@ termux_step_setup_toolchain() {
# ifaddrs.h: Added in android-24 unified headers, use a inline implementation for now.
cp "$TERMUX_SCRIPTDIR"/ndk_patches/{elf.h,sysexits.h,ifaddrs.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include
# Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem:
rm $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/sys/shm.h
# Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem.
# Also remove <sys/sem.h> as it doesn't work for non-root.
rm $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/sys/{shm.h,sem.h}
local _LIBDIR=usr/lib
if [ $TERMUX_ARCH = x86_64 ]; then _LIBDIR+=64; fi

View File

@ -15,8 +15,5 @@ USE_UNNAMED_POSIX_SEMAPHORES=1
TERMUX_PKG_EXTRA_MAKE_ARGS=" -s"
termux_step_pre_configure () {
# to use shmem and sem stubs
CFLAGS+=" -DTERMUX_SEMOPS_STUBS=1"
LDFLAGS+=" -llog"
}

View File

@ -1,17 +0,0 @@
--- /home/vishal/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm/usr/include/sys/sem.h 2016-10-12 15:11:58.000000000 +0530
+++ ./usr/include/sys/sem.h 2017-01-24 08:23:25.150726158 +0530
@@ -31,4 +31,14 @@
#include <linux/sem.h>
+#ifdef TERMUX_SEMOPS_STUBS
+
+#include <sys/syscall.h>
+
+#define semop(semid, sops, nsops) syscall(__NR_semop, semid, sops, nsops)
+#define semget(key, nsems, semflg) syscall(__NR_semget, key, nsems, semflg)
+#define semctl(semid, semnum, cmd, ...) syscall(__NR_semctl, semid, semnum, cmd, __VA_ARGS__)
+
+#endif /* TERMUX_SEMOPS_STUBS */
+
#endif /* _SYS_SEM_H_ */