Clean-up: clang-tidy: missing headers prevent analysis clang-tidy complains that some headers omit the inclusion of their dependencies, which prevents the analysis from completing. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ic6d51e82c5f5536c0d421c38a97afddbe64a16ef
sessiond: lttng: Add command to check kernel tracer status Issue observed -------------- When `lttng enable-channel --kernel` fails, little feedback is available to user to help them to understand the cause. Eg. ``` Error: Channel asdf: Kernel tracer not available (session auto-20231123-092621) ``` Solution -------- The semantic status of the kernel tracer is tracked and persisted in the session daemon (through `init_kernel_tracer` and `cleanup_tracer_tracer`. A new client command `lttng_kernel_tracer_status` is added to request the current value of the `kernel_tracer_status`. The `lttng` client uses this command after enabling a kernel-domain channel fails to provide the user with a more specific cause of the failure. Eg. ``` Error: Channel asdf: Kernel tracer not available (session auto-20231123-092621) Missing one or more required kernel modules Consult lttng-sessiond logs for more information ``` The kernel tracer status is tracked with an enum defined in `include/lttng/kernel.h` to avoid passing potentially different errno values or locale-dependant strings between the LTTng client and session daemon. Loading modules and checking signatures can fail with a number of different errno values. For example: C.f. https://gitlab.com/linux-kernel/stable/-/blob/master/kernel/module/signing.c#L70 * `EKEYREJECTED` * Any other error code C.f. https://gitlab.com/linux-kernel/stable/-/blob/master/Documentation/security/keys/core.rst * `EKEYREVOKED` * `EKEYEXPIRED` * `ENOKEY` * Others, such as `ENOMEM` Known drawbacks --------------- None. Signed-off-by: Kienan Stewart <kstewart@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I2ae4b188f0110a472200c2511439b9e3e600527d
License: common: error_query: fix typo in SPDX specifier The error-query API files were erroneously licensed under "GPL-2.1", a license which doesn't exist. As the author of those files, I hereby confirm that the intention was to license these files under LGPL-2.1 as evidenced by their presence in the libcommon_lgpl internal library. Reported-by: Christophe Bedard <christophe.bedard@apex.ai> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I0d56372ca009e44732e0737bd8f10ad4a4d000c5
Move lttng_session unique_ptr to lttng/session-internal.hpp Make it possible to use this unique_ptr elsewhere. Change-Id: I30141efac45d842f4bc3414ca03fffb2e4ba5cce Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix clang-tidy cppcoreguidelines-pro-type-const-cast warning clang-tidy reports: cppcoreguidelines-pro-type-const-cast; do not use const_cast The const_cast adds a const qualifier so this warning seems a bit strict. Regardless, we can dodge the whole question by passing the exclusion_list as `const char * const *`, which is closer to the original intention of the API anyhow. For more information on the safety of these types of casts, see: https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ia3129b7d1ed4e450f3f2d63920d2fd67c66a6d73
Fix: sessiond: incorrect use of exclusions array leads to crash Issue observed -------------- When using the CLI to list the configuration of a session that has an event rule which makes use of multiple exclusions, the session daemon crashes with the following stack trace: (gdb) bt #0 0x00007fa9ed401445 in ?? () from /usr/lib/libc.so.6 #1 0x0000560cd5fc5199 in lttng_strnlen (str=0x615f6f6c6c6568 <error: Cannot access memory at address 0x615f6f6c6c6568>, max=256) at ../../src/common/compat/string.h:19 #2 0x0000560cd5fc6b39 in lttng_event_serialize (event=0x7fa9cc01d8b0, exclusion_count=2, exclusion_list=0x7fa9cc011794, filter_expression=0x0, bytecode_len=0, bytecode=0x0, payload=0x7fa9d3ffda88) at event.c:767 #3 0x0000560cd5f380b5 in list_lttng_ust_global_events (nb_events=<synthetic pointer>, reply_payload=0x7fa9d3ffda88, ust_global=<optimized out>, channel_name=<optimized out>) at cmd.c:472 #4 cmd_list_events (domain=<optimized out>, session=<optimized out>, channel_name=<optimized out>, reply_payload=0x7fa9d3ffda88) at cmd.c:3860 #5 0x0000560cd5f6d76a in process_client_msg (cmd_ctx=0x7fa9d3ffa710, sock=0x7fa9d3ffa5b0, sock_error=0x7fa9d3ffa5b4) at client.c:1890 #6 0x0000560cd5f6f876 in thread_manage_clients (data=0x560cd7879490) at client.c:2629 #7 0x0000560cd5f65a54 in launch_thread (data=0x560cd7879500) at thread.c:66 #8 0x00007fa9ed32d44b in ?? () from /usr/lib/libc.so.6 #9 0x00007fa9ed3b0e40 in ?? () from /usr/lib/libc.so.6 Cause ----- lttng_event_serialize expects a `char **` list of exclusion names, as provided by the other callsite in liblttng-ctl. However, the callsite in list_lttng_ust_global_events passes pointer to the exclusions as stored in lttng_event_exclusion. lttng_event_exclusion contains an array of fixed-length strings (with a stride of 256 bytes) which isn't an expected layout for lttng_event_serialize. Solution -------- A temporary array of pointers is constructed before invoking lttng_event_serialize to construct a list of exclusions with the layout that lttng_event_serialize expects. The array itself is reused for all events, limiting the number of allocations. Note ---- None. Change-Id: I266a1cc9e9f18e0476177a0047b1d8f468110575 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Provide an idiomatic c++ interface for action lists Replace for_each macros with the use of an iterator. It is done by using a random_access_container_wrapper util which is intended to wrap random_access containers implemented in C. Change-Id: I1b22725b7335f267c9b2d02fc65f9375baf37426 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
actions: list: Add `for_each_action_{const, mutable}()` macros Accessing all the inner actions of a action list in a loop is a common access pattern. This commit adds 2 `for_each` macros to iterate over all elements either using a const or a mutable pointer. Add a few unit tests for the list action to test these macros. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I9aff0b81e1f782b5d20c3fcb82ee7028da8dd810
Move create_unique_class util to the memory namespace create_unique_class is helpful to write unique_ptr wrappers and is now accessed in numerous places even though it lives in the `details` namespace. Moving it to the `memory` namespace to live with other memory management facilities. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Id4bb5100c1eb3a7e1e2d65f5b2d40ff8f97c786e
Clean-up: run format-cpp on the tree The original re-format commit missed a number of files that were caught by format-cpp. Hopefully this is the last large reformat commit for a while. Change-Id: I493ee6d9fe6187e0bd087c68ed346af69c929c1e Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Cleanup: rotation-thread: enforce conding standard following fix A fix introducing rotate_notification_channel_subscription_change_eventfd didn't follow the current coding standard so as to make it easier to backport to the stable branches. Clean-up the affected code to follow the current standard: - Replace the use of a raw eventfd to use the eventfd utility, - Subscribe and unsubscribe functions made use of global variables to communicate with the rotation thread: replace that with the rotation_thread class to centralize the interface, - Make the code using eventfd exception-safe (automatic memory management, use of various RAII utils), - Replacement of non-null pointers by references. Change-Id: I7e363e21b829fd0939a336aca2570fdbcc346967 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
clang-tidy: add Chrome-inspired checks Add the checks used by the Chrome project. Most of these changes were produced and applied by clang-tidy. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I4058dafbdef00e81ac04f202fdfe377384a99e6b
Add a basic .clang-tidy file and fix typedef warnings This initial .clang-tidy file only enforces the use of 'using' instead of 'typedef'. Note that a second .clang-tidy is added to the filter sub-folder to disable checks against generated code. The entire tree can be checked by running `run-clang-tidy` after generating a compilation command database. I personally use `bear` to generate `compile_commands.json`. $ ./configure $ bear -- make -j$(nproc) $ run-clang-tidy -fix Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I074b6f2724e1af9a2df311e07a2fcdacb689bcf5
sessiond-comm: prefix lttcomm_sessiond_command entries Add LTTCOMM_SESSIOND_COMMAND as the prefix of sessiond client commands to honor the usual namespacing convention. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ie0f9c5282d442e27bcdbbf390ab23d6076c413de
Fix: sessiond: size-based rotations never trigger Issue observed ============== Size-based scheduled rotations have no effect. Cause ===== Since c08136a3f, the rotation thread's handle_condition() checks that the notification received matches the trigger that was registered. As part of the equality check, the triggers' credentials are compared. This checks fails systematically since the group id of a trigger's credentials is not transported by the serialize/create_from functions. The trigger that is received through the notification thus has an unset group id, while the rotation trigger of the `ltt_session` has a group id set; it was not stripped by the communication layer. The check also fails since the trigger registered for the size-based rotation is "hidden". This internal attribute is not propagated through the communication layer, which causes the comparison to fail. Solution ======== Since triggers only use the 'uid' part of lttng_credentials, we ensure that lttng_trigger_set_credentials only sets this part of the structure. Also, the `is_hidden` attribute of a trigger is now propagated through the communication layer. This has no effect for external applications since this attribute is not exposed through the API. However, it is useful for internal triggers which use the same communication facilities. This allows the equality check in rotation-thread.cpp to go through as expected. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I216f5cb9297ecd1a867dc292c10b8da595efce34
Fix: sessiond: rotation trigger leak ==1801304==ERROR: LeakSanitizer: detected memory leaks Direct leak of 224 byte(s) in 2 object(s) allocated from: #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x559fbeb64175 in zmalloc_internal ../../src/common/macros.hpp:60 #2 0x559fbeb6a291 in lttng_trigger* zmalloc<lttng_trigger>() ../../src/common/macros.hpp:89 #3 0x559fbeb64aa6 in lttng_trigger_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/trigger.cpp:58 #4 0x559fbe9dc417 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:87 #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993 #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246 #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #9 0x7fe0f44935c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) Indirect leak of 208 byte(s) in 2 object(s) allocated from: #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x559fbeb16e21 in zmalloc_internal ../../src/common/macros.hpp:60 #2 0x559fbeb16e31 in lttng_action_notify* zmalloc<lttng_action_notify>() ../../src/common/macros.hpp:89 #3 0x559fbeb168a0 in lttng_action_notify_create actions/notify.cpp:135 #4 0x559fbe9dc34b in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:80 #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993 #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246 #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #9 0x7fe0f44935c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) Indirect leak of 160 byte(s) in 2 object(s) allocated from: #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x559fbeb3d7a1 in zmalloc_internal ../../src/common/macros.hpp:60 #2 0x559fbeb3fa35 in lttng_condition_session_consumed_size* zmalloc<lttng_condition_session_consumed_size>() ../../src/common/macros.hpp:89 #3 0x559fbeb3e6fd in lttng_condition_session_consumed_size_create conditions/session-consumed-size.cpp:206 #4 0x559fbe9dc0f1 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:54 #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993 #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246 #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #9 0x7fe0f44935c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) Indirect leak of 112 byte(s) in 2 object(s) allocated from: #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x559fbeb242ad in zmalloc_internal ../../src/common/macros.hpp:60 #2 0x559fbeb27062 in zmalloc<(anonymous namespace)::lttng_rate_policy_every_n> ../../src/common/macros.hpp:89 #3 0x559fbeb25e9f in lttng_rate_policy_every_n_create actions/rate-policy.cpp:492 #4 0x559fbeb168b9 in lttng_action_notify_create actions/notify.cpp:141 #5 0x559fbe9dc34b in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:80 #6 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993 #7 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246 #8 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #9 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #10 0x7fe0f44935c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) Indirect leak of 34 byte(s) in 2 object(s) allocated from: #0 0x7fe0f4e19319 in __interceptor_strdup /usr/src/debug/gcc/libsanitizer/asan/asan_interceptors.cpp:454 #1 0x559fbeb3f603 in lttng_condition_session_consumed_size_set_session_name conditions/session-consumed-size.cpp:442 #2 0x559fbe9dc2c4 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:71 #3 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993 #4 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246 #5 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #6 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #7 0x7fe0f44935c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) The rotation trigger of a session (used for size-based rotations) is never cleaned-up. It is now cleaned up every time its condition is hit and whenever the session is destroyed. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I5a89341535f87b7851b548ded9838c18bd1ccb95
Fix: action error query: leak of action path ==1429021==ERROR: LeakSanitizer: detected memory leaks Direct leak of 8 byte(s) in 1 object(s) allocated from: #0 0x7fe305f031b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164 #1 0x559f1b022238 in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159 #2 0x559f1b021d9f in lttng_dynamic_buffer_append(lttng_dynamic_buffer*, void const*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:52 #3 0x559f1b02144a in lttng_dynamic_array_add_element(lttng_dynamic_array*, void const*) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-array.cpp:58 #4 0x559f1b07d07b in lttng_action_path_copy(lttng_action_path const*, lttng_action_path*) actions/path.cpp:116 #5 0x559f1b02383f in lttng_error_query_action_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:232 #6 0x559f1b02760e in lttng_error_query_create_from_payload(lttng_payload_view*, lttng_error_query**) /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:911 #7 0x559f1af5c361 in receive_lttng_error_query /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:740 #8 0x559f1af64eba in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2336 #9 0x559f1af67378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624 #10 0x559f1af50642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68 #11 0x7fe3055225c1 in start_thread (/usr/lib/libc.so.6+0x8d5c1) Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I7a6f7d2a9746124581eebf30877466f16db67a6b