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

Commitab7d421

Browse files
committed
If pg_test_fsync is interrupted, clean up the temp file.
Marti Raudsepp, with additional paranoia by me.
1 parent5bcf8ed commitab7d421

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include<sys/time.h>
1010
#include<time.h>
1111
#include<unistd.h>
12+
#include<signal.h>
1213

1314
#include"getopt_long.h"
1415
#include"access/xlogdefs.h"
@@ -29,6 +30,7 @@
2930
staticconstchar*progname;
3031

3132
staticintops_per_test=2000;
33+
staticintneeds_unlink=0;
3234
staticcharfull_buf[XLOG_SEG_SIZE],
3335
*buf,
3436
*filename=FSYNC_FILENAME;
@@ -44,6 +46,7 @@ static void test_sync(int writes_per_op);
4446
staticvoidtest_open_syncs(void);
4547
staticvoidtest_open_sync(constchar*msg,intwrites_size);
4648
staticvoidtest_file_descriptor_sync(void);
49+
staticvoidsignal_cleanup(intsig);
4750

4851
#ifdefHAVE_FSYNC_WRITETHROUGH
4952
staticintpg_fsync_writethrough(intfd);
@@ -59,6 +62,14 @@ main(int argc, char *argv[])
5962

6063
handle_args(argc,argv);
6164

65+
/* Prevent leaving behind the test file */
66+
signal(SIGINT,signal_cleanup);
67+
signal(SIGTERM,signal_cleanup);
68+
#ifdefSIGHUP
69+
/* Not defined on win32 */
70+
signal(SIGHUP,signal_cleanup);
71+
#endif
72+
6273
prepare_buf();
6374

6475
test_open();
@@ -167,6 +178,7 @@ test_open(void)
167178
*/
168179
if ((tmpfile=open(filename,O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
169180
die("could not open output file");
181+
needs_unlink=1;
170182
if (write(tmpfile,full_buf,XLOG_SEG_SIZE)!=XLOG_SEG_SIZE)
171183
die("write failed");
172184

@@ -490,6 +502,17 @@ test_non_sync(void)
490502
print_elapse(start_t,stop_t);
491503
}
492504

505+
staticvoid
506+
signal_cleanup(intsignum)
507+
{
508+
/* Delete the file if it exists. Ignore errors */
509+
if (needs_unlink)
510+
unlink(filename);
511+
/* Finish incomplete line on stdout */
512+
puts("");
513+
exit(signum);
514+
}
515+
493516
#ifdefHAVE_FSYNC_WRITETHROUGH
494517

495518
staticint

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp