lttng: enable-event: print kernel tracer status on error
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 27 Feb 2024 04:09:37 +0000 (23:09 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Feb 2024 15:41:26 +0000 (10:41 -0500)
Use the new kernel status query API to present a more descriptive error
when a kernel event rule fails to be enabled.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Icad2518bacec1a9ab3103a44052c0085eadda1a7

src/bin/lttng/commands/enable_events.cpp

index 095a3df38cde77e589379e903c0687dc85ab44d1..f827c924d9c483ec50143fb9a1172845b7df6710 100644 (file)
@@ -709,8 +709,6 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                }
 
                if (!opt_filter) {
-                       char *exclusion_string;
-
                        command_ret = lttng_enable_event_with_exclusions(
                                handle,
                                ev,
@@ -718,7 +716,9 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                nullptr,
                                lttng_dynamic_pointer_array_get_count(&exclusions),
                                (char **) exclusions.array.buffer.data);
-                       exclusion_string = print_exclusions(&exclusions);
+
+                       auto exclusion_string = lttng::make_unique_wrapper<char, lttng::free>(
+                               print_exclusions(&exclusions));
                        if (!exclusion_string) {
                                PERROR("Cannot allocate exclusion_string");
                                error = 1;
@@ -734,7 +734,7 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                              (std::string("with pattern `") +
                                                               pattern + std::string("`"))
                                                                      .c_str(),
-                                            exclusion_string,
+                                            exclusion_string.get(),
                                             print_channel_name(channel_name),
                                             session_name.c_str());
                                        warn = 1;
@@ -759,12 +759,17 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                             (std::string("with pattern `") +
                                                              pattern + std::string("`"))
                                                                     .c_str(),
-                                           exclusion_string,
+                                           exclusion_string.get(),
                                            command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME ?
                                                    print_raw_channel_name(channel_name) :
                                                    print_channel_name(channel_name),
                                            lttng_strerror(command_ret),
                                            session_name.c_str());
+
+                                       if (opt_kernel) {
+                                               print_kernel_tracer_status_error();
+                                       }
+
                                        error = 1;
                                        break;
                                }
@@ -780,7 +785,7 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                             (std::string("with pattern `") +
                                                              pattern + std::string("`"))
                                                                     .c_str(),
-                                           exclusion_string,
+                                           exclusion_string.get(),
                                            print_channel_name(channel_name));
                                        break;
                                }
@@ -797,17 +802,13 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                             (std::string("with pattern `") +
                                                              pattern + std::string("`"))
                                                                     .c_str(),
-                                           exclusion_string);
+                                           exclusion_string.get());
                                        break;
                                default:
                                        abort();
                                }
                        }
-
-                       free(exclusion_string);
                } else {
-                       char *exclusion_string;
-
                        /* Filter present */
                        ev->filter = 1;
 
@@ -818,7 +819,9 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                opt_filter,
                                lttng_dynamic_pointer_array_get_count(&exclusions),
                                (char **) exclusions.array.buffer.data);
-                       exclusion_string = print_exclusions(&exclusions);
+
+                       auto exclusion_string = lttng::make_unique_wrapper<char, lttng::free>(
+                               print_exclusions(&exclusions));
                        if (!exclusion_string) {
                                PERROR("Failed allocate exclusion string");
                                error = 1;
@@ -832,7 +835,7 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                              (std::string("with pattern `") +
                                                               pattern + std::string("`"))
                                                                      .c_str(),
-                                            exclusion_string,
+                                            exclusion_string.get(),
                                             opt_filter,
                                             print_channel_name(channel_name));
                                        warn = 1;
@@ -850,7 +853,7 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                             (std::string("with pattern `") +
                                                              pattern + std::string("`"))
                                                                     .c_str(),
-                                           exclusion_string,
+                                           exclusion_string.get(),
                                            opt_filter,
                                            command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME ?
                                                    print_raw_channel_name(channel_name) :
@@ -858,6 +861,11 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                            lttng_strerror(command_ret),
                                            session_name.c_str());
                                        error = 1;
+
+                                       if (opt_kernel) {
+                                               print_kernel_tracer_status_error();
+                                       }
+
                                        break;
                                }
 
@@ -870,11 +878,9 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa
                                                      std::string("`"))
                                                             .c_str(),
 
-                                   exclusion_string,
+                                   exclusion_string.get(),
                                    opt_filter);
                        }
-
-                       free(exclusion_string);
                }
 
                if (lttng_opt_mi) {
This page took 0.029457 seconds and 4 git commands to generate.