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