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

Commit37eb2cd

Browse files
committed
More pg_test_fsync fixups.
Reduce #includes to minimum actually needed; in particular includepostgres_fe.h not postgres.h, so as to stop build failures on someplatforms.Use get_progname() instead of hardwired program name; improve errorchecking for command line syntax; bring error messages into line withstyle guidelines; include strerror result in die() cases.
1 parent3ae28ce commit37eb2cd

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

‎contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
*tests all supported fsync() methods
44
*/
55

6-
#include"postgres.h"
6+
#include"postgres_fe.h"
77

8-
#include<fcntl.h>
98
#include<sys/stat.h>
109
#include<sys/time.h>
1110
#include<time.h>
1211
#include<unistd.h>
1312

1413
#include"getopt_long.h"
15-
#include"access/xlog_internal.h"
16-
#include"access/xlog.h"
1714
#include"access/xlogdefs.h"
1815

1916

@@ -29,9 +26,11 @@
2926
#defineNA_FORMATLABEL_FORMAT "%18s"
3027
#defineOPS_FORMAT"%9.3f ops/sec"
3128

32-
intops_per_test=2000;
33-
charfull_buf[XLOG_SEG_SIZE],*buf,*filename=FSYNC_FILENAME;
34-
structtimevalstart_t,stop_t;
29+
staticconstchar*progname;
30+
31+
staticintops_per_test=2000;
32+
staticcharfull_buf[XLOG_SEG_SIZE],*buf,*filename=FSYNC_FILENAME;
33+
staticstructtimevalstart_t,stop_t;
3534

3635

3736
staticvoidhandle_args(intargc,char*argv[]);
@@ -46,12 +45,14 @@ static voidtest_file_descriptor_sync(void);
4645
staticintpg_fsync_writethrough(intfd);
4746
#endif
4847
staticvoidprint_elapse(structtimevalstart_t,structtimevalstop_t);
49-
staticvoiddie(char*str);
48+
staticvoiddie(constchar*str);
5049

5150

5251
int
5352
main(intargc,char*argv[])
5453
{
54+
progname=get_progname(argv[0]);
55+
5556
handle_args(argc,argv);
5657

5758
prepare_buf();
@@ -91,12 +92,12 @@ handle_args(int argc, char *argv[])
9192
if (strcmp(argv[1],"--help")==0||strcmp(argv[1],"-h")==0||
9293
strcmp(argv[1],"-?")==0)
9394
{
94-
fprintf(stderr,"pg_test_fsync [-f filename] [-o ops-per-test]\n");
95+
fprintf(stderr,"%s [-f filename] [-o ops-per-test]\n",progname);
9596
exit(0);
9697
}
9798
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
9899
{
99-
fprintf(stderr,"pg_test_fsync "PG_VERSION"\n");
100+
fprintf(stderr,"%s %s\n",progname,PG_VERSION);
100101
exit(0);
101102
}
102103
}
@@ -115,14 +116,23 @@ handle_args(int argc, char *argv[])
115116
break;
116117

117118
default:
118-
fprintf(stderr,
119-
"Try \"%s --help\" for more information.\n",
120-
"pg_test_fsync");
119+
fprintf(stderr,"Try \"%s --help\" for more information.\n",
120+
progname);
121121
exit(1);
122122
break;
123123
}
124124
}
125125

126+
if (argc>optind)
127+
{
128+
fprintf(stderr,
129+
"%s: too many command-line arguments (first is \"%s\")\n",
130+
progname,argv[optind]);
131+
fprintf(stderr,"Try \"%s --help\" for more information.\n",
132+
progname);
133+
exit(1);
134+
}
135+
126136
printf("%d operations per test\n",ops_per_test);
127137
}
128138

@@ -147,7 +157,7 @@ test_open(void)
147157
* test if we can open the target file
148158
*/
149159
if ((tmpfile=open(filename,O_RDWR |O_CREAT,S_IRUSR |S_IWUSR))==-1)
150-
die("Cannotopen output file.");
160+
die("could notopen output file");
151161
if (write(tmpfile,full_buf,XLOG_SEG_SIZE)!=XLOG_SEG_SIZE)
152162
die("write failed");
153163

@@ -183,7 +193,7 @@ test_sync(int writes_per_op)
183193
fflush(stdout);
184194

185195
if ((tmpfile=open(filename,O_RDWR |O_DSYNC,0))==-1)
186-
die("Cannotopen output file.");
196+
die("could notopen output file");
187197
gettimeofday(&start_t,NULL);
188198
for (ops=0;ops<ops_per_test;ops++)
189199
{
@@ -238,7 +248,7 @@ test_sync(int writes_per_op)
238248
fflush(stdout);
239249

240250
if ((tmpfile=open(filename,O_RDWR,0))==-1)
241-
die("Cannotopen output file.");
251+
die("could notopen output file");
242252
gettimeofday(&start_t,NULL);
243253
for (ops=0;ops<ops_per_test;ops++)
244254
{
@@ -263,7 +273,7 @@ test_sync(int writes_per_op)
263273
fflush(stdout);
264274

265275
if ((tmpfile=open(filename,O_RDWR,0))==-1)
266-
die("Cannotopen output file.");
276+
die("could notopen output file");
267277
gettimeofday(&start_t,NULL);
268278
for (ops=0;ops<ops_per_test;ops++)
269279
{
@@ -287,7 +297,7 @@ test_sync(int writes_per_op)
287297
fflush(stdout);
288298

289299
if ((tmpfile=open(filename,O_RDWR,0))==-1)
290-
die("Cannotopen output file.");
300+
die("could notopen output file");
291301
gettimeofday(&start_t,NULL);
292302
for (ops=0;ops<ops_per_test;ops++)
293303
{
@@ -318,7 +328,7 @@ test_sync(int writes_per_op)
318328
fflush(stdout);
319329

320330
if ((tmpfile=open(filename,O_RDWR |OPEN_SYNC_FLAG,0))==-1)
321-
die("Cannotopen output file.");
331+
die("could notopen output file");
322332
gettimeofday(&start_t,NULL);
323333
for (ops=0;ops<ops_per_test;ops++)
324334
{
@@ -453,7 +463,7 @@ test_file_descriptor_sync(void)
453463
for (ops=0;ops<ops_per_test;ops++)
454464
{
455465
if ((tmpfile=open(filename,O_RDWR,0))==-1)
456-
die("Cannotopen output file.");
466+
die("could notopen output file");
457467
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
458468
die("write failed");
459469
if (fsync(tmpfile)!=0)
@@ -464,7 +474,7 @@ test_file_descriptor_sync(void)
464474
* with the following test
465475
*/
466476
if ((tmpfile=open(filename,O_RDWR,0))==-1)
467-
die("Cannotopen output file.");
477+
die("could notopen output file");
468478
close(tmpfile);
469479
}
470480
gettimeofday(&stop_t,NULL);
@@ -482,13 +492,13 @@ test_file_descriptor_sync(void)
482492
for (ops=0;ops<ops_per_test;ops++)
483493
{
484494
if ((tmpfile=open(filename,O_RDWR,0))==-1)
485-
die("Cannotopen output file.");
495+
die("could notopen output file");
486496
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
487497
die("write failed");
488498
close(tmpfile);
489499
/* reopen file */
490500
if ((tmpfile=open(filename,O_RDWR,0))==-1)
491-
die("Cannotopen output file.");
501+
die("could notopen output file");
492502
if (fsync(tmpfile)!=0)
493503
die("fsync failed");
494504
close(tmpfile);
@@ -514,7 +524,7 @@ test_non_sync(void)
514524
for (ops=0;ops<ops_per_test;ops++)
515525
{
516526
if ((tmpfile=open(filename,O_RDWR,0))==-1)
517-
die("Cannotopen output file.");
527+
die("could notopen output file");
518528
if (write(tmpfile,buf,WRITE_SIZE)!=WRITE_SIZE)
519529
die("write failed");
520530
close(tmpfile);
@@ -554,8 +564,8 @@ print_elapse(struct timeval start_t, struct timeval stop_t)
554564
}
555565

556566
staticvoid
557-
die(char*str)
567+
die(constchar*str)
558568
{
559-
fprintf(stderr,"%s\n",str);
569+
fprintf(stderr,"%s: %s\n",str,strerror(errno));
560570
exit(1);
561571
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp