Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbec2a0a

Browse files
macdiceThomas Munro
and
Thomas Munro
committed
Clean up test_cloexec.c and Makefile.
An unused variable caused a compiler warning on BF animal fairywren, ansnprintf() call was redundant, and some buffer sizes were inconsistent.Per code review from Tom Lane.The Makefile's test ifeq ($(PORTNAME), win32) never succeeded due to acircularity, so only Meson builds were actually compiling the new testcode, partially explaining why CI didn't tell us about the warningsooner (the other problem being that CompilerWarnings only makesworld-bin, a problem for another commit). Simplify.Backpatch-through: 16, like commitc507ba5Author: Bryan Green <dbryan.green@gmail.com>Co-authored-by: Thomas Munro <tmunro@gmail.com>Reported-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/1086088.1765593851%40sss.pgh.pa.us
1 parent548de59 commitbec2a0a

File tree

2 files changed

+23
-54
lines changed

2 files changed

+23
-54
lines changed

‎src/test/modules/test_cloexec/Makefile‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
# src/test/modules/test_cloexec/Makefile
22

3-
# This module is for Windows only
4-
ifeq ($(PORTNAME),win32)
5-
6-
MODULE_big = test_cloexec
7-
OBJS =\
8-
$(WIN32RES)\
9-
test_cloexec.o
10-
113
PGFILEDESC = "test_cloexec - test O_CLOEXEC flag handling"
4+
PGAPPICON = win32
125

13-
# Build as a standalone program, not a shared library
14-
PROGRAM = test_cloexec
15-
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS)
6+
PROGRAM += test_cloexec
7+
OBJS +=$(WIN32RES) test_cloexec.o
168

9+
NO_INSTALLCHECK = 1
1710
TAP_TESTS = 1
1811

19-
endif
20-
2112
ifdefUSE_PGXS
2213
PG_CONFIG = pg_config
2314
PGXS :=$(shell$(PG_CONFIG) --pgxs)

‎src/test/modules/test_cloexec/test_cloexec.c‎

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@
2424
#include"common/file_utils.h"
2525
#include"port.h"
2626

27+
#ifdefWIN32
2728
staticvoidrun_parent_tests(constchar*testfile1,constchar*testfile2);
2829
staticvoidrun_child_tests(constchar*handle1_str,constchar*handle2_str);
2930
staticbooltry_write_to_handle(HANDLEh,constchar*label);
31+
#endif
3032

3133
int
3234
main(intargc,char*argv[])
3335
{
34-
chartestfile1[MAXPGPATH];
35-
chartestfile2[MAXPGPATH];
36-
3736
/* Windows-only test */
3837
#ifndefWIN32
3938
fprintf(stderr,"This test only runs on Windows\n");
4039
return0;
41-
#endif
40+
#else
41+
chartestfile1[MAXPGPATH];
42+
chartestfile2[MAXPGPATH];
4243

4344
if (argc==3)
4445
{
@@ -68,36 +69,34 @@ main(int argc, char *argv[])
6869
fprintf(stderr,"Usage: %s [handle1_hex handle2_hex]\n",argv[0]);
6970
return1;
7071
}
72+
#endif
7173
}
7274

75+
#ifdefWIN32
7376
staticvoid
7477
run_parent_tests(constchar*testfile1,constchar*testfile2)
7578
{
76-
#ifdefWIN32
7779
intfd1,
7880
fd2;
7981
HANDLEh1,
8082
h2;
81-
charcmdline[1024];
82-
STARTUPINFOsi;
83-
PROCESS_INFORMATIONpi;
83+
charexe_path[MAXPGPATH];
84+
charcmdline[MAXPGPATH+100];
85+
STARTUPINFOsi= {.cb=sizeof(si)};
86+
PROCESS_INFORMATIONpi= {0};
8487
DWORDexit_code;
8588

8689
printf("Parent: Opening test files...\n");
8790

88-
/*
89-
* Open first file WITH O_CLOEXEC - should NOT be inherited
90-
*/
91+
/* Open first file WITH O_CLOEXEC - should NOT be inherited */
9192
fd1=open(testfile1,O_RDWR |O_CREAT |O_TRUNC |O_CLOEXEC,0600);
9293
if (fd1<0)
9394
{
9495
fprintf(stderr,"Failed to open %s: %s\n",testfile1,strerror(errno));
9596
exit(1);
9697
}
9798

98-
/*
99-
* Open second file WITHOUT O_CLOEXEC - should be inherited
100-
*/
99+
/* Open second file WITHOUT O_CLOEXEC - should be inherited */
101100
fd2=open(testfile2,O_RDWR |O_CREAT |O_TRUNC,0600);
102101
if (fd2<0)
103102
{
@@ -121,29 +120,12 @@ run_parent_tests(const char *testfile1, const char *testfile2)
121120
printf("Parent: fd1=%d (O_CLOEXEC) -> HANDLE=%p\n",fd1,h1);
122121
printf("Parent: fd2=%d (no O_CLOEXEC) -> HANDLE=%p\n",fd2,h2);
123122

124-
/*
125-
* Spawn child process with bInheritHandles=TRUE, passing handle values as
126-
* hex strings
127-
*/
128-
snprintf(cmdline,sizeof(cmdline),"\"%s\" %p %p",
129-
GetCommandLine(),h1,h2);
130-
131123
/*
132124
* Find the actual executable path by removing any arguments from
133-
* GetCommandLine().
125+
* GetCommandLine(), and add our new arguments.
134126
*/
135-
{
136-
charexe_path[MAX_PATH];
137-
char*space_pos;
138-
139-
GetModuleFileName(NULL,exe_path,sizeof(exe_path));
140-
snprintf(cmdline,sizeof(cmdline),"\"%s\" %p %p",
141-
exe_path,h1,h2);
142-
}
143-
144-
memset(&si,0,sizeof(si));
145-
si.cb=sizeof(si);
146-
memset(&pi,0,sizeof(pi));
127+
GetModuleFileName(NULL,exe_path,sizeof(exe_path));
128+
snprintf(cmdline,sizeof(cmdline),"\"%s\" %p %p",exe_path,h1,h2);
147129

148130
printf("Parent: Spawning child process...\n");
149131
printf("Parent: Command line: %s\n",cmdline);
@@ -180,19 +162,19 @@ run_parent_tests(const char *testfile1, const char *testfile2)
180162
printf("Parent: Child exit code: %lu\n",exit_code);
181163

182164
if (exit_code==0)
165+
{
183166
printf("Parent: SUCCESS - O_CLOEXEC behavior verified\n");
167+
}
184168
else
185169
{
186170
printf("Parent: FAILURE - O_CLOEXEC not working correctly\n");
187171
exit(1);
188172
}
189-
#endif
190173
}
191174

192175
staticvoid
193176
run_child_tests(constchar*handle1_str,constchar*handle2_str)
194177
{
195-
#ifdefWIN32
196178
HANDLEh1,
197179
h2;
198180
boolh1_worked,
@@ -232,13 +214,11 @@ run_child_tests(const char *handle1_str, const char *handle2_str)
232214
printf("Child: Test FAILED - O_CLOEXEC not working correctly\n");
233215
exit(1);
234216
}
235-
#endif
236217
}
237218

238219
staticbool
239220
try_write_to_handle(HANDLEh,constchar*label)
240221
{
241-
#ifdefWIN32
242222
constchar*test_data="test\n";
243223
DWORDbytes_written;
244224
BOOLresult;
@@ -256,7 +236,5 @@ try_write_to_handle(HANDLE h, const char *label)
256236
label,GetLastError());
257237
return false;
258238
}
259-
#else
260-
return false;
261-
#endif
262239
}
240+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp