fs-sink: explicitely handle stream_begin notif
[babeltrace.git] / cli / babeltrace.c
index 3d37d4e01010d941def39933ab403f28aa1ff7eb..66c74df44b85ca8024f2ef99cc5e07bd3232bbd0 100644 (file)
@@ -26,6 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "CLI"
+#include "logging.h"
+
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/plugin/plugin.h>
 #include <babeltrace/common-internal.h>
@@ -54,9 +57,6 @@
 #include "babeltrace-cfg-cli-args.h"
 #include "babeltrace-cfg-cli-args-default.h"
 
-#define BT_LOG_TAG "CLI"
-#include "logging.h"
-
 #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH"
 
 /* Application's processing graph (weak) */
@@ -65,9 +65,6 @@ static bool canceled = false;
 
 GPtrArray *loaded_plugins;
 
-BT_HIDDEN
-int bt_cli_log_level = BT_LOG_NONE;
-
 static
 void sigint_handler(int signum)
 {
@@ -581,6 +578,19 @@ int load_dynamic_plugins(struct bt_value *plugin_paths)
                plugin_path_value = bt_value_array_get(plugin_paths, i);
                bt_value_string_get(plugin_path_value, &plugin_path);
                assert(plugin_path);
+
+               /*
+                * Skip this if the directory does not exist because
+                * bt_plugin_create_all_from_dir() expects an existing
+                * directory.
+                */
+               if (!g_file_test(plugin_path, G_FILE_TEST_IS_DIR)) {
+                       BT_LOGV("Skipping nonexistent directory path: "
+                               "path=\"%s\"", plugin_path);
+                       BT_PUT(plugin_path_value);
+                       continue;
+               }
+
                plugin_set = bt_plugin_create_all_from_dir(plugin_path, false);
                if (!plugin_set) {
                        BT_LOGD("Unable to load dynamic plugins: path=\"%s\"",
@@ -1180,7 +1190,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                cfg_conn->downstream_comp_name->str);
        assert(downstreamp_comp_name_quark > 0);
        downstream_comp = g_hash_table_lookup(ctx->components,
-               (gpointer) (long) downstreamp_comp_name_quark);
+               GUINT_TO_POINTER(downstreamp_comp_name_quark));
        if (!downstream_comp) {
                BT_LOGE("Cannot find downstream component:  comp-name=\"%s\", "
                        "conn-arg=\"%s\"", cfg_conn->downstream_comp_name->str,
@@ -1494,25 +1504,29 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
        the_graph = ctx->graph;
        ret = bt_graph_add_port_added_listener(ctx->graph,
                graph_port_added_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"port added\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_port_removed_listener(ctx->graph,
                graph_port_removed_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"port removed\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_ports_connected_listener(ctx->graph,
                graph_ports_connected_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"ports connected\" listener to graph.");
                goto error;
        }
 
        ret = bt_graph_add_ports_disconnected_listener(ctx->graph,
                graph_ports_disconnected_listener, ctx);
-       if (ret) {
+       if (ret < 0) {
+               BT_LOGE_STR("Cannot add \"ports disconnected\" listener to graph.");
                goto error;
        }
 
@@ -1582,7 +1596,7 @@ int cmd_run_ctx_create_components_from_config_components(
                quark = g_quark_from_string(cfg_comp->instance_name->str);
                assert(quark > 0);
                g_hash_table_insert(ctx->components,
-                       (gpointer) (long) quark, comp);
+                       GUINT_TO_POINTER(quark), comp);
                comp = NULL;
                BT_PUT(comp_cls);
        }
@@ -1732,6 +1746,13 @@ int cmd_run(struct bt_config *cfg)
                goto error;
        }
 
+       if (canceled) {
+               BT_LOGI_STR("Canceled by user before creating components.");
+               goto error;
+       }
+
+       BT_LOGI_STR("Creating components.");
+
        /* Create the requested component instances */
        if (cmd_run_ctx_create_components(&ctx)) {
                BT_LOGE_STR("Cannot create components.");
@@ -1739,6 +1760,13 @@ int cmd_run(struct bt_config *cfg)
                goto error;
        }
 
+       if (canceled) {
+               BT_LOGI_STR("Canceled by user before connecting components.");
+               goto error;
+       }
+
+       BT_LOGI_STR("Connecting components.");
+
        /* Connect the initially visible component ports */
        if (cmd_run_ctx_connect_ports(&ctx)) {
                BT_LOGE_STR("Cannot connect initial component ports.");
@@ -1747,7 +1775,8 @@ int cmd_run(struct bt_config *cfg)
        }
 
        if (canceled) {
-               goto end;
+               BT_LOGI_STR("Canceled by user before running the graph.");
+               goto error;
        }
 
        BT_LOGI_STR("Running the graph.");
@@ -1841,31 +1870,7 @@ void warn_command_name_and_directory_clash(struct bt_config *cfg)
 static
 void init_log_level(void)
 {
-       enum bt_logging_level log_level = BT_LOG_NONE;
-       const char *log_level_env = getenv("BABELTRACE_CLI_LOG_LEVEL");
-
-       if (!log_level_env) {
-               goto set_level;
-       }
-
-       if (strcmp(log_level_env, "VERBOSE") == 0) {
-               log_level = BT_LOGGING_LEVEL_VERBOSE;
-       } else if (strcmp(log_level_env, "DEBUG") == 0) {
-               log_level = BT_LOGGING_LEVEL_DEBUG;
-       } else if (strcmp(log_level_env, "INFO") == 0) {
-               log_level = BT_LOGGING_LEVEL_INFO;
-       } else if (strcmp(log_level_env, "WARN") == 0) {
-               log_level = BT_LOGGING_LEVEL_WARN;
-       } else if (strcmp(log_level_env, "ERROR") == 0) {
-               log_level = BT_LOGGING_LEVEL_ERROR;
-       } else if (strcmp(log_level_env, "FATAL") == 0) {
-               log_level = BT_LOGGING_LEVEL_FATAL;
-       } else if (strcmp(log_level_env, "NONE") == 0) {
-               log_level = BT_LOGGING_LEVEL_NONE;
-       }
-
-set_level:
-       bt_cli_log_level = log_level;
+       bt_cli_log_level = bt_log_get_level_from_env("BABELTRACE_CLI_LOG_LEVEL");
 }
 
 void set_sigint_handler(void)
This page took 0.028485 seconds and 4 git commands to generate.