Skip to content

Commit 188d88e

Browse files
committed
Refactor FPM checks
1 parent 2e5a801 commit 188d88e

File tree

5 files changed

+201
-229
lines changed

5 files changed

+201
-229
lines changed

cmake/cmake/modules/PHP/CheckClockGettime.cmake

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#[=============================================================================[
2-
Check for items required by listening queue implemented in FPM.
2+
Check FPM listening queue implementation.
33
4-
Cache variables:
4+
## Cache variables
55
66
* `HAVE_LQ_TCP_INFO`
7+
78
Whether `TCP_INFO` is present.
9+
810
* `HAVE_LQ_TCP_CONNECTION_INFO`
11+
912
Whether `TCP_CONNECTION_INFO` is present.
13+
1014
* `HAVE_LQ_SO_LISTENQ`
15+
1116
Whether `SO_LISTENQLEN` and `SO_LISTENQLIMIT` are available as alternative to
1217
`TCP_INFO` and `TCP_CONNECTION_INFO`.
1318
#]=============================================================================]
@@ -18,7 +23,8 @@ include(CheckSourceCompiles)
1823
include(CMakePushCheckState)
1924
include(PHP/SystemExtensions)
2025

21-
message(CHECK_START "Checking for TCP_INFO")
26+
message(CHECK_START "Checking FPM listening queue implementation")
27+
2228
cmake_push_check_state(RESET)
2329
# Requires _DEFAULT_SOURCE, which is enabled by _GNU_SOURCE.
2430
set(CMAKE_REQUIRED_LIBRARIES PHP::SystemExtensions)
@@ -36,36 +42,26 @@ cmake_push_check_state(RESET)
3642
}
3743
]] HAVE_LQ_TCP_INFO)
3844
cmake_pop_check_state()
39-
if(HAVE_LQ_TCP_INFO)
40-
message(CHECK_PASS "yes")
41-
else()
42-
message(CHECK_FAIL "no")
43-
endif()
4445

4546
# For macOS.
46-
message(CHECK_START "Checking for TCP_CONNECTION_INFO")
47-
check_source_compiles(C [[
48-
#include <netinet/tcp.h>
49-
50-
int main(void)
51-
{
52-
struct tcp_connection_info ti;
53-
int x = TCP_CONNECTION_INFO;
54-
(void)ti;
55-
(void)x;
56-
57-
return 0;
58-
}
59-
]] HAVE_LQ_TCP_CONNECTION_INFO)
60-
if(HAVE_LQ_TCP_CONNECTION_INFO)
61-
message(CHECK_PASS "yes")
62-
else()
63-
message(CHECK_FAIL "no")
47+
if(NOT HAVE_LQ_TCP_INFO)
48+
check_source_compiles(C [[
49+
#include <netinet/tcp.h>
50+
51+
int main(void)
52+
{
53+
struct tcp_connection_info ti;
54+
int x = TCP_CONNECTION_INFO;
55+
(void)ti;
56+
(void)x;
57+
58+
return 0;
59+
}
60+
]] HAVE_LQ_TCP_CONNECTION_INFO)
6461
endif()
6562

6663
# For FreeBSD.
67-
if(NOT HAVE_LQ_TCP_INFO AND NOT HAVE_LQ_TCP_CONNECTION_INFO)
68-
message(CHECK_START "Checking for SO_LISTENQLEN and SO_LISTENQLIMIT")
64+
if(NOT HAVE_LQ_TCP_INFO AND NOT HAVE_LQ_TCP_INFO)
6965
check_source_compiles(C [[
7066
#include <sys/socket.h>
7167

@@ -79,9 +75,10 @@ if(NOT HAVE_LQ_TCP_INFO AND NOT HAVE_LQ_TCP_CONNECTION_INFO)
7975
return 0;
8076
}
8177
]] HAVE_LQ_SO_LISTENQ)
82-
if(HAVE_LQ_SO_LISTENQ)
83-
message(CHECK_PASS "yes")
84-
else()
85-
message(CHECK_FAIL "no")
86-
endif()
78+
endif()
79+
80+
if(HAVE_LQ_TCP_INFO OR HAVE_LQ_TCP_CONNECTION_INFO OR HAVE_LQ_SO_LISTENQ)
81+
message(CHECK_PASS "found")
82+
else()
83+
message(CHECK_FAIL "not found, FPM listening queue is disabled")
8784
endif()

cmake/cmake/modules/PHP/CheckPtrace.cmake

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[=============================================================================[
2-
Check for ptrace().
2+
Check FPM trace implementation.
33
44
## Cache variables:
55
@@ -26,6 +26,8 @@ include(CheckSourceRuns)
2626
include(CheckSymbolExists)
2727
include(CMakePushCheckState)
2828

29+
message(CHECK_START "Checking FPM trace implementation")
30+
2931
message(CHECK_START "Checking whether ptrace works")
3032

3133
cmake_push_check_state(RESET)
@@ -118,70 +120,77 @@ endif()
118120

119121
if(HAVE_PTRACE)
120122
message(CHECK_PASS "yes")
121-
return()
123+
else()
124+
message(CHECK_FAIL "no")
122125
endif()
123-
message(CHECK_FAIL "no")
124-
125-
check_symbol_exists(mach_vm_read "mach/mach.h;mach/mach_vm.h" HAVE_MACH_VM_READ)
126126

127-
if(HAVE_MACH_VM_READ)
128-
return()
127+
if(NOT HAVE_PTRACE)
128+
check_symbol_exists(mach_vm_read "mach/mach.h;mach/mach_vm.h" HAVE_MACH_VM_READ)
129129
endif()
130130

131-
message(CHECK_START "Checking for process memory access file")
131+
if(NOT HAVE_PTRACE AND NOT HAVE_MACH_VM_READ)
132+
message(CHECK_START "Checking for process memory access file")
132133

133-
if(NOT CMAKE_CROSSCOMPILING)
134-
set(PROC_MEM_FILE)
135-
if(EXISTS /proc/self/mem)
136-
set(PROC_MEM_FILE "mem")
137-
elseif(EXISTS /proc/self/as)
138-
set(PROC_MEM_FILE "as")
139-
endif()
134+
if(NOT CMAKE_CROSSCOMPILING)
135+
set(PROC_MEM_FILE)
136+
if(EXISTS /proc/self/mem)
137+
set(PROC_MEM_FILE "mem")
138+
elseif(EXISTS /proc/self/as)
139+
set(PROC_MEM_FILE "as")
140+
endif()
140141

141-
if(PROC_MEM_FILE)
142-
cmake_push_check_state(RESET)
143-
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
144-
set(CMAKE_REQUIRED_QUIET TRUE)
145-
check_source_runs(C "
146-
#define _FILE_OFFSET_BITS 64
147-
#include <stdint.h>
148-
#include <unistd.h>
149-
#include <sys/types.h>
150-
#include <sys/stat.h>
151-
#include <fcntl.h>
152-
#include <stdio.h>
153-
154-
int main(void)
155-
{
156-
long v1 = (unsigned int) -1, v2 = 0;
157-
char buf[128];
158-
int fd;
159-
sprintf(buf, \"/proc/%d/${PROC_MEM_FILE}\", getpid());
160-
fd = open(buf, O_RDONLY);
161-
if (0 > fd) {
162-
return 1;
163-
}
164-
if (sizeof(long) != pread(fd, &v2, sizeof(long), (uintptr_t) &v1)) {
142+
if(PROC_MEM_FILE)
143+
cmake_push_check_state(RESET)
144+
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
145+
set(CMAKE_REQUIRED_QUIET TRUE)
146+
check_source_runs(C "
147+
#define _FILE_OFFSET_BITS 64
148+
#include <stdint.h>
149+
#include <unistd.h>
150+
#include <sys/types.h>
151+
#include <sys/stat.h>
152+
#include <fcntl.h>
153+
#include <stdio.h>
154+
155+
int main(void)
156+
{
157+
long v1 = (unsigned int) -1, v2 = 0;
158+
char buf[128];
159+
int fd;
160+
sprintf(buf, \"/proc/%d/${PROC_MEM_FILE}\", getpid());
161+
fd = open(buf, O_RDONLY);
162+
if (0 > fd) {
163+
return 1;
164+
}
165+
if (sizeof(long) != pread(fd, &v2, sizeof(long), (uintptr_t) &v1)) {
166+
close(fd);
167+
return 1;
168+
}
165169
close(fd);
166-
return 1;
170+
return v1 != v2;
167171
}
168-
close(fd);
169-
return v1 != v2;
170-
}
171-
" _HAVE_PROC_MEM_FILE)
172-
cmake_pop_check_state()
172+
" _HAVE_PROC_MEM_FILE)
173+
cmake_pop_check_state()
173174

174-
if(NOT _HAVE_PROC_MEM_FILE)
175-
unset(PROC_MEM_FILE)
175+
if(NOT _HAVE_PROC_MEM_FILE)
176+
unset(PROC_MEM_FILE)
177+
endif()
176178
endif()
177179
endif()
178-
endif()
179180

180-
if(PROC_MEM_FILE)
181-
message(CHECK_PASS "yes (${PROC_MEM_FILE})")
182-
return()
181+
if(PROC_MEM_FILE)
182+
message(CHECK_PASS "yes (${PROC_MEM_FILE})")
183+
else()
184+
message(CHECK_FAIL "no")
185+
endif()
183186
endif()
184187

185-
message(CHECK_FAIL "no")
186-
187-
message(WARNING "FPM trace - ptrace, pread, or mach: could not be found")
188+
if(HAVE_PTRACE)
189+
message(CHECK_PASS "found (ptrace)")
190+
elseif(HAVE_MACH_VM_READ)
191+
message(CHECK_PASS "found (mach)")
192+
elseif(PROC_MEM_FILE)
193+
message(CHECK_PASS "found (pread)")
194+
else()
195+
message(CHECK_FAIL "not found, FPM trace implementation is disabled")
196+
endif()

cmake/cmake/toolchains/template.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ set(ZEND_MM_EXITCODE 0)
6868
set(ZEND_MM_EXITCODE__TRYRUN_OUTPUT "(size_t)8 (size_t)3 0")
6969

7070
################################################################################
71-
# FPM SAPI
71+
# sapi/fpm
7272
################################################################################
7373

7474
# Set the exit code for the clock_get_time() check.

0 commit comments

Comments
 (0)