standard/syslog: the request shutdown hook calls closelog() even when the request never opened syslog
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 62/100
Línea de trabajo
El cierre incondicional está en PHP_RSHUTDOWN_FUNCTION(syslog) en ext/standard/syslog.c. Lee php_closelog() y la bandera PG(have_called_openlog) en main/php_syslog.c (alrededor de las líneas 74-84), y el reinicio en main/main.c cerca de la línea 2317. Está terminado cuando una solicitud que nunca llama a openlog, closelog o syslog omite php_closelog() y aun así libera BG(syslog_device). Compruébalo con strace sobre varias solicitudes en un SAPI de múltiples solicitudes, como muestra el issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
ext/standard/syslog.c installs an unconditional request shutdown hook:
PHP_RSHUTDOWN_FUNCTION(syslog)
{
php_closelog();
if (BG(syslog_device)) {
free(BG(syslog_device));
BG(syslog_device) = NULL;
}
return SUCCESS;
}
php_closelog() runs after every request, whether or not this request opened syslog. In a SAPI that serves more than one request per process, that closes a process-wide handle the request may not own, and the next request opens it again.
Note that the state to avoid this already exists: php_openlog() sets PG(have_called_openlog) = 1 and php_closelog() clears it (main/php_syslog.c:74-84), and php_module_startup() resets it to 0 (main/main.c:2317). The shutdown hook simply does not look at it.
Expected
A request that never calls openlog(), closelog() or syslog() should leave the process syslog handle alone. If the handle was opened outside PHP, for example by the embedding application or by a library in the same process, PHP should not close it.
Actual
Embedded SAPI, PHP 8.5.11 (Alpine 3.24.2, musl 1.2.6, OpenSSL 3.5.9), one worker process serving three requests with error_log = syslog and a script that only calls error_log("request"). strace of the worker:
1080 connect(15, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(15, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
1080 connect(14, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(14, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
1080 connect(14, {sa_family=AF_UNIX, sun_path="/dev/log"}, 12) = 0
1080 sendto(14, "<13>Oct 13 21:57:46 php: request\n", 33, 0, NULL, 0) = 33
Three requests, three connects: the handle does not survive a request boundary. In the same process, a host that opened syslog before running PHP loses it when the first request ends. php-fpm works around this by calling php_closelog() itself when it takes over the child, with the comment "ensure to close syslog not to interrupt with PHP syslog code" (sapi/fpm/fpm/fpm_stdio.c:144), which is the same interaction seen from the other side.
Suggested fix
Check the existing flag before closing:
PHP_RSHUTDOWN_FUNCTION(syslog)
{
if (PG(have_called_openlog)) {
php_closelog();
}
...
}
That keeps the per-request BG(syslog_device) cleanup, closes the handle when this request opened it, and leaves a host-owned handle alone.
Version
PHP 8.5.11, and the same code is in the current PHP-8.5 and master branches.
- Lenguaje dominante
- C
- Estrellas
- 40.4k
- Forks
- 8.2k
- Merge medio
- 2 d 24 min
- PR fusionados (30 d)
- 157
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de php/php-src
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
php/php-src#24196 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Feature Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
php/php-src#24183 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Sockets from synchronous stream_socket_client() are left in non-blocking mode on WindowsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoBug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
sapi_lsapi_ub_write does not return bytes written in lsapi modePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoBug Status: Needs Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
Bug Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de php/php-src
Issues similares
-
chore: update release scheduleAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 4 días
-
foomatic-rip: dstrtrim_right() underflows mid-loop on an all-whitespace stringPosiblemente ocupada @ManasBagul23 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
OpenPrinting/cups-filters#759 ·
Los mantenedores suelen responder en 11 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
EchoTools/nevr-runtime#547 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
enhancement help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
kabirvashisht4-glitch/Vet#22 ·