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>
lib: compile liblttng-ctl as C++ Same as the previous commits, but compile the liblttng-ctl library as C++ code (while still offering a C interface). Some exported global variables (for example in deprecated-symbols.cpp) have to be made non-const, otherwise we get: CXX deprecated-symbols.lo /home/simark/src/lttng-tools/src/lib/lttng-ctl/deprecated-symbols.cpp:21:33: error: ‘visibility’ attribute ignored [-Werror=attributes] 21 | LTTNG_EXPORT const char * const config_element_pid_tracker; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ I think this is related to the fact that const global variables automatically have internal linkage in C++. Despite using -export-symbols in src/lib/lttng-ctl/Makefile.am, some new ELF symbols become exposed. It could be related to this, in the ld man page: --retain-symbols-file does not discard undefined symbols, or symbols needed for relocations. One new symbol I see, for example, is `_Z16connect_sessiondv`. Looking at liblttng-ctl.so, I indeed see a relocation for this symbol: 000000000010b778 0000053e00000007 R_X86_64_JUMP_SLOT 00000000000314a2 _Z16connect_sessiondv + 0 And that would explain why the linker keeps that symbol visible. This is related to the entry for this function in the procedure linkage table. I'm not entirely sure why these functions didn't generate a PLT entry in C, but do in C++. To avoid these new symbols, build everything with -fvisibility=hidden and -fvisibility-inlines-hidden, and tag functions we really want to export with LTTNG_EXPORT, a new macro defined to __attribute__((visibility("default"))). This macro is publicly visible, because it has to be used in distributed header files (although it's of no use for users of liblttng-ctl). Change-Id: Ie51bf0a2edfb87e5f46f9c39eed5309d9f8c41d6 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bin: compile lttng-sessiond as C++ Same as commit 48a400056134 ("bin: compile lttng as C++"), but change lttng-sessiond to be a C++ program. In addition to the categories of changes already mentioned in that commit's message, here are some interesting changes: - Add an include in trigger.h, an exported header, to fix: CXX notification-thread.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/notification-thread.cpp:9: /home/simark/src/lttng-tools/include/lttng/trigger/trigger.h:142:13: error: use of enum ‘lttng_error_code’ without previous declaration 142 | extern enum lttng_error_code lttng_register_trigger_with_name( | ^~~~~~~~~~~~~~~~ - We get this with clang: CXX lttng-conf.o In file included from /home/simark/src/lttng-tools/src/bin/lttng/conf.cpp:18: In file included from /home/simark/src/lttng-tools/src/common/common.h:14: In file included from /home/simark/src/lttng-tools/src/common/runas.h:17: In file included from /home/simark/src/lttng-tools/src/common/sessiond-comm/sessiond-comm.h:38: In file included from /home/simark/src/lttng-tools/src/common/unix.h:17: /home/simark/src/lttng-tools/src/common/payload-view.h:82:27: error: 'lttng_payload_view_from_payload' has C-linkage specified, but returns user-defined type 'struct lttng_payload_view' which is incompatible with C [-Werror,-Wreturn-type-c-linkage] struct lttng_payload_view lttng_payload_view_from_payload( ^ Turns out that because of the "const" field in lttng_payload_view, clang doesn't consider that type incompatible with C. I don't really want to remove the "const" for C code using that API, so conditionally remove it if we are compiling with clang in C++. - clang gives: CXX event.lo In file included from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/event.cpp:19: /home/simark/src/lttng-tools/src/common/bytecode/bytecode.h:50:1: error: struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] struct literal_string { ^ It looks like that type isn't even used? Remove it. - it's not possible to initialize some union members, for example with lttcomm_consumer_msg, in consumer.cpp. Initialize it in a separate statement. - It's not possible to use the transparent union trick when calling urcu function, for example in thread_application_registration, in register.cpp. We need to instantiate a cds_wfcq_head_ptr_t object, assign the appropriate field, and pass that object to the function. - the ALIGNED_CONST_PTR trick does not work in C++: CXX consumer.lo In file included from /home/simark/src/lttng-tools/src/common/error.h:19, from /home/simark/src/lttng-tools/src/common/common.h:12, from /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:19: /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp: In function ‘int consumer_send_relayd_socket(consumer_socket*, lttcomm_relayd_sock*, consumer_output*, lttng_stream_type, uint64_t, const char*, const char*, const char*, int, const uint64_t*, time_t, bool)’: /home/simark/src/lttng-tools/src/common/macros.h:116:58: error: expected primary-expression before ‘]’ token 116 | #define ALIGNED_CONST_PTR(value) (((const typeof(value) []) { value })) | ^ /home/simark/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:1192:48: note: in expansion of macro ‘ALIGNED_CONST_PTR’ 1192 | ret = consumer_send_fds(consumer_sock, ALIGNED_CONST_PTR(rsock->sock.fd), 1); | ^~~~~~~~~~~~~~~~~ Replace uses with copying the data in a local variable (which is properly aligned), and pass the address to that variable to the function. - In consumer.h, an array field in a structure is defined using the max macro. It can't be replaced with std::max, since std::max isn't constexpr in C++11. Define a max_constexpr function locally and use it. - g++ 7 doesn't support non-trivial designated initializers, leading to errors like: CXX globals.lo /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/globals.cpp:44:1: sorry, unimplemented: non-trivial designated initializers not supported }; ^ Change consumer_data to have a constructor instead. Change initializations of some structures, such as lttcomm_lttng_msg, to initialize the fields separate from the variable declaration. This requires making these variable non-const which is not ideal. But once everything is C++, these types could get a fancy constructor, and then they can be made const again. - When compiling without UST support the stub versions of functions ust_app_rotate_session & co, in ust-app.h, are used. Some of them have the return type "enum lttng_error_code", but return 0, an invalid value, causing: CXX main.o In file included from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/lttng-sessiond.h:22:0, from /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/main.cpp:45: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h: In function ‘lttng_error_code ust_app_snapshot_record(ltt_ust_session*, const consumer_output*, int, uint64_t)’: /home/smarchi/src/lttng-tools/src/bin/lttng-sessiond/ust-app.h:575:9: error: invalid conversion from ‘int’ to ‘lttng_error_code’ [-fpermissive] return 0; ^ Change these functions to return LTTNG_ERR_UNK. These functions are not supposed to be called if UST support is not included. But even if they were: all their callers check that the return value is not LTTNG_OK. The value 0 would be considered an error, so will be LTTNG_ERR_UNK. Change-Id: I2cdd34459a54b1943087b43843ef20b35b7bf7d8 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Move firing policy from lttng_trigger to lttng_action After some reflection on the future of the importance of the trigger feature and the centralization we wish to carry around it, it is required that the notion of firing policy be moved from the trigger object to each action object of a trigger. This is necessary since we plan on introducing tracer side actions, such as increment value of map. Controlling the firing policy on the tracer side is not an easy thing to do since for UST tracing a lot a synchronizations must take place and also we must define the behaviour when multiple apps are present. Hence, we need a way to ensure that we are not painting ourself in a corner. The middle ground that was chosen was to move the notion of firing policy to the action object level. This allows us to scope the concept to the action and decide for each type if firing policy can be supported and, as needed, define the behaviour per action type. Essentially this patch perform the complete transition. It removes the notion of firing policy at the trigger level and exposes the firing policy of each action type if applicable. CLI ====== For the `add-trigger` command the change essentially boils down to moving the `--fire-every` and `--fire-once-after` from a top-level parsing to the parsing of each actions. Yes, for now all actions supports the `--fire-*` options but it will not be the case in the future. A side effect of this is that a user could decide to have different firing policy for each actions, but this also mean that if a user want to apply the same firing policy across actions, the user needs to specify it for each actions. This could be solved in the future as the trigger feature matures and that common ground are found in the behaviour or implementation of the actions (tracer side action, async action, sync actions etc.) such that "syntactic sugar" options emerge. As for the `list-trigger`, we move the firing policy printing to each actions. Tests have been updated to reflect the changes. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ib29d4319922096c0c4b3f00782f3bbefb17e2f40
lttng-ctl: add capture descriptor feature to event rule condition API This patch makes it possible to add capture descriptors to an event rule condition. A capture descriptor describes a value to be captured by an LTTng tracer when an event occurs and to be attached to the corresponding condition's evaluation. The lttng_condition_event_rule_append_capture_descriptor() function appends a capture descriptor to an event rule condition. The capture descriptor is an event expression object of which the ownership is moved to the condition object. The verb "append" here indicates that the order of the condition's capture descriptors is significant: indeed, when liblttng-ctl gets an upgrade to the "event rule hit" condition evaluation API in the future to make its user read the captured values, such values will be ordered the same way, therefore sharing the same numeric indexes. Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I68f163e6eb011e690f648d9ff8ea3eb89af004ff Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479
lttng: Add remove-trigger command Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I323ddc181c9214dcf4ae66e23a382451f6582fff Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479
lttng: Add list-triggers command Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I901264798baa81626d8e212a40774570100dc4f9 Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479
trigger: implement listing of registered trigger Each client have visibility over triggers matching its user id (uid). The root user have visibility over all registered triggers. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I3e5ae75939214ed85c376bea12f1e4b307d78976
trigger: introduce firing policies A firing policy controls the rate of firing of a trigger. Two firing policy mode are implemented: LTTNG_TRIGGER_FIRING_POLICY_FIRE_EVERY_N The triggers's actions are executed every N times the condition occurs. LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N The triggers's actions are executed once the condition was met N times. Firing policies will be moved to the specific `action` objects in a follow-up commit as not all actions can implement the firing policies. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ifaeeaaec7b6f2bed57d0d5f4ed8546762ec02e8d
trigger: lttng_triggers: implement a container for multiple triggers This container is exposed for the listing of triggers. We also plan on using it internally in the sessiond for inter-thread communication. The current implementation is backed by a lttng_dynamic_pointer_array. Caller of lttng_triggers_add is responsible for managing ownership via ref-counting of the lttng_trigger object. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ib541027a6d7d856daa746de5aa49f0002bbe036f
trigger: implement trigger naming A trigger can now have an optional name on the client side. If no name is provided the sessiond will generate a name and return a trigger object to populate the client side object. For now, the name generation code generate the following pattern: TN Where `N` is incremented each time a name has to be generated. If a collision occurs, we increment `N` as needed. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I5f303610713c049177e53937bfc9824cd61501e4
trigger: expose trigger owner uid To facilitate behavior management for the root user and to allow duplicate trigger names across users, enforce the usage of the trigger owner user id. The root user will be able to register and unregister triggers on behalf of other users. The root user will also have visibility on triggers of other users. Only the root user can use the `lttng_trigger_set_owner_uid` function successfully. As indicated in the comments, this function performs a client-side validation steps to catch mis-uses, but this is properly enforced on the sessiond's end in the register/unregister trigger commands. With the future addition of a trigger name (id), the owner id and the name will act as a key tuple allowing identicaly named triggers across users. We plan on exposing the `--user` switch in the upcoming command line (add-trigger, remove-trigger). Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ifca3c41b7ffd97b67e16fb80c18472b667cb2f56
Move to kernel style SPDX license identifiers The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. See https://spdx.org/ids-how for details. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: I62e7038e191a061286abcef5550b58f5ee67149d Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>