Skip to content

Commit 1cc9346

Browse files
committed
extra pthread handling
unlikely to be needed, but better safe than sorry
1 parent cc8dfa8 commit 1cc9346

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

frankenphp.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ __thread HashTable *sandboxed_env = NULL;
8989

9090
#ifndef PHP_WIN32
9191
static bool is_forked_child = false;
92-
static void frankenphp_fork_child(void) { is_forked_child = true; }
92+
static void frankenphp_fork_child(void) {
93+
is_forked_child = true;
94+
#ifdef __linux__
95+
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
96+
#endif
97+
}
9398
#endif
9499

95100
void frankenphp_update_local_thread_context(bool is_worker) {
@@ -762,6 +767,12 @@ static int frankenphp_startup(sapi_module_struct *sapi_module) {
762767
static int frankenphp_deactivate(void) { return SUCCESS; }
763768

764769
static size_t frankenphp_ub_write(const char *str, size_t str_length) {
770+
#ifndef PHP_WIN32
771+
if (UNEXPECTED(is_forked_child)) {
772+
return 0;
773+
}
774+
#endif
775+
765776
struct go_ub_write_return result =
766777
go_ub_write(thread_index, (char *)str, str_length);
767778

@@ -773,6 +784,12 @@ static size_t frankenphp_ub_write(const char *str, size_t str_length) {
773784
}
774785

775786
static int frankenphp_send_headers(sapi_headers_struct *sapi_headers) {
787+
#ifndef PHP_WIN32
788+
if (UNEXPECTED(is_forked_child)) {
789+
return SAPI_HEADER_SEND_FAILED;
790+
}
791+
#endif
792+
776793
if (SG(request_info).no_headers == 1) {
777794
return SAPI_HEADER_SENT_SUCCESSFULLY;
778795
}
@@ -798,6 +815,12 @@ static int frankenphp_send_headers(sapi_headers_struct *sapi_headers) {
798815
}
799816

800817
static void frankenphp_sapi_flush(void *server_context) {
818+
#ifndef PHP_WIN32
819+
if (UNEXPECTED(is_forked_child)) {
820+
return;
821+
}
822+
#endif
823+
801824
sapi_send_headers();
802825
if (go_sapi_flush(thread_index)) {
803826
php_handle_aborted_connection();

0 commit comments

Comments
 (0)