cli: ensure queries always receive a map
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 10 Oct 2019 14:50:57 +0000 (10:50 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 10 Oct 2019 19:22:43 +0000 (15:22 -0400)
Note that with this commit it's possible to have multiple `--params`
options for the same query object. Before, that the last `--params`
would overwrite any previous ones.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Id63354024a4464cc65ddab2e2e0a168c36dc377d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2164
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cli/babeltrace2-cfg-cli-args.c

index 748738af3df8450b7abecd14d3a6418e394697f8..c6401e1085f65563fe02bbe60877289b4953dc35 100644 (file)
@@ -1480,12 +1480,14 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
        struct bt_config *cfg = NULL;
        const char *component_class_spec = NULL;
        const char *query_object = NULL;
-       bt_value *params;
        GString *error_str = NULL;
        struct bt_argpar_parse_ret argpar_parse_ret = { 0 };
 
-       params = bt_value_null;
-       bt_value_get_ref(bt_value_null);
+       bt_value *params = bt_value_map_create();
+       if (!params) {
+               BT_CLI_LOGE_APPEND_CAUSE_OOM();
+               goto error;
+       }
 
        *retcode = 0;
        cfg = bt_config_query_create(plugin_paths);
@@ -1527,13 +1529,21 @@ struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
                        switch (argpar_item_opt->descr->id) {
                        case OPT_PARAMS:
                        {
-                               bt_value_put_ref(params);
-                               params = bt_param_parse(arg, error_str);
-                               if (!params) {
+                               bt_value *parsed_params = bt_param_parse(arg, error_str);
+                               bt_value_map_extend_status extend_status;
+                               if (!parsed_params) {
                                        BT_CLI_LOGE_APPEND_CAUSE("Invalid format for --params option's argument:\n    %s",
                                                error_str->str);
                                        goto error;
                                }
+
+                               extend_status = bt_value_map_extend(params, parsed_params);
+                               BT_VALUE_PUT_REF_AND_RESET(parsed_params);
+                               if (extend_status) {
+                                       BT_CLI_LOGE_APPEND_CAUSE("Cannot extend current parameters with --params option's argument:\n    %s",
+                                               arg);
+                                       goto error;
+                               }
                                break;
                        }
                        default:
This page took 0.03028 seconds and 4 git commands to generate.