Fix pg_recvlogical to accept the documented -I instead only --startpos.

The bug was caused by omitting 'I:' from the short argument list to
getopt_long(). To make similar bugs in the future less likely reorder
options in --help, long and short option lists to be in the same,
alphabetical within groups, order.

Report and fix by Michael Paquier, some additional reordering by me.
This commit is contained in:
Andres Freund 2014-05-25 18:47:05 +02:00
parent 0a5faaa907
commit bf2e70ba6c
1 changed files with 25 additions and 25 deletions

View File

@ -68,6 +68,8 @@ usage(void)
printf(_(" %s [OPTION]...\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -f, --file=FILE receive log into this file. - for stdout\n"));
printf(_(" -F --fsync-interval=SECS\n"
" frequency of syncs to the output file (default: %d)\n"), (fsync_interval / 1000));
printf(_(" -n, --no-loop do not loop on connection lost\n"));
printf(_(" -v, --verbose output verbose messages\n"));
printf(_(" -V, --version output version information, then exit\n"));
@ -80,8 +82,7 @@ usage(void)
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_("\nReplication options:\n"));
printf(_(" -F --fsync-interval=SECS\n"
" frequency of syncs to the output file (default: %d)\n"), (fsync_interval / 1000));
printf(_(" -I, --startpos=PTR where in an existing slot should the streaming start\n"));
printf(_(" -o, --option=NAME[=VALUE]\n"
" specify option NAME with optional value VALUE, to be passed\n"
" to the output plugin\n"));
@ -89,7 +90,6 @@ usage(void)
printf(_(" -s, --status-interval=SECS\n"
" time between status packets sent to server (default: %d)\n"), (standby_message_timeout / 1000));
printf(_(" -S, --slot=SLOT use existing replication slot SLOT instead of starting a new one\n"));
printf(_(" -I, --startpos=PTR where in an existing slot should the streaming start\n"));
printf(_("\nAction to be performed:\n"));
printf(_(" --create create a new replication slot (for the slotname see --slot)\n"));
printf(_(" --start start streaming in a replication slot (for the slotname see --slot)\n"));
@ -600,6 +600,7 @@ main(int argc, char **argv)
static struct option long_options[] = {
/* general options */
{"file", required_argument, NULL, 'f'},
{"fsync-interval", required_argument, NULL, 'F'},
{"no-loop", no_argument, NULL, 'n'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
@ -612,12 +613,11 @@ main(int argc, char **argv)
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
/* replication options */
{"startpos", required_argument, NULL, 'I'},
{"option", required_argument, NULL, 'o'},
{"plugin", required_argument, NULL, 'P'},
{"status-interval", required_argument, NULL, 's'},
{"fsync-interval", required_argument, NULL, 'F'},
{"slot", required_argument, NULL, 'S'},
{"startpos", required_argument, NULL, 'I'},
/* action */
{"create", no_argument, NULL, 1},
{"start", no_argument, NULL, 2},
@ -647,7 +647,7 @@ main(int argc, char **argv)
}
}
while ((c = getopt_long(argc, argv, "f:F:nvd:h:o:p:U:wWP:s:S:",
while ((c = getopt_long(argc, argv, "f:F:nvd:h:p:U:wWI:o:P:s:S:",
long_options, &option_index)) != -1)
{
switch (c)
@ -656,6 +656,15 @@ main(int argc, char **argv)
case 'f':
outfile = pg_strdup(optarg);
break;
case 'F':
fsync_interval = atoi(optarg) * 1000;
if (fsync_interval < 0)
{
fprintf(stderr, _("%s: invalid fsync interval \"%s\"\n"),
progname, optarg);
exit(1);
}
break;
case 'n':
noloop = 1;
break;
@ -688,6 +697,16 @@ main(int argc, char **argv)
dbgetpassword = 1;
break;
/* replication options */
case 'I':
if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
{
fprintf(stderr,
_("%s: could not parse start position \"%s\"\n"),
progname, optarg);
exit(1);
}
startpos = ((uint64) hi) << 32 | lo;
break;
case 'o':
{
char *data = pg_strdup(optarg);
@ -720,28 +739,9 @@ main(int argc, char **argv)
exit(1);
}
break;
case 'F':
fsync_interval = atoi(optarg) * 1000;
if (fsync_interval < 0)
{
fprintf(stderr, _("%s: invalid fsync interval \"%s\"\n"),
progname, optarg);
exit(1);
}
break;
case 'S':
replication_slot = pg_strdup(optarg);
break;
case 'I':
if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
{
fprintf(stderr,
_("%s: could not parse start position \"%s\"\n"),
progname, optarg);
exit(1);
}
startpos = ((uint64) hi) << 32 | lo;
break;
/* action */
case 1:
do_create_slot = true;