From 2fc06c56dab4bfb94edc5f641dbdf532295a8e4b Mon Sep 17 00:00:00 2001 From: Alexandre Rossi Date: Tue, 7 Nov 2023 14:46:45 +0100 Subject: [PATCH 01/12] properly init cache for purge_lru Purging the least recently used cache item relies on a linked list maintained during cache get and set. While uwsgi is running, this works well. But if the uwsgi process is stopped, lru_head and lru_tail are not initialized when loading the existing cache file. As a consequence, least recently used items never get deleted a full cache fails to set any new keys until the cache file is deleted. This patch properly initializes those variables. --- core/cache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/cache.c b/core/cache.c index 93da38dfb..661320bf4 100644 --- a/core/cache.c +++ b/core/cache.c @@ -737,6 +737,12 @@ void uwsgi_cache_fix(struct uwsgi_cache *uc) { if (uci->expires && (!next_scan || next_scan > uci->expires)) { next_scan = uci->expires; } + if (!uc->lru_head && !uci->lru_prev) { + uc->lru_head = i; + } + if (!uc->lru_tail && !uci->lru_next) { + uc->lru_tail = i; + } restored++; } else { From 88b3d309894a7c5fb4eb3234fd233e610471b89d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 13 Nov 2023 09:20:20 +0100 Subject: [PATCH 02/12] use libphp on PHP 8+, else libphp7 --- plugins/php/uwsgiplugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/php/uwsgiplugin.py b/plugins/php/uwsgiplugin.py index d930c44eb..492926023 100644 --- a/plugins/php/uwsgiplugin.py +++ b/plugins/php/uwsgiplugin.py @@ -21,7 +21,12 @@ LDFLAGS.append('-L%s' % ld_run_path) os.environ['LD_RUN_PATH'] = ld_run_path -LIBS = [os.popen(PHPPATH + ' --libs').read().rstrip(), '-lphp' + php_version] +# PHP8 and above does not add the version to the library +# name +if int(php_version) < 8: + LIBS = [os.popen(PHPPATH + ' --libs').read().rstrip(), '-lphp' + php_version] +else: + LIBS = [os.popen(PHPPATH + ' --libs').read().rstrip(), '-lphp'] phplibdir = os.environ.get('UWSGICONFIG_PHPLIBDIR') if phplibdir: From b95f7a268c457cf078bb9daa8e24adef03f42d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Thu, 23 Nov 2023 15:45:40 +0100 Subject: [PATCH 03/12] Remove unused variables due to compilation failure --- core/ini.c | 3 --- core/yaml.c | 2 -- 2 files changed, 5 deletions(-) diff --git a/core/ini.c b/core/ini.c index 770819cb9..bb7587157 100644 --- a/core/ini.c +++ b/core/ini.c @@ -87,8 +87,6 @@ void uwsgi_ini_config(char *file, char *magic_table[]) { char *key; char *val; - int lines = 1; - char *section_asked = "uwsgi"; char *colon; int got_section = 0; @@ -130,7 +128,6 @@ void uwsgi_ini_config(char *file, char *magic_table[]) { if (ini_line == NULL) { break; } - lines++; // skip empty line key = ini_lstrip(ini); diff --git a/core/yaml.c b/core/yaml.c index 869c4dc45..c95b5d92a 100644 --- a/core/yaml.c +++ b/core/yaml.c @@ -211,7 +211,6 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) { #else int depth; int current_depth = 0; - int lines = 1; char *yaml_line; char *section = ""; @@ -221,7 +220,6 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) { if (yaml_line == NULL) { break; } - lines++; // skip empty line if (yaml[0] == 0) From f47557f921f665745cd1c530effce013e7a72189 Mon Sep 17 00:00:00 2001 From: Shai Bentov Date: Thu, 7 Dec 2023 09:48:50 -0700 Subject: [PATCH 04/12] core: use right type for harakiri --- core/master_checks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/master_checks.c b/core/master_checks.c index 289daa686..6732db15b 100644 --- a/core/master_checks.c +++ b/core/master_checks.c @@ -180,7 +180,7 @@ void uwsgi_master_check_idle() { } -int uwsgi_master_check_harakiri(int w, int c, int harakiri) { +int uwsgi_master_check_harakiri(int w, int c, time_t harakiri) { /** * Triggers a harakiri when the following conditions are met: * - harakiri timeout > current time From b75e072cc657b09de56b44aff5d451def5691933 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 26 Dec 2023 11:45:53 +0100 Subject: [PATCH 05/12] core/master: fix socket queue stats for ipv6 It looks like the code works fine with ipv6 too so enable it. Fix #2577 --- core/master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/master.c b/core/master.c index 7a4b4010c..44d94e26f 100644 --- a/core/master.c +++ b/core/master.c @@ -253,7 +253,7 @@ static void master_check_listen_queue() { uint64_t backlog = 0; struct uwsgi_socket *uwsgi_sock = uwsgi.sockets; while(uwsgi_sock) { - if (uwsgi_sock->family == AF_INET) { + if (uwsgi_sock->family == AF_INET || uwsgi_sock->family == AF_INET6) { get_tcp_info(uwsgi_sock); } #ifdef __linux__ From 02df5fb5f2f5249eb883bff7f9a1e436c2fd41d7 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 26 Dec 2023 12:13:09 +0100 Subject: [PATCH 06/12] core/logging: fixup -Wformat-signedness warnings --- core/logging.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/logging.c b/core/logging.c index eb8cfaaee..a5ae67cff 100644 --- a/core/logging.c +++ b/core/logging.c @@ -707,7 +707,7 @@ void uwsgi_logit_simple(struct wsgi_request *wsgi_req) { } if (uwsgi.logging_options.memory_report == 1) { - rlen = snprintf(mempkt, 4096, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024, + rlen = snprintf(mempkt, 4096, "{address space usage: %llu bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024, (unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024); logvec[logvecpos].iov_base = mempkt; logvec[logvecpos].iov_len = rlen; @@ -749,7 +749,7 @@ void get_memusage(uint64_t * rss, uint64_t * vsz) { int i; procfile = fopen("/proc/self/stat", "r"); if (procfile) { - i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %lld", (unsigned long long *) vsz, (unsigned long long *) rss); + i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %llu", (unsigned long long *) vsz, (unsigned long long *) rss); if (i != 2) { uwsgi_log("warning: invalid record in /proc/self/stat\n"); } else { @@ -763,7 +763,7 @@ void get_memusage(uint64_t * rss, uint64_t * vsz) { int i; procfile = fopen("/proc/self/stat", "r"); if (procfile) { - i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %lld", (unsigned long long *) vsz, (unsigned long long *) rss); + i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %llu", (unsigned long long *) vsz, (unsigned long long *) rss); if (i != 2) { uwsgi_log("warning: invalid record in /proc/self/stat\n"); } From 22486bf17ea7b8b32e9947c33896c59f8937b1ca Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 26 Dec 2023 13:44:34 +0100 Subject: [PATCH 07/12] core/utils: use unsigned values in uwsgi_uuid --- core/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils.c b/core/utils.c index 947c7c47e..26e56aac1 100644 --- a/core/utils.c +++ b/core/utils.c @@ -4048,7 +4048,7 @@ void uwsgi_uuid(char *buf) { uuid_generate(uuid_value); uuid_unparse(uuid_value, buf); #else - int i, r[11]; + unsigned int i, r[11]; if (!uwsgi_file_exists("/dev/urandom")) goto fallback; int fd = open("/dev/urandom", O_RDONLY); @@ -4064,7 +4064,7 @@ void uwsgi_uuid(char *buf) { goto done; fallback: for (i = 0; i < 11; i++) { - r[i] = rand(); + r[i] = (unsigned int) rand(); } done: snprintf(buf, 37, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10]); From 043f4ddf445a79b38ac7a8463a6b89abb92615a6 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 28 Dec 2023 11:53:45 +0100 Subject: [PATCH 08/12] uwsgiconfig: add -Wformat-signedness --- uwsgiconfig.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 968690d39..620067726 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -683,8 +683,14 @@ def __init__(self, filename, mute=False): if 'UWSGI_INCLUDES' in os.environ: self.include_path += os.environ['UWSGI_INCLUDES'].split(',') - - self.cflags = ['-O2', '-I.', '-Wall', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split() + self.get('cflags','').split() + self.cflags = [ + '-O2', + '-I.', + '-Wall', + '-Wformat-signedness', + '-D_LARGEFILE_SOURCE', + '-D_FILE_OFFSET_BITS=64' + ] + os.environ.get("CFLAGS", "").split() + self.get('cflags', '').split() report['kernel'] = uwsgi_os From dd43a73445f6e35c09e12f63d4554aa9f500efa2 Mon Sep 17 00:00:00 2001 From: Ben Kallus Date: Mon, 1 Jan 2024 13:00:39 -0500 Subject: [PATCH 09/12] Avoid strncpy from null in pyloader --- plugins/python/pyloader.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 8e632ec0f..78f14195a 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -97,7 +97,9 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre memset(wi, 0, sizeof(struct uwsgi_app)); wi->modifier1 = python_plugin.modifier1; wi->mountpoint_len = wsgi_req->appid_len < 0xff ? wsgi_req->appid_len : (0xff-1); - strncpy(wi->mountpoint, wsgi_req->appid, wi->mountpoint_len); + if (wi->mountpoint_len > 0) { + strncpy(wi->mountpoint, wsgi_req->appid, wi->mountpoint_len); + } // dynamic chdir ? if (wsgi_req->chdir_len > 0) { From 2cfd89d9db42cf9ec2180807823848de022ba149 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 8 Feb 2024 16:55:37 +0100 Subject: [PATCH 10/12] uwsgiconfig: make -Wformat-signedness conditional on gcc Since it's not available on clang. Fix #2602 --- uwsgiconfig.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 620067726..89d135dbf 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -683,14 +683,16 @@ def __init__(self, filename, mute=False): if 'UWSGI_INCLUDES' in os.environ: self.include_path += os.environ['UWSGI_INCLUDES'].split(',') - self.cflags = [ + cflags = [ '-O2', '-I.', '-Wall', - '-Wformat-signedness', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64' - ] + os.environ.get("CFLAGS", "").split() + self.get('cflags', '').split() + ] + if "gcc" in GCC: + cflags.append('-Wformat-signedness') + self.cflags = cflags + os.environ.get("CFLAGS", "").split() + self.get('cflags', '').split() report['kernel'] = uwsgi_os From bb1a721da9ab93edc0212a3e3cbc80294f277f1d Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 8 Feb 2024 17:02:02 +0100 Subject: [PATCH 11/12] ci: add clang to compile test matrix Add a default build of uwsgi with clang, cannot do the travis profile because at least perl headers don't compile. --- .github/workflows/compile-test.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/compile-test.yml b/.github/workflows/compile-test.yml index 2a05e3495..d78edc9b9 100644 --- a/.github/workflows/compile-test.yml +++ b/.github/workflows/compile-test.yml @@ -14,9 +14,15 @@ jobs: - os: ubuntu-20.04 php: "php7.4" php-config: "php-config7.4" + cc: "gcc" - os: ubuntu-22.04 php: "php8.1" php-config: "php-config8.1" + cc: "gcc" + - os: ubuntu-22.04 + php: "php8.1" + php-config: "php-config8.1" + cc: "clang" runs-on: ${{ matrix.os }} @@ -43,16 +49,16 @@ jobs: libcurl4-openssl-dev \ openjdk-11-jdk libgloox-dev gccgo \ cli-common-dev mono-devel mono-mcs uuid-dev \ - curl check + curl check ${{ matrix.cc == 'clang' && 'clang' || '' }} - uses: actions/checkout@v2 - - name: Build kitchensink uWSGI binary - run: UWSGICONFIG_PHPPATH=${{ matrix.php-config }} /usr/bin/python3 uwsgiconfig.py --build travis + - name: Build kitchensink uWSGI binary with gcc or default with clang + run: CC=${{ matrix.cc }} UWSGICONFIG_PHPPATH=${{ matrix.php-config }} /usr/bin/python3 uwsgiconfig.py --build ${{ matrix.cc == 'gcc' && 'travis' || '' }} - name: Build uWSGI binary run: | - /usr/bin/python3 uwsgiconfig.py --build base + CC=${{ matrix.cc }} /usr/bin/python3 uwsgiconfig.py --build base - name: Build cgi plugin run: | - /usr/bin/python3 uwsgiconfig.py --plugin plugins/cgi base + CC=${{ matrix.cc }} /usr/bin/python3 uwsgiconfig.py --plugin plugins/cgi base - name: Build dummy plugin run: | - /usr/bin/python3 uwsgiconfig.py --plugin plugins/dummy base + CC=${{ matrix.cc }} /usr/bin/python3 uwsgiconfig.py --plugin plugins/dummy base From 0cea1d55da5e87eb70dc8bf648e25e91f9fc243c Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 8 Feb 2024 17:20:29 +0100 Subject: [PATCH 12/12] ci: use actions/checkout@v4 to avoid node versions warnings --- .github/workflows/compile-test.yml | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile-test.yml b/.github/workflows/compile-test.yml index d78edc9b9..d1ec99799 100644 --- a/.github/workflows/compile-test.yml +++ b/.github/workflows/compile-test.yml @@ -50,7 +50,7 @@ jobs: openjdk-11-jdk libgloox-dev gccgo \ cli-common-dev mono-devel mono-mcs uuid-dev \ curl check ${{ matrix.cc == 'clang' && 'clang' || '' }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build kitchensink uWSGI binary with gcc or default with clang run: CC=${{ matrix.cc }} UWSGICONFIG_PHPPATH=${{ matrix.php-config }} /usr/bin/python3 uwsgiconfig.py --build ${{ matrix.cc == 'gcc' && 'travis' || '' }} - name: Build uWSGI binary diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 009d48438..ba0cbbb49 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: if: contains(fromJson('["3.6","3.7","3.8","3.9","3.10","3.11","3.12"]'), matrix.python-version) run: | sudo apt install --no-install-recommends -qqyf python${{ matrix.python-version }}-distutils \ - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Run unit tests if: matrix.test-suite == 'unittest' run: make tests @@ -61,7 +61,7 @@ jobs: sudo apt install --no-install-recommends -qqyf python3-dev \ libpcre3-dev libjansson-dev libcap2-dev ruby2.7-dev \ curl check - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Run unit tests run: make tests - name: Build uWSGI binary