Clean up calls to repmgr_atoi()

In some places we were still providing "false" from the original implementation,
which was intended to indicate whether a negative value was allowed.

This has not been a problem, as it merely means we have been providing "0",
which is the same thing; however we can finer-tune some of the calls
(e.g. node ID must be or greater).
This commit is contained in:
Ian Barwick
2019-01-30 11:43:43 +09:00
parent b6264b77c4
commit 70e4243a1d
3 changed files with 15 additions and 16 deletions

View File

@@ -473,7 +473,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
/* Copy into correct entry in parameters struct */
if (strcmp(name, "node_id") == 0)
{
options->node_id = repmgr_atoi(value, name, error_list, 1);
options->node_id = repmgr_atoi(value, name, error_list, MIN_NODE_ID);
node_id_found = true;
}
else if (strcmp(name, "node_name") == 0)

View File

@@ -294,7 +294,12 @@ main(int argc, char **argv)
break;
case 'p':
(void) repmgr_atoi(optarg, "-p/--port", &cli_errors, false);
/*
* minimum TCP port number is 1; in practice PostgreSQL
* won't be running on a privileged port, but we don't want
* to be concerned with that level of checking
*/
(void) repmgr_atoi(optarg, "-p/--port", &cli_errors, 1);
param_set(&source_conninfo, "port", optarg);
strncpy(runtime_options.port,
optarg,
@@ -336,7 +341,7 @@ main(int argc, char **argv)
/* --node-id */
case OPT_NODE_ID:
runtime_options.node_id = repmgr_atoi(optarg, "--node-id", &cli_errors, false);
runtime_options.node_id = repmgr_atoi(optarg, "--node-id", &cli_errors, MIN_NODE_ID);
break;
/* --node-name */
@@ -346,7 +351,7 @@ main(int argc, char **argv)
/* --remote-node-id */
case OPT_REMOTE_NODE_ID:
runtime_options.remote_node_id = repmgr_atoi(optarg, "--remote-node-id", &cli_errors, false);
runtime_options.remote_node_id = repmgr_atoi(optarg, "--remote-node-id", &cli_errors, MIN_NODE_ID);
break;
/*
@@ -355,7 +360,7 @@ main(int argc, char **argv)
/* --upstream-node-id */
case OPT_UPSTREAM_NODE_ID:
runtime_options.upstream_node_id = repmgr_atoi(optarg, "--upstream-node-id", &cli_errors, false);
runtime_options.upstream_node_id = repmgr_atoi(optarg, "--upstream-node-id", &cli_errors, MIN_NODE_ID);
break;
/*------------------------
@@ -415,14 +420,14 @@ main(int argc, char **argv)
*/
case OPT_WAIT_START:
runtime_options.wait_start = repmgr_atoi(optarg, "--wait-start", &cli_errors, false);
runtime_options.wait_start = repmgr_atoi(optarg, "--wait-start", &cli_errors, 0);
break;
case OPT_WAIT_SYNC:
runtime_options.wait_register_sync = true;
if (optarg != NULL)
{
runtime_options.wait_register_sync_seconds = repmgr_atoi(optarg, "--wait-sync", &cli_errors, false);
runtime_options.wait_register_sync_seconds = repmgr_atoi(optarg, "--wait-sync", &cli_errors, 0);
}
break;
@@ -543,7 +548,7 @@ main(int argc, char **argv)
break;
case OPT_LIMIT:
runtime_options.limit = repmgr_atoi(optarg, "--limit", &cli_errors, false);
runtime_options.limit = repmgr_atoi(optarg, "--limit", &cli_errors, 1);
runtime_options.limit_provided = true;
break;
@@ -558,7 +563,7 @@ main(int argc, char **argv)
/* -k/--keep-history */
case 'k':
runtime_options.keep_history = repmgr_atoi(optarg, "-k/--keep-history", &cli_errors, false);
runtime_options.keep_history = repmgr_atoi(optarg, "-k/--keep-history", &cli_errors, 0);
break;
/*----------------
@@ -1679,12 +1684,6 @@ check_cli_parameters(const int action)
switch (action)
{
case CLUSTER_EVENT:
if (runtime_options.limit < 1)
{
item_list_append_format(&cli_errors,
_("value for --limit must be 1 or greater (provided: %i)"),
runtime_options.limit);
}
break;
default:
item_list_append_format(&cli_warnings,

View File

@@ -58,7 +58,7 @@
#define NODE_NOT_FOUND -1
#define NO_UPSTREAM_NODE -1
#define UNKNOWN_NODE_ID -1
#define MIN_NODE_ID 1
#define VOTING_TERM_NOT_SET -1
#define BDR2_REPLICATION_SET_NAME "repmgr"