plugins: call bt_current_thread_clear_error() when not propagating error
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 20:31:56 +0000 (16:31 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 6 Jul 2019 03:47:50 +0000 (23:47 -0400)
Most of the locations where bt_current_thread_clear_error() is called in
this patch need to be replaced with proper error handling, except in
finalization methods which cannot fail. This work will be done by a
subsequent patch.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I10fb2eb98f46e685e6abf563346a2750b46b01d9
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1613
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/plugins/ctf/lttng-live/data-stream.c
src/plugins/lttng-utils/debug-info/debug-info.c
src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-mapping.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
src/plugins/text/details/details.c

index d759e3635da8b23a94aab8b6daf04d01f768c23b..b94bbd382ce5be665785e2a3d979d8a54f0a23f6 100644 (file)
@@ -111,11 +111,14 @@ bt_stream *medop_borrow_stream(bt_stream_class *stream_class,
                                "%" PRId64 ", stream ID %" PRIu64 ")",
                                lttng_live_stream->name->str,
                                stream_class_id, stream_id);
+                       goto end;
                }
+
                bt_stream_set_name(lttng_live_stream->stream,
                        lttng_live_stream->name->str);
        }
 
+end:
        return lttng_live_stream->stream;
 }
 
index 80f96e7b5e5f1dc758a28849013585533d03cd25..ef76225beec6a198264001c92517a4e41ac620cf 100644 (file)
@@ -588,6 +588,7 @@ void debug_info_destroy(struct debug_info *debug_info)
                        debug_info->destruction_listener_id);
        if (remove_listener_status != BT_TRACE_REMOVE_LISTENER_STATUS_OK) {
                BT_COMP_LOGE("Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(debug_info);
@@ -890,13 +891,17 @@ void handle_event_statedump(struct debug_info_msg_iter *debug_it,
 
        debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace);
        if (!debug_info) {
+               bt_trace_add_listener_status add_listener_status;
+
                debug_info = debug_info_create(debug_it->debug_info_component,
                                trace, &debug_it->fd_cache);
                g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace,
                                debug_info);
-               bt_trace_add_destruction_listener(trace,
-                               trace_debug_info_remove_func, debug_it,
+               add_listener_status = bt_trace_add_destruction_listener(
+                               trace, trace_debug_info_remove_func,
+                               debug_it,
                                &debug_info->destruction_listener_id);
+               BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK);
        }
 
        q_event_name = g_quark_try_string(event_name);
@@ -968,6 +973,7 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src,
                        BT_COMP_LOGE("Cannot set path component of \"bin\" "
                                "curr_field field's value: str-fc-addr=%p",
                                curr_field);
+                       bt_current_thread_clear_error();
                }
 
                append_status = bt_field_string_append(curr_field,
@@ -976,12 +982,14 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src,
                        BT_COMP_LOGE("Cannot set bin location component of \"bin\" "
                                "curr_field field's value: str-fc-addr=%p",
                                curr_field);
+                       bt_current_thread_clear_error();
                }
        } else {
                set_status = bt_field_string_set_value(curr_field, "");
                if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                        BT_COMP_LOGE("Cannot set \"bin\" curr_field field's value: "
                                "str-fc-addr=%p", curr_field);
+                       bt_current_thread_clear_error();
                }
        }
 }
@@ -1004,6 +1012,7 @@ void fill_debug_info_func_field(struct debug_info_source *dbg_info_src,
        if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                BT_COMP_LOGE("Cannot set \"func\" curr_field field's value: "
                        "str-fc-addr=%p", curr_field);
+               bt_current_thread_clear_error();
        }
 }
 
@@ -1031,6 +1040,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src,
                        BT_COMP_LOGE("Cannot set path component of \"src\" "
                                "curr_field field's value: str-fc-addr=%p",
                                curr_field);
+                       bt_current_thread_clear_error();
                }
 
                append_status = bt_field_string_append(curr_field, ":");
@@ -1038,6 +1048,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src,
                        BT_COMP_LOGE("Cannot set colon component of \"src\" "
                                "curr_field field's value: str-fc-addr=%p",
                                curr_field);
+                       bt_current_thread_clear_error();
                }
 
                append_status = bt_field_string_append(curr_field,
@@ -1046,12 +1057,14 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src,
                        BT_COMP_LOGE("Cannot set line number component of \"src\" "
                                "curr_field field's value: str-fc-addr=%p",
                                curr_field);
+                       bt_current_thread_clear_error();
                }
        } else {
                set_status = bt_field_string_set_value(curr_field, "");
                if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                        BT_COMP_LOGE("Cannot set \"src\" curr_field field's value: "
                                "str-fc-addr=%p", curr_field);
+                       bt_current_thread_clear_error();
                }
        }
 }
@@ -1084,18 +1097,21 @@ void fill_debug_info_field_empty(bt_field *debug_info_field,
        if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                BT_COMP_LOGE("Cannot set \"bin\" bin_field field's value: "
                        "str-fc-addr=%p", bin_field);
+               bt_current_thread_clear_error();
        }
 
        status = bt_field_string_set_value(func_field, "");
        if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                BT_COMP_LOGE("Cannot set \"func\" func_field field's value: "
                        "str-fc-addr=%p", func_field);
+               bt_current_thread_clear_error();
        }
 
        status = bt_field_string_set_value(src_field, "");
        if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) {
                BT_COMP_LOGE("Cannot set \"src\" src_field field's value: "
                        "str-fc-addr=%p", src_field);
+               bt_current_thread_clear_error();
        }
 }
 static
@@ -1366,11 +1382,13 @@ bt_message *handle_stream_end_message(struct debug_info_msg_iter *debug_it,
        if (!out_message) {
                BT_COMP_LOGE("Error creating output stream end message: out-s-addr=%p",
                                out_stream);
+               goto end;
        }
 
        /* Remove stream from trace mapping hashtable. */
        trace_ir_mapping_remove_mapped_stream(debug_it->ir_maps, in_stream);
 
+end:
        return out_message;
 }
 
@@ -1462,11 +1480,13 @@ bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it,
        if (!out_message) {
                BT_COMP_LOGE("Error creating output packet end message: "
                        "out-p-addr=%p", out_packet);
+               goto end;
        }
 
        /* Remove packet from data mapping hashtable. */
        trace_ir_mapping_remove_mapped_packet(debug_it->ir_maps, in_packet);
 
+end:
        return out_message;
 }
 
index 39cb9fb7bbf6a9f54e8abb6617ef7b81aef14750..feb8347b92a27cf1a4bc55ec57612d66e20ee85f 100644 (file)
@@ -51,6 +51,7 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
                if (status != BT_TRACE_SET_NAME_STATUS_OK) {
                        BT_COMP_LOGE("Cannot set trace's name: trace-addr=%p, name=\"%s\"",
                                out_trace, trace_name);
+                       bt_current_thread_clear_error();
                        goto end;
                }
        }
@@ -190,6 +191,8 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        BT_COMP_LOGE("Cannot set string field's value: "
                                "str-field-addr=%p, str=%s" PRId64,
                                out_field, str);
+                       bt_current_thread_clear_error();
+
                }
                break;
        }
@@ -249,6 +252,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                                BT_COMP_LOGE("Cannot set dynamic array field's "
                                        "length field: field-addr=%p, "
                                        "length=%" PRIu64, out_field, array_len);
+                               bt_current_thread_clear_error();
                        }
                }
 
@@ -281,6 +285,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        BT_COMP_LOGE("Cannot select variant field's option field: "
                                "var-field-addr=%p, opt-index=%" PRId64,
                                out_field, in_selected_option_idx);
+                       bt_current_thread_clear_error();
                }
 
                in_option_field = bt_field_variant_borrow_selected_option_field_const(in_field);
index 1f50c30487519d5e0a0e7527f03895d0a84b448b..ec074d5dc56a65c6cd831744eec98733d621efa6 100644 (file)
@@ -484,6 +484,8 @@ struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_ma
 {
        struct trace_ir_data_maps *d_maps =
                g_new0(struct trace_ir_data_maps, 1);
+       bt_trace_add_listener_status add_listener_status;
+
        if (!d_maps) {
                BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
                goto error;
@@ -499,8 +501,11 @@ struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_ma
        d_maps->packet_map = g_hash_table_new_full(g_direct_hash,
                        g_direct_equal, NULL,(GDestroyNotify) bt_packet_put_ref);
 
-       bt_trace_add_destruction_listener(in_trace, trace_ir_data_maps_remove_func,
-                       ir_maps, &d_maps->destruction_listener_id);
+       add_listener_status = bt_trace_add_destruction_listener(
+               in_trace, trace_ir_data_maps_remove_func,
+               ir_maps, &d_maps->destruction_listener_id);
+       BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK);
+
 error:
        return d_maps;
 }
@@ -511,6 +516,8 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
 {
        struct trace_ir_metadata_maps *md_maps =
                g_new0(struct trace_ir_metadata_maps, 1);
+       bt_trace_class_add_listener_status add_listener_status;
+
        if (!md_maps) {
                BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
                goto error;
@@ -541,9 +548,13 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
        md_maps->clock_class_map = g_hash_table_new_full(g_direct_hash,
                        g_direct_equal, NULL, (GDestroyNotify) bt_clock_class_put_ref);
 
-       bt_trace_class_add_destruction_listener(in_trace_class,
+       add_listener_status = bt_trace_class_add_destruction_listener(
+                       in_trace_class,
                        trace_ir_metadata_maps_remove_func,
                        ir_maps, &md_maps->destruction_listener_id);
+       BT_ASSERT(add_listener_status ==
+               BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK);
+
 error:
        return md_maps;
 }
@@ -575,6 +586,7 @@ void trace_ir_data_maps_destroy(struct trace_ir_data_maps *maps)
                BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
                        maps->self_comp,
                        "Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(maps);
@@ -620,6 +632,7 @@ void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *maps)
                BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
                        maps->self_comp,
                        "Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(maps);
index 353cfb1021b271bbcd893953b446d84ae9c62b18..2b3970fca43dd538fcf62b1f7cca084c6e10dd8f 100644 (file)
@@ -56,7 +56,13 @@ int copy_trace_class_content(const bt_trace_class *in_trace_class,
 
        in_trace_class_name = bt_trace_class_get_name(in_trace_class);
        if (in_trace_class_name) {
-               bt_trace_class_set_name(out_trace_class, in_trace_class_name);
+               bt_trace_class_set_name_status status;
+
+               status = bt_trace_class_set_name(out_trace_class,
+                       in_trace_class_name);
+               if (status != BT_TRACE_CLASS_SET_NAME_STATUS_OK) {
+                       bt_current_thread_clear_error();
+               }
        }
 
        /*
index 37951910138eb330c402e7efbc213bfb233c90de..cd48a87c7b3e003e7a0a0d6acf221a4fb070a654 100644 (file)
@@ -139,9 +139,11 @@ void destroy_details_comp(struct details_comp *details_comp)
 
                        if (details_tc_meta->tc_destruction_listener_id !=
                                        UINT64_C(-1)) {
-                               bt_trace_class_remove_destruction_listener(
-                                       (const void *) key,
-                                       details_tc_meta->tc_destruction_listener_id);
+                               if (bt_trace_class_remove_destruction_listener(
+                                               (const void *) key,
+                                               details_tc_meta->tc_destruction_listener_id)) {
+                                       bt_current_thread_clear_error();
+                               }
                        }
                }
 
@@ -160,9 +162,11 @@ void destroy_details_comp(struct details_comp *details_comp)
                while (g_hash_table_iter_next(&iter, &key, &value)) {
                        struct details_trace *details_trace = value;
 
-                       bt_trace_remove_destruction_listener(
-                               (const void *) key,
-                               details_trace->trace_destruction_listener_id);
+                       if (bt_trace_remove_destruction_listener(
+                                       (const void *) key,
+                                       details_trace->trace_destruction_listener_id)) {
+                               bt_current_thread_clear_error();
+                       }
                }
 
                g_hash_table_destroy(details_comp->traces);
This page took 0.029979 seconds and 4 git commands to generate.