mirror of
https://github.com/postgres/postgres.git
synced 2025-08-05 07:41:25 +03:00
pg_waldump: Fix invalid option handling
Previously, running pg_waldump with an invalid option (pg_waldump --foo) would print the help output and exit successfully. This was because it tried to process the option letter '?' as a normal option, but that letter is used by getopt() to report an invalid option. To fix, process help and version options separately, like we do everywhere else. Also add a basic test suite for pg_waldump and run the basic option handling tests, which would have caught this.
This commit is contained in:
3
src/bin/pg_waldump/.gitignore
vendored
3
src/bin/pg_waldump/.gitignore
vendored
@@ -2,3 +2,6 @@
|
|||||||
# Source files copied from src/backend/access/rmgrdesc/
|
# Source files copied from src/backend/access/rmgrdesc/
|
||||||
/*desc.c
|
/*desc.c
|
||||||
/xlogreader.c
|
/xlogreader.c
|
||||||
|
|
||||||
|
# Generated by test suite
|
||||||
|
/tmp_check/
|
||||||
|
@@ -38,3 +38,10 @@ uninstall:
|
|||||||
|
|
||||||
clean distclean maintainer-clean:
|
clean distclean maintainer-clean:
|
||||||
rm -f pg_waldump$(X) $(OBJS) $(RMGRDESCSOURCES) xlogreader.c
|
rm -f pg_waldump$(X) $(OBJS) $(RMGRDESCSOURCES) xlogreader.c
|
||||||
|
rm -rf tmp_check
|
||||||
|
|
||||||
|
check:
|
||||||
|
$(prove_check)
|
||||||
|
|
||||||
|
installcheck:
|
||||||
|
$(prove_installcheck)
|
||||||
|
@@ -806,6 +806,7 @@ usage(void)
|
|||||||
printf(_(" -z, --stats[=record] show statistics instead of records\n"
|
printf(_(" -z, --stats[=record] show statistics instead of records\n"
|
||||||
" (optionally, show per-record statistics)\n"));
|
" (optionally, show per-record statistics)\n"));
|
||||||
printf(_(" -?, --help show this help, then exit\n"));
|
printf(_(" -?, --help show this help, then exit\n"));
|
||||||
|
printf(_("\nReport bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -844,6 +845,20 @@ main(int argc, char **argv)
|
|||||||
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_waldump"));
|
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_waldump"));
|
||||||
progname = get_progname(argv[0]);
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
||||||
|
{
|
||||||
|
puts("pg_waldump (PostgreSQL) " PG_VERSION);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memset(&private, 0, sizeof(XLogDumpPrivate));
|
memset(&private, 0, sizeof(XLogDumpPrivate));
|
||||||
memset(&config, 0, sizeof(XLogDumpConfig));
|
memset(&config, 0, sizeof(XLogDumpConfig));
|
||||||
memset(&stats, 0, sizeof(XLogDumpStats));
|
memset(&stats, 0, sizeof(XLogDumpStats));
|
||||||
@@ -869,7 +884,7 @@ main(int argc, char **argv)
|
|||||||
goto bad_argument;
|
goto bad_argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((option = getopt_long(argc, argv, "be:?fn:p:r:s:t:Vx:z",
|
while ((option = getopt_long(argc, argv, "be:fn:p:r:s:t:x:z",
|
||||||
long_options, &optindex)) != -1)
|
long_options, &optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (option)
|
switch (option)
|
||||||
@@ -889,10 +904,6 @@ main(int argc, char **argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
config.follow = true;
|
config.follow = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
|
||||||
usage();
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
break;
|
|
||||||
case 'n':
|
case 'n':
|
||||||
if (sscanf(optarg, "%d", &config.stop_after_records) != 1)
|
if (sscanf(optarg, "%d", &config.stop_after_records) != 1)
|
||||||
{
|
{
|
||||||
@@ -947,10 +958,6 @@ main(int argc, char **argv)
|
|||||||
goto bad_argument;
|
goto bad_argument;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'V':
|
|
||||||
puts("pg_waldump (PostgreSQL) " PG_VERSION);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
break;
|
|
||||||
case 'x':
|
case 'x':
|
||||||
if (sscanf(optarg, "%u", &config.filter_by_xid) != 1)
|
if (sscanf(optarg, "%u", &config.filter_by_xid) != 1)
|
||||||
{
|
{
|
||||||
|
8
src/bin/pg_waldump/t/001_basic.pl
Normal file
8
src/bin/pg_waldump/t/001_basic.pl
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use TestLib;
|
||||||
|
use Test::More tests => 8;
|
||||||
|
|
||||||
|
program_help_ok('pg_waldump');
|
||||||
|
program_version_ok('pg_waldump');
|
||||||
|
program_options_handling_ok('pg_waldump');
|
Reference in New Issue
Block a user