[php-src] Issue #7769: Writing to stderr with a demonized process that has stderr closed sends stderr output out socket instead.

From: Date: Mon, 13 Dec 2021 16:01:55 +0000
Subject: [php-src] Issue #7769: Writing to stderr with a demonized process that has stderr closed sends stderr output out socket instead.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238374@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7769
Author: gnif

### Description

The following code:
```php
<?PHP

$pid = pcntl_fork();
if ($pid)
{
  echo "PID: $pid\n";
  exit(0);
}

fclose(STDOUT);
fclose(STDERR);
posix_setsid();

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, 0, 1234);
socket_listen($socket);

$client = socket_accept($socket);

for(;;)
{
  $line = socket_read($client, 1024, PHP_NORMAL_READ);
  if ($line === false)
    break;

  exec("echo This is sent out the socket >&2");
}

socket_close($client);
socket_close($socket);
?>
```

When connecting over a socket to the host on port 1234 (via telnet) resulted in this
output:
```
> asdf
< This is sent out the socket
< This is sent out the socket
```

But I expected no output at all on the socket.
Note I am not sure if this is caused by misuse by closing STDOUT & STDERR but it seems like this
is incorrect behaviour.

### PHP Version

PHP 8.0.13

### Operating System

_No response_


Thread (1 message)

  • gnif
« previous php.bugs (#238374) next »