Skip to content

Commit 2f359e7

Browse files
committed
Always allow true/false
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
1 parent 5aae094 commit 2f359e7

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

cdb2api/cdb2api.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static int process_env_var_str(const char *var, char *value, int len, int *indic
563563
return 1;
564564
}
565565
566-
static int value_on_off(const char *value, int *err, int allow_true_false);
566+
static int value_on_off(const char *value, int *err);
567567
568568
// Prints a warning if the env var's value is invalid.
569569
//
@@ -574,7 +574,7 @@ static int process_env_var_str_on_off(const char *var, int *value, int *indicato
574574
int err;
575575
576576
if (s) {
577-
*value = value_on_off(s, &err, 0);
577+
*value = value_on_off(s, &err);
578578
579579
if (err == -1) {
580580
fprintf(stderr, "WARNING: %s: Value of %s is not valid. Using value '%s'.\n", __func__, var,
@@ -1274,15 +1274,14 @@ static int is_valid_int(const char *str)
12741274

12751275
// `err` is set to -1 if the `value` is invalid; otherwise, it is set to 0.
12761276
//
1277-
// `value` is invalid if it is not equal to one of the following: "on", "off", "yes", "no", "1", "0".
1278-
// "true" and "false" are also allowed if allow_true_false is set (for allow_pmux_route backwards compatibility).
1277+
// `value` is invalid if it is not equal to one of the following: "on", "off", "yes", "no", "1", "0", "true", "false".
12791278
// Ideally these values would be rejected, but this wouldn't be backwards compatible (currently,
12801279
// all nonzero numbers are effectively "on" and all values that cannot be converted to integers other
12811280
// than "on", "off", "yes", and "no" are effectively "off")
12821281
//
12831282
// Returning a separate error allows us to print a warning message when this occurs while maintaining
12841283
// old behavior.
1285-
static int value_on_off(const char *value, int *err, int allow_true_false)
1284+
static int value_on_off(const char *value, int *err)
12861285
{
12871286
*err = 0;
12881287

@@ -1298,9 +1297,9 @@ static int value_on_off(const char *value, int *err, int allow_true_false)
12981297
return 0;
12991298
} else if (strcasecmp("1", value) == 0) {
13001299
return 1;
1301-
} else if (allow_true_false && strcasecmp("true", value) == 0) {
1300+
} else if (strcasecmp("true", value) == 0) {
13021301
return 1;
1303-
} else if (allow_true_false && strcasecmp("false", value) == 0) {
1302+
} else if (strcasecmp("false", value) == 0) {
13041303
return 0;
13051304
} else {
13061305
*err = -1;
@@ -1499,11 +1498,11 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, SBUF2 *s, const char *comdb2db
14991498
if (!cdb2_iam_identity_set_from_env && (strcasecmp("iam_identity_v6", tok) == 0)) {
15001499
tok = strtok_r(NULL, " =:,", &last);
15011500
if (tok)
1502-
iam_identity = value_on_off(tok, &err, 0);
1501+
iam_identity = value_on_off(tok, &err);
15031502
} else if ((strcasecmp("use_env_vars", tok) == 0) && !hndl) {
15041503
tok = strtok_r(NULL, " =:,", &last);
15051504
if (tok)
1506-
cdb2_use_env_vars = value_on_off(tok, &err, 0);
1505+
cdb2_use_env_vars = value_on_off(tok, &err);
15071506
}
15081507
} else if (strcasecmp("comdb2_config", tok) == 0) {
15091508
tok = strtok_r(NULL, " =:,", &last);
@@ -1582,7 +1581,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, SBUF2 *s, const char *comdb2db
15821581
} else if (!cdb2_allow_pmux_route_set_from_env && strcasecmp("allow_pmux_route", tok) == 0) {
15831582
tok = strtok_r(NULL, " :,", &last);
15841583
if (tok) {
1585-
cdb2_allow_pmux_route = value_on_off(tok, &err, 1);
1584+
cdb2_allow_pmux_route = value_on_off(tok, &err);
15861585
}
15871586
} else if (!cdb2_uninstall_set_from_env && (strcasecmp("uninstall_static_libs_v4", tok) == 0 ||
15881587
strcasecmp("disable_static_libs", tok) == 0)) {
@@ -1630,7 +1629,7 @@ static void read_comdb2db_cfg(cdb2_hndl_tp *hndl, SBUF2 *s, const char *comdb2db
16301629
(strcasecmp("get_hostname_from_sockpool_fd_v3", tok) == 0)) {
16311630
tok = strtok_r(NULL, " :,", &last);
16321631
if (tok)
1633-
get_hostname_from_sockpool_fd = value_on_off(tok, &err, 1);
1632+
get_hostname_from_sockpool_fd = value_on_off(tok, &err);
16341633
} else if (strcasecmp("ssl_mode", tok) == 0) {
16351634
tok = strtok_r(NULL, " :,", &last);
16361635
if (tok != NULL) {

0 commit comments

Comments
 (0)