0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-11-24 02:36:16 +00:00
termux-packages/disabled-packages/kphp/server-php-master-restart.cpp.patch
Tee KOBAYASHI 1bbe66e98a kphp: Disabled
Incompatible with latest libuber-h3. A whole bunch of patches are quite
unmaintainable.

kphp-timelib is also disabled as only kphp depends on it.
2022-11-17 18:08:03 +00:00

79 lines
2.3 KiB
Diff

--- a/server/php-master-restart.cpp
+++ b/server/php-master-restart.cpp
@@ -12,6 +12,48 @@
#include <sys/stat.h>
#include <unistd.h>
+#ifdef __ANDROID__
+#include <alloca.h>
+
+static int shm_open(const char *name, int oflag, mode_t mode) {
+ size_t namelen;
+ char *fname;
+ int fd;
+
+ /* Construct the filename. */
+ while (name[0] == '/') ++name;
+
+ if (name[0] == '\0') {
+ /* The name "/" is not supported. */
+ errno = EINVAL;
+ return -1;
+ }
+
+ namelen = strlen(name);
+ fname = (char *) alloca(sizeof("@TERMUX_PREFIX@/tmp/") - 1 + namelen + 1);
+ memcpy(fname, "@TERMUX_PREFIX@/tmp/", sizeof("@TERMUX_PREFIX@/tmp/") - 1);
+ memcpy(fname + sizeof("@TERMUX_PREFIX@/tmp/") - 1, name, namelen + 1);
+
+ fd = open(fname, oflag, mode);
+ if (fd != -1) {
+ /* We got a descriptor. Now set the FD_CLOEXEC bit. */
+ int flags = fcntl(fd, F_GETFD, 0);
+ flags |= FD_CLOEXEC;
+ flags = fcntl(fd, F_SETFD, flags);
+
+ if (flags == -1) {
+ /* Something went wrong. We cannot return the descriptor. */
+ int save_errno = errno;
+ close(fd);
+ fd = -1;
+ errno = save_errno;
+ }
+ }
+
+ return fd;
+}
+#endif /* __ANDROID__ */
+
#include "common/dl-utils-lite.h"
#include "common/kprintf.h"
#include "common/macos-ports.h"
@@ -29,8 +71,10 @@
int err;
err = pthread_mutexattr_init(&attr);
assert (err == 0 && "failed to init mutexattr");
+#ifndef __ANDROID__
err = pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP);
assert (err == 0 && "failed to setrobust_np for mutex");
+#endif
err = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
assert (err == 0 && "failed to setpshared for mutex");
@@ -98,11 +142,15 @@
void shared_data_lock(shared_data_t *data) {
int err = pthread_mutex_lock(&data->main_mutex);
if (err != 0) {
+#ifdef __ANDROID__
+ if (0) {
+#else
if (err == EOWNERDEAD) {
vkprintf(1, "owner of shared memory mutex is dead. trying to make mutex and memory consitent\n");
err = pthread_mutex_consistent_np(&data->main_mutex);
assert (err == 0 && "failed to make mutex constistent_np");
+#endif
} else {
assert (0 && "unknown mutex lock error");
}