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>
Force usage of assert() condition when NDEBUG is defined Reuse the BT2 approach to force the usage of the assertion condition even when assert() are removed by the NDEBUG define. See `BT_USE_EXPR()` macro and documentation in Babeltrace commit[0]: commit 1778c2a4134647150b199b2b57130817144446b0 Author: Philippe Proulx <eeppeliteloop@gmail.com> Date: Tue Apr 21 11:15:42 2020 -0400 lib: assign a unique ID to each pre/postcond. and report it on failure 0: https://github.com/efficios/babeltrace/commit/1778c2a4134647150b199b2b57130817144446b0 Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I3844b6ae7e95952d90033898397ac936540b785c
build: Use liblttng-sessiond-common.la instead of SESSIOND_OBJS This allows correctly linking test_session and test_ust_data with slibtool. Signed-off-by: orbea <orbea@riseup.net> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I5c18187e4185218db337ac3548f0d44fb60501f3
Clean-up: sessiond: prepend `the_` to global variable names This avoids name clashes between global variables and local variables or function parameters (notification_thread_handle, for example). This is a step towards enabling -Wshadow. This also helps readability, in my opinion, as it helps quickly spot that some code is using a global variable. Change-Id: Ib0e35ad7efcc54fa88e1900cab3388b98a06b8d9 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
port: FreeBSD has no ENODATA, alias it to ENOATTR According to 'the internet' ENOATTR is used in a similar fashion to ENODATA on the BSDs and we used it internally only anyway. Change-Id: Ia4e77fd6d28c9dfb43f99ddba6c32369384827f0 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: 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: I89cd4b4b7440f71f52426a5508252932bb46e796 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: build failure with -fno-common GCC 10 will default to building with -fno-common, this inhibits the linker from merging multiple tentative definitions of a symbol in an archive. I'm not sure I understand what happen with the symbols in mi-lttng.h but a similar issue was adressed in: commit 4965f956f3ef47388fb4a1b2f8f504abfe31afe7 Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> Date: Fri May 22 12:53:30 2015 -0400 Fix: Mark MI and Config string declarations as extern This fixes a build issue with GCC 5.1 which would complain about these symbols being defined multiple times. Make sure these symbols are extern and defined only in one compile unit. For more information, see: https://gcc.gnu.org/gcc-10/porting_to.html Change-Id: I139c9695371836cb1011f9ce192080b602ed2fbc Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests: make functions static in test_session.c Fixes: CC test_session.o /home/smarchi/src/lttng-tools/tests/unit/test_session.c:219:6: error: no previous declaration for ‘test_session_list’ [-Werror=missing-declarations] void test_session_list(void) ^~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:225:6: error: no previous declaration for ‘test_create_one_session’ [-Werror=missing-declarations] void test_create_one_session(void) ^~~~~~~~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:232:6: error: no previous declaration for ‘test_validate_session’ [-Werror=missing-declarations] void test_validate_session(void) ^~~~~~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:258:6: error: no previous declaration for ‘test_destroy_session’ [-Werror=missing-declarations] void test_destroy_session(void) ^~~~~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:278:6: error: no previous declaration for ‘test_duplicate_session’ [-Werror=missing-declarations] void test_duplicate_session(void) ^~~~~~~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:284:6: error: no previous declaration for ‘test_session_name_generation’ [-Werror=missing-declarations] void test_session_name_generation(void) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/smarchi/src/lttng-tools/tests/unit/test_session.c:309:6: error: no previous declaration for ‘test_large_session_number’ [-Werror=missing-declarations] void test_large_session_number(void) ^~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ib1f6a004e6feb4693c4331a8b0ce67ee1697703c Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: move set base_path of session to URI configuration The load code still uses the "old" API to create and configure network session output (lttng_create_session followed by lttng_set_consumer_url). The session base_path is only set in the cmd_create_session_from_descriptor function. This results in invalid network output paths when using a loaded session configuration (xml). While we might want to move the load code to the new API, there is a case to be made in not breaking the previous API behaviour. To restore the expected behaviour of lttng_set_consumer_url, move the assignation of the session base_path to the cmd_set_consumer_uri function (LTTNG_SET_CONSUMER_URI). Both the previous and session descriptor based creation API uses this code path when needed (network output). Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: Tests: test_session.c: Structurally dead code Coverity report: CID 1400680 (#1 of 1): Structurally dead code (UNREACHABLE) unreachable: This code cannot be reached: ret = 0;. Reported-by: Coverity (1400680) Structurally dead code Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: honor base path for network URIs Starting from 2.11, the following use-case stopped working as expected: lttng create --set-url=net://localhost/my/path/custom lttng enable-event -u -a lttng start [ run app ] The output trace is expected in the following directory on the relayd (no timestamp suffix): $LTTNG_HOME/lttng-traces/[hostname]/my/path/custom Add the base_path information to the session object in the session daemon, extracted from the network URI, and pass that information to the relay daemon through the create session (2.11) command. It also fixes the use-case: lttng create --snapshot --set-url=net://localhost/my/path/custom lttng enable-event -u -a lttng start [ run app ] lttng snapshot record which is expected to record the snapshot under: $LTTNG_HOME/lttng-traces/[hostname]/my/path/custom/snapshot-[N]-[timestamp] Similar situation for: lttng create --snapshot lttng enable-event -u -a lttng start [ run app ] lttng snapshot record net://localhost/my/path/custom which is expected to record the snapshot under: $LTTNG_HOME/lttng-traces/[hostname]/my/path/custom/snapshot-[N]-[timestamp] Note that specifying the base_path on the snapshot record command overrides the base path specified at create. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix tests: NULL pointer dereference in ltt_session unit tests The check for a NULL kernel session must be skipped when the session_find_by_name() fails to find a session else a NULL pointer dereference will occur. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Generate session name and default output on sessiond's end The lttng client currently generates the default session name and output parameters. This has, over time, resulted in a number of problems. Notably, it is possible for scripts to create session too quickly using automatically-generated session names that would clash since the session's creation timestamp is the only variable part of a session "automatic" name. Hence, sessions created in the same second would clash and result in spurious session creation failures. More importantly, generating session names and outputs on the client end makes it impossible to reliably differentiate output locations that were automatically generated vs. those that were explicitly provided. This causes destinations to be "opaque" to the LTTng daemons as the subdir, session name, and session's creation timestamp are all "cooked" as part of the output destination path/subdir. Keeping these path components separate will make it easier to implement output path configurations that allow the grouping of session outputs by name, by host, etc. Since a session's creation time is used as part of its shm-path, an accessor to the session's creation time is added to the public API: lttng_session_get_creation_time(). This creation time attribute can be accessed when an lttng_session structure is created using the session listing API. Note that existing session creation functions are preserved to maintain the binary compatibility with existing liblttng-ctl users. The session creation functions are reimplemented on top of this newly-introduced API. The only function for which compatibility is dropped is the hidden _lttng_create_session_ext(). Overhaul of path separation --- Not generating paths on the client-end has uncovered a number of problems in the path handling of the session daemon, especially when a network output was used. A lot of code presumed that a network session would be created with a URL containing a sub-directory of the form "session_name-timestamp". While this is true for remote sessions created by the lttng client, a sub-directory is not required when liblttng-ctl is used directly. Hence, this commit ensures that session directories are split as base path, chunk directory, domain directory, application directory. A number of changes in this fix ensure that a session's base path contains everything up to the "session" path element _or_ up to the user-specified output directory. For example, creating a local session using default output settings, the session base output is: /home/user/lttng-traces/session-timestamp Creating a remote session using default output settings, the session base output path is: /hostname/session-timestamp/ Using custom output directories, whether locally or remotely, causes the session base path to be set to that custom output directory. For example, using a local output path of /tmp/my_path will result in a session base path of the form: /tmp/my_path Whereas creating a session with a network output of net://localhost/my_path will result in a session base path of the form: /hostname/my_path Another problematic element is the subdir of the kernel_session and ust_session consumer output which in different scenarios contained chunk names and arbitrary parts of the path hierarchy. The consumer output subdir has been renamed to 'domain_subdir' and now only ever contains: "kernel/", "ust/", or "". Finally, the chunk_path session attribute only contains the name of the current chunk directory being produced. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Reference count ltt_session objects The lifetime of ltt_session objects is mishandled in a number of situations. For instance, if a rotation is launched on a session and the session is destroyed during the rotation, it is not possible for the session daemon to identify the completion of the rotation. This then prevents the session daemon from renaming the last chunk of a now-destroyed session and from notifying clients that a new trace archive chunk is available. This change only introduces reference counting of the ltt_session objects; it does not change any behavior with regards to the lifetime of the sessions themselved. Follow-up commits introduce those changes. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>