Skip to content

Commit fbad11e

Browse files
committed
Skip unavailable Unix datagram socket tests
1 parent c648932 commit fbad11e

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

ext/sockets/tests/bug76839.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ sockets
77
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
88
die('skip not valid for Windows.');
99
}
10+
require __DIR__ . '/unix_dgram_skipif.inc';
1011
?>
1112
--FILE--
1213
<?php
@@ -16,11 +17,11 @@ if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
1617
// best way I could manage to reproduce this problem without modifying php itself :-/
1718

1819
for ($i = 0; $i < 10; $i++) {
19-
$senderSocketPath = '/tmp/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
20+
$senderSocketPath = sys_get_temp_dir() . '/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
2021
$senderSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
2122
socket_bind($senderSocket, $senderSocketPath);
2223

23-
$receiverSocketPath = '/tmp/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
24+
$receiverSocketPath = sys_get_temp_dir() . '/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
2425
$receiverSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
2526
socket_bind($receiverSocket, $receiverSocketPath);
2627

ext/sockets/tests/socket_sendmsg_scm_rights_object.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if (strtolower(substr(PHP_OS, 0, 3)) == 'aix') {
1313
if (!defined('SCM_RIGHTS')) {
1414
die('skip SCM_RIGHTS not available');
1515
}
16+
require __DIR__ . '/unix_dgram_skipif.inc';
1617
?>
1718
--FILE--
1819
<?php
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
$socketPath = tempnam(sys_get_temp_dir(), 'php_socket_');
4+
if ($socketPath === false) {
5+
die('skip unable to create a temporary socket path');
6+
}
7+
unlink($socketPath);
8+
9+
$socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
10+
if ($socket === false || !@socket_bind($socket, $socketPath)) {
11+
$error = socket_last_error($socket !== false ? $socket : null);
12+
if ($socket !== false) {
13+
socket_close($socket);
14+
}
15+
@unlink($socketPath);
16+
17+
$unavailableErrors = array_filter([
18+
defined('SOCKET_EPERM') ? SOCKET_EPERM : null,
19+
defined('SOCKET_EACCES') ? SOCKET_EACCES : null,
20+
defined('SOCKET_EAFNOSUPPORT') ? SOCKET_EAFNOSUPPORT : null,
21+
defined('SOCKET_EPROTONOSUPPORT') ? SOCKET_EPROTONOSUPPORT : null,
22+
defined('SOCKET_ESOCKTNOSUPPORT') ? SOCKET_ESOCKTNOSUPPORT : null,
23+
defined('SOCKET_EOPNOTSUPP') ? SOCKET_EOPNOTSUPP : null,
24+
], static fn(?int $error): bool => $error !== null);
25+
if (in_array($error, $unavailableErrors, true)) {
26+
die('skip unable to bind an AF_UNIX datagram socket');
27+
}
28+
die('unexpected AF_UNIX datagram bind failure: ' . socket_strerror($error));
29+
}
30+
socket_close($socket);
31+
unlink($socketPath);

0 commit comments

Comments
 (0)