Re: Set new system identifier using pg_resetxlog - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Set new system identifier using pg_resetxlog
Date
Msg-id 20140717224105.GI21370@awork2.anarazel.de
Whole thread Raw
In response to Re: Set new system identifier using pg_resetxlog  (Petr Jelinek <petr@2ndquadrant.com>)
Responses Re: Set new system identifier using pg_resetxlog
Re: Set new system identifier using pg_resetxlog
List pgsql-hackers
On 2014-06-27 00:51:02 +0200, Petr Jelinek wrote:
> -    while ((c = getopt(argc, argv, "fl:m:no:O:x:e:")) != -1)
> +    while ((c = getopt(argc, argv, "fl:m:no:O:x:e:s::")) != -1)

Why two :?

>      {
>          switch (c)
>          {
> @@ -227,6 +229,33 @@ main(int argc, char *argv[])
>                  XLogFromFileName(optarg, &minXlogTli, &minXlogSegNo);
>                  break;
>  
> +            case 's':
> +                if (optarg)
> +                {
> +#ifdef HAVE_STRTOULL
> +                    set_sysid = strtoull(optarg, &endptr, 10);
> +#else
> +                    set_sysid = strtoul(optarg, &endptr, 10);
> +#endif

Wouldn't it be better to use sscanf()? That should work with large
inputs across platforms.

> +                    /*
> +                     * Validate input, we use strspn because strtoul(l) accepts
> +                     * negative numbers and silently converts them to unsigned
> +                     */
> +                    if (set_sysid == 0 || errno != 0 ||
> +                        endptr == optarg || *endptr != '\0' ||
> +                        strspn(optarg, "0123456789") != strlen(optarg))
> +                    {
> +                        fprintf(stderr, _("%s: invalid argument for option -s\n"), progname);
> +                        fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
> +                        exit(1);
> +                    }

Maybe: 'invalid argument \"%s\" ...'?

> @@ -1087,6 +1147,7 @@ usage(void)
>      printf(_("  -o OID           set next OID\n"));
>      printf(_("  -O OFFSET        set next multitransaction offset\n"));
>      printf(_("  -V, --version    output version information, then exit\n"));
> +    printf(_("  -s [SYSID]       set system identifier (or generate one)\n"));
>      printf(_("  -x XID           set next transaction ID\n"));
>      printf(_("  -?, --help       show this help, then exit\n"));
>      printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));

I think we usually try to keep the options roughly alphabetically
ordered. Same in the getopt() above.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Gavin Flower
Date:
Subject: Re: [TODO] Process pg_hba.conf keywords as case-insensitive
Next
From: Andres Freund
Date:
Subject: Re: Set new system identifier using pg_resetxlog