File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ PHP NEWS
1717 . Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more.
1818 (Martin Mirchev)
1919
20+ - Standard:
21+ . Fixed bug GH-24308 (Request shutdown calls closelog() even when syslog
22+ was not opened by PHP). (lazerg)
23+
2024- Streams:
2125 . Fixed bug GH-24506 (stream_select() leaks a stream-error operation level
2226 on its FD_SETSIZE failure path). (azjezz)
Original file line number Diff line number Diff line change @@ -39,7 +39,9 @@ PHP_MINIT_FUNCTION(syslog)
3939
4040PHP_RSHUTDOWN_FUNCTION (syslog )
4141{
42- php_closelog ();
42+ if (PG (have_called_openlog )) {
43+ php_closelog ();
44+ }
4345 if (BG (syslog_device )) {
4446 free (BG (syslog_device ));
4547 BG (syslog_device ) = NULL ;
@@ -100,6 +102,9 @@ PHP_FUNCTION(syslog)
100102 Z_PARAM_STR (message )
101103 ZEND_PARSE_PARAMETERS_END ();
102104
105+ if (!PG (have_called_openlog )) {
106+ php_openlog (PG (syslog_ident ), 0 , PG (syslog_facility ));
107+ }
103108 php_syslog_str (priority , message );
104109 RETURN_TRUE ;
105110}
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-24308 (syslog() without openlog() is closed at request end)
3+ --SKIPIF--
4+ <?php
5+ if (PHP_OS_FAMILY !== 'Linux ' ) die ('skip Linux only ' );
6+ if (!@is_dir ('/proc/self/fd ' )) die ('skip requires /proc/self/fd ' );
7+ if (!@stream_socket_client ('udg:///dev/log ' )) die ('skip requires /dev/log ' );
8+ ?>
9+ --FILE--
10+ <?php
11+ $ serverCode = <<<'CODE'
12+ function sockets() {
13+ $sockets = [];
14+ foreach (scandir('/proc/self/fd') as $fd) {
15+ $link = @readlink("/proc/self/fd/$fd");
16+ if ($link !== false && str_starts_with($link, 'socket:')) {
17+ $sockets[$fd] = $link;
18+ }
19+ }
20+ return $sockets;
21+ }
22+
23+ if (isset($_GET['syslog'])) {
24+ $before = sockets();
25+ syslog(LOG_DEBUG, 'GH-24308');
26+ echo json_encode(array_diff_assoc(sockets(), $before));
27+ } else {
28+ echo json_encode(sockets());
29+ }
30+ CODE;
31+
32+ include __DIR__ ."/../../../../sapi/cli/tests/php_cli_server.inc " ;
33+ php_cli_server_start ($ serverCode , null , []);
34+
35+ $ opened = json_decode (file_get_contents ("http:// " . PHP_CLI_SERVER_ADDRESS . "/?syslog " ), true );
36+ var_dump (count ($ opened ));
37+
38+ $ next = json_decode (file_get_contents ("http:// " . PHP_CLI_SERVER_ADDRESS . "/ " ), true );
39+ var_dump (array_intersect_assoc ($ opened , $ next ));
40+ ?>
41+ --EXPECT--
42+ int(1)
43+ array(0) {
44+ }
You can’t perform that action at this time.
0 commit comments