|
|
01619e |
From ea5510dd979bb6d375324cda26925d9e7c4362f5 Mon Sep 17 00:00:00 2001
|
|
|
01619e |
From: Chris Lumens <clumens@redhat.com>
|
|
|
01619e |
Date: Mon, 19 Jul 2021 10:04:16 -0400
|
|
|
01619e |
Subject: [PATCH 1/2] Low: tools: The --get-value option does not require an
|
|
|
01619e |
arg.
|
|
|
01619e |
|
|
|
01619e |
Regression in 2.1.0 introduced by 15f5c2901.
|
|
|
01619e |
---
|
|
|
01619e |
tools/crm_attribute.c | 2 +-
|
|
|
01619e |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
01619e |
|
|
|
01619e |
diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c
|
|
|
01619e |
index 2cc8d26..8a5b4e4 100644
|
|
|
01619e |
--- a/tools/crm_attribute.c
|
|
|
01619e |
+++ b/tools/crm_attribute.c
|
|
|
01619e |
@@ -242,7 +242,7 @@ static GOptionEntry deprecated_entries[] = {
|
|
|
01619e |
NULL, NULL
|
|
|
01619e |
},
|
|
|
01619e |
|
|
|
01619e |
- { "get-value", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, value_cb,
|
|
|
01619e |
+ { "get-value", 0, G_OPTION_FLAG_HIDDEN|G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, value_cb,
|
|
|
01619e |
NULL, NULL
|
|
|
01619e |
},
|
|
|
01619e |
|
|
|
01619e |
--
|
|
|
01619e |
1.8.3.1
|
|
|
01619e |
|
|
|
01619e |
|
|
|
01619e |
From ef054d943afe8e60017f6adc4e25f88a59ac91a4 Mon Sep 17 00:00:00 2001
|
|
|
01619e |
From: Chris Lumens <clumens@redhat.com>
|
|
|
01619e |
Date: Mon, 19 Jul 2021 11:37:04 -0400
|
|
|
01619e |
Subject: [PATCH 2/2] Low: libcrmcommon: Allow negative numbers as cmdline
|
|
|
01619e |
options.
|
|
|
01619e |
|
|
|
01619e |
The bug here is that negative numbers (for instance, negative scores)
|
|
|
01619e |
are not supported as command line arguments. Because we break up a
|
|
|
01619e |
string that starts with a single dash into multiple arguments, "-1000"
|
|
|
01619e |
becomes "-1", "-0", "-0", and "-0".
|
|
|
01619e |
|
|
|
01619e |
Because we don't have enough information about what is happening on the
|
|
|
01619e |
command line, the best we can do here is recognize something as a
|
|
|
01619e |
negative number and pass it on. Any errors will have to be detected at
|
|
|
01619e |
a later step.
|
|
|
01619e |
|
|
|
01619e |
Also note that we only recognize negative numbers if they start with
|
|
|
01619e |
1-9. Starting with 0 will be recognized as some sort of string.
|
|
|
01619e |
|
|
|
01619e |
Regression in 2.1.0 caused by a long-standing bug in
|
|
|
01619e |
pcmk__cmdline_preproc_test.
|
|
|
01619e |
---
|
|
|
01619e |
lib/common/cmdline.c | 29 ++++++++++++++++++++++
|
|
|
01619e |
.../tests/cmdline/pcmk__cmdline_preproc_test.c | 24 +++++++++++++++++-
|
|
|
01619e |
2 files changed, 52 insertions(+), 1 deletion(-)
|
|
|
01619e |
|
|
|
01619e |
diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c
|
|
|
01619e |
index 7c95d02..9c1b810 100644
|
|
|
01619e |
--- a/lib/common/cmdline.c
|
|
|
01619e |
+++ b/lib/common/cmdline.c
|
|
|
01619e |
@@ -9,6 +9,7 @@
|
|
|
01619e |
|
|
|
01619e |
#include <crm_internal.h>
|
|
|
01619e |
|
|
|
01619e |
+#include <ctype.h>
|
|
|
01619e |
#include <glib.h>
|
|
|
01619e |
|
|
|
01619e |
#include <crm/crm.h>
|
|
|
01619e |
@@ -189,6 +190,34 @@ pcmk__cmdline_preproc(char **argv, const char *special) {
|
|
|
01619e |
/* Skip over leading dash */
|
|
|
01619e |
char *ch = argv[i]+1;
|
|
|
01619e |
|
|
|
01619e |
+ /* This looks like the start of a number, which means it is a negative
|
|
|
01619e |
+ * number. It's probably the argument to the preceeding option, but
|
|
|
01619e |
+ * we can't know that here. Copy it over and let whatever handles
|
|
|
01619e |
+ * arguments next figure it out.
|
|
|
01619e |
+ */
|
|
|
01619e |
+ if (*ch != '\0' && *ch >= '1' && *ch <= '9') {
|
|
|
01619e |
+ bool is_numeric = true;
|
|
|
01619e |
+
|
|
|
01619e |
+ while (*ch != '\0') {
|
|
|
01619e |
+ if (!isdigit(*ch)) {
|
|
|
01619e |
+ is_numeric = false;
|
|
|
01619e |
+ break;
|
|
|
01619e |
+ }
|
|
|
01619e |
+
|
|
|
01619e |
+ ch++;
|
|
|
01619e |
+ }
|
|
|
01619e |
+
|
|
|
01619e |
+ if (is_numeric) {
|
|
|
01619e |
+ g_ptr_array_add(arr, g_strdup_printf("%s", argv[i]));
|
|
|
01619e |
+ continue;
|
|
|
01619e |
+ } else {
|
|
|
01619e |
+ /* This argument wasn't entirely numeric. Reset ch to the
|
|
|
01619e |
+ * beginning so we can process it one character at a time.
|
|
|
01619e |
+ */
|
|
|
01619e |
+ ch = argv[i]+1;
|
|
|
01619e |
+ }
|
|
|
01619e |
+ }
|
|
|
01619e |
+
|
|
|
01619e |
while (*ch != '\0') {
|
|
|
01619e |
/* This is a special short argument that takes an option. getopt
|
|
|
01619e |
* allows values to be interspersed with a list of arguments, but
|
|
|
01619e |
diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
|
|
|
01619e |
index b8506c6..9a752ef 100644
|
|
|
01619e |
--- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
|
|
|
01619e |
+++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c
|
|
|
01619e |
@@ -1,5 +1,5 @@
|
|
|
01619e |
/*
|
|
|
01619e |
- * Copyright 2020 the Pacemaker project contributors
|
|
|
01619e |
+ * Copyright 2020-2021 the Pacemaker project contributors
|
|
|
01619e |
*
|
|
|
01619e |
* The version control history for this file may have further details.
|
|
|
01619e |
*
|
|
|
01619e |
@@ -86,6 +86,26 @@ long_arg(void) {
|
|
|
01619e |
g_strfreev(processed);
|
|
|
01619e |
}
|
|
|
01619e |
|
|
|
01619e |
+static void
|
|
|
01619e |
+negative_score(void) {
|
|
|
01619e |
+ const char *argv[] = { "-v", "-1000", NULL };
|
|
|
01619e |
+ const gchar *expected[] = { "-v", "-1000", NULL };
|
|
|
01619e |
+
|
|
|
01619e |
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, "v");
|
|
|
01619e |
+ LISTS_EQ(processed, expected);
|
|
|
01619e |
+ g_strfreev(processed);
|
|
|
01619e |
+}
|
|
|
01619e |
+
|
|
|
01619e |
+static void
|
|
|
01619e |
+negative_score_2(void) {
|
|
|
01619e |
+ const char *argv[] = { "-1i3", NULL };
|
|
|
01619e |
+ const gchar *expected[] = { "-1", "-i", "-3", NULL };
|
|
|
01619e |
+
|
|
|
01619e |
+ gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL);
|
|
|
01619e |
+ LISTS_EQ(processed, expected);
|
|
|
01619e |
+ g_strfreev(processed);
|
|
|
01619e |
+}
|
|
|
01619e |
+
|
|
|
01619e |
int
|
|
|
01619e |
main(int argc, char **argv)
|
|
|
01619e |
{
|
|
|
01619e |
@@ -98,5 +118,7 @@ main(int argc, char **argv)
|
|
|
01619e |
g_test_add_func("/common/cmdline/preproc/special_args", special_args);
|
|
|
01619e |
g_test_add_func("/common/cmdline/preproc/special_arg_at_end", special_arg_at_end);
|
|
|
01619e |
g_test_add_func("/common/cmdline/preproc/long_arg", long_arg);
|
|
|
01619e |
+ g_test_add_func("/common/cmdline/preproc/negative_score", negative_score);
|
|
|
01619e |
+ g_test_add_func("/common/cmdline/preproc/negative_score_2", negative_score_2);
|
|
|
01619e |
return g_test_run();
|
|
|
01619e |
}
|
|
|
01619e |
--
|
|
|
01619e |
1.8.3.1
|
|
|
01619e |
|