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 fix: build without lttng-ust Add conditionnal inclusion of ust-sigbus to the tests modified by: commit e207fe73b58787c6077ec5d49254e12ff1a82b51 Author: orbea <orbea@riseup.net> Date: Sat May 29 11:07:41 2021 -0700 build: Add missing DEFINE_LTTNG_UST_SIGBUS_STATE(); Fixes: liblttng-ust-ctl.so: undefined reference to `lttng_ust_sigbus_state' Change-Id: If4af7ada6d94ee67603156d151575dcc57baad05 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
build: Add missing DEFINE_LTTNG_UST_SIGBUS_STATE(); Fixes: liblttng-ust-ctl.so: undefined reference to `lttng_ust_sigbus_state' Signed-off-by: orbea <orbea@riseup.net> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I428bdc262168d1701525e024e7580861d2498e2b
build: Add the liblttng-sessiond-comm.la convenience library This allows correctly linking test_kernel_data with slibtool. Signed-off-by: orbea <orbea@riseup.net> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ib076854dc2a4f0234ad3fb04ea1c3c7c4d4a2b7e
Sync lttng-modules ABI in internal kernel-ioctl.h This commit bumps the modules minor version number in `kernel-ioctl.h` and applies the following renames: define renames: `LTTNG_KERNEL_x` -> `LTTNG_KERNEL_ABI_x` `RING_BUFFER_x` -> `LTTNG_KERNEL_ABI_RING_BUFFER_x` struct renames: `struct lttng_kernel_x` -> `struct lttng_kernel_abi_x` No behavior change intended. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I0bb0ac6bca56b6740ea2d543a6d1bd618d39b36c
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: return the proper TAP exit code The C TAP library provides the 'exit_status()' function that will return the proper exit code according to the number of tests that succeeded or failed. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I0de2349609eb34b1c5e58f09012c1db0126923c0
sessiond: enforce mmap output type for kernel metadata channel A follow-up fix causes the consumer daemon to accumulate metadata packets into a complete "unit" that can be parsed before sending it to the relay daemon. The consumer daemon will also need to extract the contents of the metadata cache when computing a rotation position (follow-up fix too). Hence, it is not possible to rely on the splice back-end as the consumer daemon may need to accumulate more content than can be backed by the ring buffer's underlying pages. In both cases, the splice output mode could still be used when combined with a memfd, but I see no tangible benefit. Moreover, it would require a 3.17 kernel. Curiously the kernel metadata channel configuration appears to be hard-coded twice; once in the ltt_kernel_session's ltt_kernel_metadata, and once again in kernel_consumer_add_metadata(). kernel_consumer_add_metadata is modified to use the kernel session's metadata configuration. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ia4cad82f595d3eee50d081851c234d4c2ef7ee5f
Fix: tests: `-Wstringop-overflow` warning I get the following warning when compiling with `-Wall -Werror` with gcc 9.3.0: In file included from ../../src/common/macros.h:15, from ../../src/common/lttng-kernel.h:14, from ../../src/bin/lttng-sessiond/trace-kernel.h:14, from test_kernel_data.c:16: In function ‘lttng_strnlen’, inlined from ‘lttng_strncpy’ at ../../src/common/macros.h:120:6, inlined from ‘test_create_kernel_event’ at test_kernel_data.c:136:2: ../../src/common/compat/string.h:28:8: error: ‘memchr’ reading 256 bytes from a region of size 11 [-Werror=stringop-overflow=] 28 | end = memchr(str, 0, max); | ^~~~~~~~~~~~~~~~~~~ Fix this warning by using the RANDOM_STRING_LEN value as the max number of bytes to copy. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Change-Id: I61752ee17163c4d642aad21b296c0fc4fad5b7a6 (cherry picked from commit 1dd622b10db0821d77490c937caee80c65332f14) 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>
trace_kernel_create_event() now returns an error code The created kernel event is returned via an out parameter. The error code specifies the reason of a potential failure of the creation of the event. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: illegal memory access in test_create_kernel_event Found by Coverity: CID 1243030 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)1. buffer_size_warning: Calling strncpy with a maximum size argument of 256 bytes on destination array ev.name of size 256 bytes might leave the destination string unterminated. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>