new package: uwsgi (#8148)

This commit is contained in:
xtkoba 2021-12-11 05:37:54 +09:00 committed by GitHub
parent de533fe10c
commit d617bb28bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 513 additions and 0 deletions

23
packages/uwsgi/build.sh Normal file
View File

@ -0,0 +1,23 @@
TERMUX_PKG_HOMEPAGE=https://projects.unbit.it/uwsgi
TERMUX_PKG_DESCRIPTION="uWSGI application server container"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=2.0.19.1
TERMUX_PKG_SRCURL=https://github.com/unbit/uwsgi/archive/${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=bf17cdbb9bd8bcb7c1633e34d9d7308cb4cc19eb0ff2d61057f840c1ba1fc41b
TERMUX_PKG_DEPENDS="libandroid-glob, libcap, libcrypt, libjansson, libuuid, libxml2, openssl, pcre, python"
TERMUX_PKG_BUILD_IN_SRC=true
termux_step_configure() {
cp $TERMUX_PKG_BUILDER_DIR/sys_sem.c $TERMUX_PKG_SRCDIR/core/
cp $TERMUX_PKG_BUILDER_DIR/sys_time.c $TERMUX_PKG_SRCDIR/core/
export UWSGI_PYTHON_NOLIB=true
export UWSGI_INCLUDES="$TERMUX_PREFIX/include"
export APPEND_CFLAGS="$CPPFLAGS -I$TERMUX_PREFIX/include/python3.10 -DOBSOLETE_LINUX_KERNEL"
LDFLAGS+=" -lpython3.10 -landroid-glob"
}
termux_step_make_install() {
install -Dm700 -t $TERMUX_PREFIX/bin "$TERMUX_PKG_BUILDDIR/uwsgi"
}

View File

@ -0,0 +1,11 @@
--- a/core/lock.c
+++ b/core/lock.c
@@ -495,7 +495,7 @@
union semun {
int val;
struct semid_ds *buf;
- ushort *array;
+ unsigned short *array;
} semu;
int semid;
key_t myKey;

View File

@ -0,0 +1,38 @@
--- a/core/spooler.c
+++ b/core/spooler.c
@@ -3,7 +3,7 @@
extern struct uwsgi_server uwsgi;
static void spooler_readdir(struct uwsgi_spooler *, char *dir);
-#ifdef __linux__
+#if defined __linux__ && !defined __ANDROID__
static void spooler_scandir(struct uwsgi_spooler *, char *dir);
#endif
static void spooler_manage_task(struct uwsgi_spooler *, char *, char *);
@@ -439,7 +439,7 @@
}
if (uwsgi.spooler_ordered) {
-#ifdef __linux__
+#if defined __linux__ && !defined __ANDROID__
spooler_scandir(uspool, NULL);
#else
spooler_readdir(uspool, NULL);
@@ -472,7 +472,7 @@
}
}
-#ifdef __linux__
+#if defined __linux__ && !defined __ANDROID__
static void spooler_scandir(struct uwsgi_spooler *uspool, char *dir) {
struct dirent **tasklist;
@@ -596,7 +596,7 @@
return;
}
-#ifdef __linux__
+#if defined __linux__ && !defined __ANDROID__
if (S_ISDIR(sf_lstat.st_mode) && uwsgi.spooler_ordered) {
if (chdir(task)) {
uwsgi_error("chdir()");

View File

@ -0,0 +1,29 @@
--- a/core/utils.c
+++ b/core/utils.c
@@ -795,7 +795,7 @@
union semun {
int val;
struct semid_ds *buf;
- ushort *array;
+ unsigned short *array;
} semu;
struct semid_ds sds;
@@ -2402,7 +2402,7 @@
return usl->value;
}
}
- return "/bin/sh";
+ return "@TERMUX_PREFIX@/bin/sh";
}
void uwsgi_exec_command_with_args(char *cmdline) {
@@ -3556,7 +3559,7 @@
int fd = -1;
char *tmpdir = getenv("TMPDIR");
if (!tmpdir) {
- tmpdir = "/tmp";
+ tmpdir = "@TERMUX_PREFIX@/tmp";
}
#ifdef O_TMPFILE
fd = open(tmpdir, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);

View File

@ -0,0 +1,27 @@
--- a/core/uwsgi.c
+++ b/core/uwsgi.c
@@ -1194,6 +1194,7 @@
// in threading mode we need to use the cancel pthread subsystem
void wait_for_threads() {
+#ifndef __ANDROID__
int i, ret;
// on some platform thread cancellation is REALLY flaky
@@ -1243,6 +1244,7 @@
end:
pthread_mutex_unlock(&uwsgi.six_feet_under_lock);
+#endif /* __ANDROID__ */
}
@@ -2718,7 +2720,7 @@
#ifdef __APPLE__
uwsgi_string_new_list(&uwsgi.mime_file, "/etc/apache2/mime.types");
#else
- uwsgi_string_new_list(&uwsgi.mime_file, "/etc/mime.types");
+ uwsgi_string_new_list(&uwsgi.mime_file, "@TERMUX_PREFIX@/etc/mime.types");
#endif
struct uwsgi_string_list *umd = uwsgi.mime_file;
while (umd) {

View File

@ -0,0 +1,11 @@
--- a/plugins/corerouter/corerouter.c
+++ b/plugins/corerouter/corerouter.c
@@ -722,7 +722,7 @@
if (!ucr->pb_base_dir) {
ucr->pb_base_dir = getenv("TMPDIR");
if (!ucr->pb_base_dir)
- ucr->pb_base_dir = "/tmp";
+ ucr->pb_base_dir = "@TERMUX_PREFIX@/tmp";
}
int nevents;

View File

@ -0,0 +1,11 @@
--- a/plugins/router_basicauth/router_basicauth.c
+++ b/plugins/router_basicauth/router_basicauth.c
@@ -5,7 +5,7 @@
// TODO: Add more crypt_r supported platfroms here
#if defined(__linux__) && defined(__GLIBC__)
#include <crypt.h>
-#elif defined(__CYGWIN__)
+#elif defined(__CYGWIN__) || defined(__ANDROID__)
#include <crypt.h>
pthread_mutex_t ur_basicauth_crypt_mutex;
#else

79
packages/uwsgi/sys_sem.c Normal file
View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <linux/sem.h>
#include <stdarg.h>
#include <sys/syscall.h>
#include <unistd.h>
#pragma GCC visibility push(hidden)
int semtimedop(int id, struct sembuf* ops, size_t op_count, const struct timespec* ts) {
#if defined(SYS_semtimedop)
return syscall(SYS_semtimedop, id, ops, op_count, ts);
#else
return syscall(SYS_ipc, SEMTIMEDOP, id, op_count, 0, ops, ts);
#endif
}
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
} semu;
int semctl(int id, int num, int cmd, ...) {
#if !defined(__LP64__)
// Annoyingly, the kernel requires this for 32-bit but rejects it for 64-bit.
cmd |= IPC_64;
#endif
va_list ap;
va_start(ap, cmd);
union semun arg = va_arg(ap, union semun);
va_end(ap);
#if defined(SYS_semctl)
return syscall(SYS_semctl, id, num, cmd, arg);
#else
return syscall(SYS_ipc, SEMCTL, id, num, cmd, &arg, 0);
#endif
}
int semget(key_t key, int n, int flags) {
#if defined(SYS_semget)
return syscall(SYS_semget, key, n, flags);
#else
return syscall(SYS_ipc, SEMGET, key, n, flags, 0, 0);
#endif
}
int semop(int id, struct sembuf* ops, size_t op_count) {
return semtimedop(id, ops, op_count, NULL);
}
#pragma GCC visibility pop

58
packages/uwsgi/sys_time.c Normal file
View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#pragma GCC visibility push(hidden)
int timespec_from_timeval(struct timespec ts, const struct timeval tv) {
// Whole seconds can just be copied.
ts.tv_sec = tv.tv_sec;
// But we might overflow when converting microseconds to nanoseconds.
if (tv.tv_usec >= 1000000 || tv.tv_usec < 0) {
return 0;
}
ts.tv_nsec = tv.tv_usec * 1000;
return 1;
}
int futimes(int fd, const struct timeval tv[2]) {
struct timespec ts[2];
if (tv && (!timespec_from_timeval(ts[0], tv[0]) || !timespec_from_timeval(ts[1], tv[1]))) {
errno = EINVAL;
return -1;
}
return futimens(fd, tv ? ts : NULL);
}
#pragma GCC visibility pop

View File

@ -0,0 +1,107 @@
https://github.com/unbit/uwsgi/commit/8c890c84604a0477b46a66eab8a620733f596cc8
diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c
index a63c375b..d8ab6fe3 100644
--- a/plugins/python/pyloader.c
+++ b/plugins/python/pyloader.c
@@ -757,25 +757,15 @@ PyObject *uwsgi_eval_loader(void *arg1) {
PyObject *wsgi_eval_module, *wsgi_eval_callable = NULL;
- struct _node *wsgi_eval_node = NULL;
PyObject *wsgi_compiled_node;
- wsgi_eval_node = PyParser_SimpleParseString(code, Py_file_input);
- if (!wsgi_eval_node) {
- PyErr_Print();
- uwsgi_log( "failed to parse <eval> code\n");
- exit(UWSGI_FAILED_APP_CODE);
- }
-
- wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
-
+ wsgi_compiled_node = Py_CompileString(code, "uwsgi_eval_config", Py_file_input);
if (!wsgi_compiled_node) {
PyErr_Print();
uwsgi_log( "failed to compile eval code\n");
exit(UWSGI_FAILED_APP_CODE);
}
-
wsgi_eval_module = PyImport_ExecCodeModule("uwsgi_eval_config", wsgi_compiled_node);
if (!wsgi_eval_module) {
PyErr_Print();
diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c
index 37d0b7bb..79f29d43 100644
--- a/plugins/python/python_plugin.c
+++ b/plugins/python/python_plugin.c
@@ -473,8 +473,7 @@ UWSGI_RELEASE_GIL
PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
- FILE *pyfile;
- struct _node *py_file_node = NULL;
+ char *pycontent;
PyObject *py_compiled_node, *py_file_module;
int is_a_package = 0;
struct stat pystat;
@@ -483,7 +482,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
if (!uwsgi_check_scheme(filename)) {
- pyfile = fopen(filename, "r");
+ FILE *pyfile = fopen(filename, "r");
if (!pyfile) {
uwsgi_log("failed to open python file %s\n", filename);
return NULL;
@@ -507,37 +506,32 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
}
}
- py_file_node = PyParser_SimpleParseFile(pyfile, real_filename, Py_file_input);
- if (!py_file_node) {
- PyErr_Print();
- uwsgi_log("failed to parse file %s\n", real_filename);
- if (is_a_package)
+ fclose(pyfile);
+ pycontent = uwsgi_simple_file_read(real_filename);
+
+ if (!pycontent) {
+ if (is_a_package) {
free(real_filename);
- fclose(pyfile);
+ }
+ uwsgi_log("no data read from file %s\n", real_filename);
return NULL;
}
- fclose(pyfile);
}
else {
size_t pycontent_size = 0;
- char *pycontent = uwsgi_open_and_read(filename, &pycontent_size, 1, NULL);
+ pycontent = uwsgi_open_and_read(filename, &pycontent_size, 1, NULL);
- if (pycontent) {
- py_file_node = PyParser_SimpleParseString(pycontent, Py_file_input);
- if (!py_file_node) {
- PyErr_Print();
- uwsgi_log("failed to parse url %s\n", real_filename);
- return NULL;
- }
+ if (!pycontent) {
+ uwsgi_log("no data read from url %s\n", real_filename);
+ return NULL;
}
}
- py_compiled_node = (PyObject *) PyNode_Compile(py_file_node, real_filename);
-
+ py_compiled_node = Py_CompileString(pycontent, real_filename, Py_file_input);
if (!py_compiled_node) {
PyErr_Print();
- uwsgi_log("failed to compile python file %s\n", real_filename);
+ uwsgi_log("failed to compile %s\n", real_filename);
return NULL;
}

View File

@ -0,0 +1,31 @@
--- a/uwsgi.h
+++ b/uwsgi.h
@@ -209,7 +209,7 @@
#endif
#include <sys/ipc.h>
-#include <sys/sem.h>
+#include <linux/sem.h>
#include <stdarg.h>
#include <errno.h>
@@ -4967,6 +4967,19 @@
int uwsgi_wait_for_mountpoint(char *);
int uwsgi_wait_for_socket(char *);
+#ifdef __ANDROID__
+#define pivot_root(new_root, put_old) (-1)
+#define pthread_setcancelstate(state, oldstate) (-1)
+#define pthread_setcanceltype(type, oldtype) (-1)
+#if __ANDROID_API__ < 26
+int futimes(int, const struct timeval[2]);
+#endif
+#define semid_ds semid64_ds
+int semctl(int, int, int, ...);
+int semget(key_t, int, int);
+int semop(int, struct sembuf *, size_t);
+#endif
+
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,88 @@
--- a/uwsgiconfig.py
+++ b/uwsgiconfig.py
@@ -670,7 +670,7 @@
'core/setup_utils', 'core/clock', 'core/init', 'core/buffer', 'core/reader', 'core/writer', 'core/alarm', 'core/cron', 'core/hooks',
'core/plugins', 'core/lock', 'core/cache', 'core/daemons', 'core/errors', 'core/hash', 'core/master_events', 'core/chunked',
'core/queue', 'core/event', 'core/signal', 'core/strings', 'core/progress', 'core/timebomb', 'core/ini', 'core/fsmon', 'core/mount',
- 'core/metrics', 'core/plugins_builder', 'core/sharedarea',
+ 'core/metrics', 'core/plugins_builder', 'core/sharedarea', 'core/sys_sem', 'core/sys_time',
'core/rpc', 'core/gateway', 'core/loop', 'core/cookie', 'core/querystring', 'core/rb_timers', 'core/transformations', 'core/uwsgi']
# add protocols
self.gcc_list.append('proto/base')
@@ -725,7 +725,7 @@
if not self.include_path:
raise
except:
- self.include_path = ['/usr/include', '/usr/local/include']
+ self.include_path = []
additional_include_paths = self.get('additional_include_paths')
if additional_include_paths:
@@ -762,7 +762,7 @@
self.cflags.append('-Wno-format -Wno-format-security')
self.ldflags = os.environ.get("LDFLAGS", "").split()
- self.libs = ['-lpthread', '-lm', '-rdynamic']
+ self.libs = ['-lm', '-rdynamic']
if uwsgi_os in ('Linux', 'GNU', 'GNU/kFreeBSD'):
self.libs.append('-ldl')
if uwsgi_os == 'GNU/kFreeBSD':
@@ -1079,23 +1079,23 @@
# re-enable after pcre fix
if self.get('pcre'):
if self.get('pcre') == 'auto':
- pcreconf = spcall('pcre-config --libs')
+ pcreconf = spcall('sh @TERMUX_PREFIX@/bin/pcre-config --libs')
if pcreconf:
self.libs.append(pcreconf)
- pcreconf = spcall("pcre-config --cflags")
+ pcreconf = spcall("sh @TERMUX_PREFIX@/bin/pcre-config --cflags")
self.cflags.append(pcreconf)
self.gcc_list.append('core/regexp')
self.cflags.append("-DUWSGI_PCRE")
has_pcre = True
else:
- pcreconf = spcall('pcre-config --libs')
+ pcreconf = spcall('sh @TERMUX_PREFIX@/bin/pcre-config --libs')
if pcreconf is None:
print("*** libpcre headers unavailable. uWSGI build is interrupted. You have to install pcre development package or disable pcre")
sys.exit(1)
else:
self.libs.append(pcreconf)
- pcreconf = spcall("pcre-config --cflags")
+ pcreconf = spcall("sh @TERMUX_PREFIX@/bin/pcre-config --cflags")
self.cflags.append(pcreconf)
self.gcc_list.append('core/regexp')
self.cflags.append("-DUWSGI_PCRE")
@@ -1123,7 +1123,7 @@
if self.has_include('uuid/uuid.h'):
self.cflags.append("-DUWSGI_UUID")
- if uwsgi_os in ('Linux', 'GNU', 'GNU/kFreeBSD') or uwsgi_os.startswith('CYGWIN') or os.path.exists('/usr/lib/libuuid.so') or os.path.exists('/usr/local/lib/libuuid.so') or os.path.exists('/usr/lib64/libuuid.so') or os.path.exists('/usr/local/lib64/libuuid.so'):
+ if uwsgi_os in ('Linux', 'GNU', 'GNU/kFreeBSD') or uwsgi_os.startswith('CYGWIN') or os.path.exists('@TERMUX_PREFIX@/lib/libuuid.so'):
self.libs.append('-luuid')
if self.get('append_version'):
@@ -1310,10 +1310,10 @@
if self.get('xml'):
if self.get('xml') == 'auto':
- xmlconf = spcall('xml2-config --libs')
+ xmlconf = spcall('sh @TERMUX_PREFIX@/bin/xml2-config --libs')
if xmlconf and uwsgi_os != 'Darwin':
self.libs.append(xmlconf)
- xmlconf = spcall("xml2-config --cflags")
+ xmlconf = spcall("sh @TERMUX_PREFIX@/bin/xml2-config --cflags")
self.cflags.append(xmlconf)
self.cflags.append("-DUWSGI_XML -DUWSGI_XML_LIBXML2")
self.gcc_list.append('core/xmlconf')
@@ -1324,7 +1324,7 @@
self.gcc_list.append('core/xmlconf')
report['xml'] = 'expat'
elif self.get('xml') == 'libxml2':
- xmlconf = spcall('xml2-config --libs')
+ xmlconf = spcall('sh @TERMUX_PREFIX@/bin/xml2-config --libs')
if xmlconf is None:
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
sys.exit(1)