X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fautodisc%2Fautodisc.c;h=0ae53817866924f16e74b0da9b471ccb715f1c01;hp=1b15c1a18cd3b4aa927ea1514be7eafd578a1bb4;hb=HEAD;hpb=764d8fd9edb022ac415f831bec0d262052de0eb1 diff --git a/src/autodisc/autodisc.c b/src/autodisc/autodisc.c index 1b15c1a1..d171a33d 100644 --- a/src/autodisc/autodisc.c +++ b/src/autodisc/autodisc.c @@ -1,36 +1,22 @@ /* - * Copyright (c) 2019 EfficiOS Inc. and Linux Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. + * SPDX-License-Identifier: MIT * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright (c) 2019 EfficiOS Inc. and Linux Foundation */ #define BT_LOG_TAG "CLI-CFG-SRC-AUTO-DISC" -#define BT_LOG_OUTPUT_LEVEL log_level +#define BT_LOG_OUTPUT_LEVEL ((enum bt_log_level) log_level) #include "logging/log.h" +#include + #include "autodisc.h" #include "common/common.h" #define BT_AUTODISC_LOG_AND_APPEND(_lvl, _fmt, ...) \ - do { \ - BT_LOG_WRITE(_lvl, BT_LOG_TAG, _fmt, ##__VA_ARGS__); \ - (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( \ + do { \ + BT_LOG_WRITE_PRINTF(_lvl, BT_LOG_TAG, _fmt, ##__VA_ARGS__); \ + (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( \ "Source auto-discovery", _fmt, ##__VA_ARGS__); \ } while (0) @@ -361,7 +347,7 @@ auto_source_discovery_internal_status support_info_query_all_sources( const bt_component_class_source *source; const bt_plugin *plugin; const bt_value *group; - double weigth; + double weight; } winner = { NULL, NULL, NULL, 0 }; if (interrupter && bt_interrupter_is_set(interrupter)) { @@ -458,17 +444,10 @@ auto_source_discovery_internal_status support_info_query_all_sources( } if (bt_value_map_has_entry(query_result, "group")) { - enum bt_value_type group_value_type; - group_value = bt_value_map_borrow_entry_value_const(query_result, "group"); BT_ASSERT(group_value); - group_value_type = bt_value_get_type(group_value); - - if (group_value_type == BT_VALUE_TYPE_NULL) { - /* Do as if no value was passed. */ - group_value = NULL; - } else if (bt_value_get_type(group_value) != BT_VALUE_TYPE_STRING) { + if (bt_value_get_type(group_value) != BT_VALUE_TYPE_STRING) { BT_LOGW("babeltrace.support-info query: unexpected type for entry `group`: " "component-class-name=source.%s.%s, input=%s, input-type=%s, " "expected-entry-type=%s,%s, actual-entry-type=%s", @@ -496,11 +475,11 @@ auto_source_discovery_internal_status support_info_query_all_sources( } BT_LOGD("babeltrace.support-info query: success: component-class-name=source.%s.%s, input=%s, " - "type=%s, weight=%f\n", + "type=%s, weight=%f, group=%s\n", bt_plugin_get_name(plugin), bt_component_class_get_name(cc), input, - input_type, weight); + input_type, weight, group_value ? bt_value_string_get(group_value) : "(none)"); - if (weight > winner.weigth) { + if (weight > winner.weight) { winner.source = source_cc; winner.plugin = plugin; @@ -508,7 +487,7 @@ auto_source_discovery_internal_status support_info_query_all_sources( winner.group = group_value; bt_value_get_ref(winner.group); - winner.weigth = weight; + winner.weight = weight; } } else if (query_status == BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR) { BT_AUTODISC_LOGE_APPEND_CAUSE("babeltrace.support-info query failed."); @@ -536,8 +515,8 @@ auto_source_discovery_internal_status support_info_query_all_sources( plugin_name = bt_plugin_get_name(winner.plugin); group = winner.group ? bt_value_string_get(winner.group) : NULL; - BT_LOGI("Input %s is awarded to component class source.%s.%s with weight %f", - input, plugin_name, source_name, winner.weigth); + BT_LOGI("Input awarded: input=%s, type=%s, component-class-name=source.%s.%s, weight=%f, group=%s", + input, input_type, plugin_name, source_name, winner.weight, group ? group : "(none)"); status = auto_source_discovery_add(auto_disc, plugin_name, source_name, group, input, original_input_index, log_level); @@ -545,7 +524,7 @@ auto_source_discovery_internal_status support_info_query_all_sources( goto error; } } else { - BT_LOGI("Input %s (%s) was not recognized by any source component class.", + BT_LOGI("Input not recognized: input=%s, type=%s", input, input_type); status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH; } @@ -600,6 +579,7 @@ auto_source_discovery_internal_status auto_discover_source_for_input_as_dir_or_f { auto_source_discovery_internal_status status; GError *error = NULL; + GDir *dir = NULL; if (g_file_test(input->str, G_FILE_TEST_IS_REGULAR)) { /* It's a file. */ @@ -608,7 +588,6 @@ auto_source_discovery_internal_status auto_discover_source_for_input_as_dir_or_f component_class_restrict, log_level, auto_disc, interrupter); } else if (g_file_test(input->str, G_FILE_TEST_IS_DIR)) { - GDir *dir; const gchar *dirent; gsize saved_input_len; int dir_status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH; @@ -633,18 +612,19 @@ auto_source_discovery_internal_status auto_discover_source_for_input_as_dir_or_f dir = g_dir_open(input->str, 0, &error); if (!dir) { - const char *fmt = "Failed to open directory %s: %s"; - BT_LOGW(fmt, input->str, error->message); +#define BT_FMT "Failed to open directory %s: %s" + BT_LOGW(BT_FMT, input->str, error->message); if (error->code == G_FILE_ERROR_ACCES) { /* This is not a fatal error, we just skip it. */ status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH; goto end; } else { - BT_AUTODISC_LOGE_APPEND_CAUSE(fmt, input->str, + BT_AUTODISC_LOGE_APPEND_CAUSE(BT_FMT, input->str, error->message); goto error; } +#undef BT_FMT } saved_input_len = input->len; @@ -678,8 +658,6 @@ auto_source_discovery_internal_status auto_discover_source_for_input_as_dir_or_f } while (dirent); status = dir_status; - - g_dir_close(dir); } else { BT_LOGD("Skipping %s, not a file or directory", input->str); status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH; @@ -691,6 +669,9 @@ error: status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR; end: + if (dir) { + g_dir_close(dir); + } if (error) { g_error_free(error);