| 1 |
# Test O_CLOEXEC flag handling on Windows |
| 2 |
# |
| 3 |
# This test verifies that file handles opened with O_CLOEXEC are not |
| 4 |
# inherited by child processes, while handles opened without O_CLOEXEC |
| 5 |
# are inherited. |
| 6 |
|
| 7 |
use strict; |
| 8 |
use warnings FATAL => 'all'; |
| 9 |
use PostgreSQL::Test::Utils; |
| 10 |
use Test::More; |
| 11 |
use IPC::Run qw(run); |
| 12 |
use File::Spec; |
| 13 |
use Cwd 'abs_path'; |
| 14 |
|
| 15 |
if (!$PostgreSQL::Test::Utils::windows_os) |
| 16 |
{ |
| 17 |
plan skip_all => 'test is Windows-specific'; |
| 18 |
} |
| 19 |
|
| 20 |
plan tests => 1; |
| 21 |
|
| 22 |
my $test_prog; |
| 23 |
foreach my $dir (split(/$Config::Config{path_sep}/, $ENV{PATH})) |
| 24 |
{ |
| 25 |
my $candidate = File::Spec->catfile($dir, 'test_cloexec.exe'); |
| 26 |
if (-f $candidate && -x $candidate) |
| 27 |
{ |
| 28 |
$test_prog = $candidate; |
| 29 |
last; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
if (!$test_prog) |
| 34 |
{ |
| 35 |
$test_prog = './test_cloexec.exe'; |
| 36 |
} |
| 37 |
|
| 38 |
if (!-f $test_prog) |
| 39 |
{ |
| 40 |
BAIL_OUT("test program not found: $test_prog"); |
| 41 |
} |
| 42 |
|
| 43 |
note("Using test program: $test_prog"); |
| 44 |
|
| 45 |
my ($stdout, $stderr); |
| 46 |
my $result = run [ $test_prog ], '>', \$stdout, '2>', \$stderr; |
| 47 |
|
| 48 |
note("Test program output:"); |
| 49 |
note($stdout) if $stdout; |
| 50 |
|
| 51 |
if ($stderr) |
| 52 |
{ |
| 53 |
diag("Test program stderr:"); |
| 54 |
diag($stderr); |
| 55 |
} |
| 56 |
|
| 57 |
ok($result && $stdout =~ /SUCCESS.*O_CLOEXEC behavior verified/s, |
| 58 |
"O_CLOEXEC prevents handle inheritance"); |
| 59 |
|
| 60 |
done_testing(); |