common: compile libconfig as C++ As seen previously, make some global variables that need to be exported non-const. config_element_tracker_pid_target_legacy seems unused and clang gives an unused warning. It was not exposed publicly, so I think it's safe to remove it. Change-Id: I6f9e7d77a7a04b02ae6585383c11389869b4a79a Signed-off-by: Simon Marchi <simon.marchi@efficios.com> 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>
liblttng-ctl: use export list to define exported symbols Symbols are currently exported by default by liblttng-ctl.so (usable by other shared libraries / programs using liblttng-ctl.so), so we must use LTTNG_HIDDEN on all symbols that are meant to be internal to liblttng-ctl.so. Of course, this is easy to forget, so over the years many symbols that were not meant to be exported were exported, and must now stay exported to avoid breaking the ABI. As explained here [1], a better method is to make symbols hidden by default, and mark those we want to be exported as such. I have tried to use this, but when subsequently converting the code to C++, I have noticed that some symbols related to the STL were exported anyway, which is bad. The other alternative, implemented in this patch, is to use an explicit symbol export list [2], using libtool's -export-symbols (which uses the linker's -version-script option). Only the symbols listed here are exported. So, in practice, this patch: - Adds an liblttng-ctl.sym file with the list of exported symbols and adjusts the Makefile to use the -export-symbol option - Removes LTTNG_HIDDEN and all its uses abidiff shows no changes for liblttng-ctl.so between before and after this patch. [1] https://gcc.gnu.org/wiki/Visibility [2] https://www.gnu.org/software/libtool/manual/libtool.html#Link-mode Change-Id: I5d8c558303894b0ad8113c6e52f79a053bb580e1 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
config: accept "0" and "1" as XML boolean values These are valid values when validating a "boolean" using a schema (XSD). Somebody could therefore write a file with <started>0</started> instead of <started>false</started> The file would validate against session.xsd, but we would fail after that: Warning: Invalid boolean value encoutered (0). Error: Invalid session configuration Reference: https://www.w3.org/TR/xmlschema11-2/#boolean Change-Id: Icea85b13233ec01aa09ef3b578906f4c0e482088 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Clean-up: config: fix -Wshadow error in config_load_session Fix: CC libconfig_la-session-config.lo /home/simark/src/lttng-tools/src/common/config/session-config.c: In function ‘config_load_session’: /home/simark/src/lttng-tools/src/common/config/session-config.c:4020:9: error: declaration of ‘path’ shadows a parameter [-Werror=shadow] 4020 | char path[PATH_MAX]; | ^~~~ /home/simark/src/lttng-tools/src/common/config/session-config.c:3999:37: note: shadowed declaration is here 3999 | int config_load_session(const char *path, const char *session_name, | ~~~~~~~~~~~~^~~~ Change-Id: Id7d5f6fcf0e88f43dee420dfb174d9bf01aa8fbd Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: load: incomplete error handling for load_session_from_file This fix is adapted from a fix against the stable-2.11 branch. The commit message of the stable-2.11 branch follows. An equivalent fix was already in place in `load_session_from_path()`, but the same problem as the stable-2.11 branch is present in `load_session_from_file()`. Original message: Observed issue ============== lttng-ivc test fails to fail. test_save_load_blocking_timeout[lttng-tools-2.12-lttng-tools-2.11-False] Here we load a xml created by lttng-tools-2.12 and try to load it using lttng-tools 2.11. We expect this to fail on the load. The command report an error on the stderr but the command return code value is zero. From lttng-ivc test runtime.log: Command #0 Return value: 0 Command: lttng load --input-path=/home/joraj/lttng/lttng-ivc/.tox/py3/tmp/test_save_load_blocking_timeou0/save_load saved_trace STDOUT: Session saved_trace has been loaded successfully STDERR: XML Error: Element 'process_attr_trackers': This element is not expected. Error: Session configuration file validation failed Cause ===== The error coming from load_session_from_file is not handled correctly. Solution ======== Rework error handling in load_session_from_path and load_session_from_file. LTTNG_ERR_LOAD_SESSION_NOENT is NOT an error when session_name is specified in load_session_from_path. In this scenario, we are actively looking for the configuration of the session. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Change-Id: Ic68c253aa194bf8ab72c3c271f10d443118bdeee
Fix: lttng-load: support legacy PID tracker specification The 2.12 release changes the way tracked process attributes are expressed in the MI and save/restore formats. While the MI schema was bumped to 4.0, the save/restore schema only undergoes a minor bump to accomodate existing users. The original commit introducing this change justified the breaking change as saved PIDs being fairly unlikely. However, even the 'INCLUDE_ALL' policy will specify a 'trackers' node, which no longer existed and made all existing configurations incompatible. A legacy load path is introduced to support the former PID tracker serialization format and preserve the compatibility with existing configurations. Configurations generated by the 2.11 releases are included to test this new legacy path. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Ied6532c42cb2d1a5c9e39785cc4e47aaf89b8288
Refactor: lttng-ctl: follow terminology of the tracker documentation This commit harmonizes the process attribute tracker API and serialization formats (save/restore and MI) with the documentation with regards to the terminology used. The message of the parent commit adjusting the manual pages of the lttng-track and lttng-untrack commands details those terminology changes and their rationale. Some problems with the API introduced during the 2.12 development cycle are also adressed: Type safety: - The process attribute tracker is made type safe with regards to the platform's native types to express process attributes. Where the original API casted all integral values to integers, this change introduces accessors for all process attribute types (pid_t, uid_t, gid_t). This makes it easier to use the API safely and without producing warnings in user's code. Another benefit of adopting this explicit type-safe approach is that is will make it easier to add new attributes which are not expressible (or non-ambiguously expressible) using `int` and `string` types (e.g. tracking a virtual PID within a given namespace). Ambiguity of INCLUDE_ALL, EXCLUDE_ALL, and INCLUDE_SET states: - The original tracker API has a notion of 'enabled' pid_tracker which is confusing to users: - enable = 0: everything is tracked, - enable = 1: a list of tracked pids is provided, which may be empty. - pid '-1' is *special* and tracks or untracks everything. This was replaced with a 'special' opaque value meaning 'ALL' which, while being clearer, was still confusing and hard to document. The revised API explicitly expresses the notion of a tracking policy (`enum lttng_tracking_policy`). When that policy is set to `LTTNG_TRACKING_POLICY_INCLUDE_SET`, the inclusion set can be queried and/or mutated. On top of being clearer, this aligns more closely with the internal lttng-sessiond daemon API which gets rid of a lot of code to handle those special cases. The resulting code is more verbose, but a lot easier to understand. Moreover, the types introduced (e.g. lttng_process_attr_values) are meant to be re-used if a new `LTTNG_TRACKING_POLICY_EXCLUDE_SET` tracking policy is added in the future. Documentation: - The revised API includes a complete documentation. It documents the API usage, but also adds implementation notes such explicitly mentionning when/where user names and group names are resolved. Client: - While making the changes to use this new API, some error messages are clarified (or added). The resulting output when listing the trackers was also changed to be more compact. The CLI output now also makes use of the terminology used in the documentation for all commands interacting with process attribute trackers. It is now also possible to specify multiple process attribute trackers along with the --all option for the lttng-track and lttng-untrack command. For instance: `lttng tracker --userspace --vpid --vuid --all` is now allowed. The same process attribute tracker can also be specified more than once in a command, as follows: `lttng track --userspace --vpid 43,11 --vpid 55,77` Since the serialization had been changed during the 2.12 cycle, I changed them further to use the API's terminology in the element names. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: I5f0ea2849eb024ea6944b2ee7dbadfd893cc0be4
Fix: liblttng-ctl: hide new tracker config symbols Session configuration constants are supposed to remain internal. Some symbols were errneously exported in previous releases, but we mark new ones as "hidden". Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> Change-Id: Iae51c7e479ba9f9e377bb426f35f9e3a73c2d449
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>
Refactoring: use an opaque lttng_tracker_id type Move the tracker and tracker id related API to tracker.h and tracker-internal.h. The use of an opaque object mimics the new API for rotation and trigger etc. Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> Change-Id: I00b876c618d7dcb0dd940189e5250c3f3d64c7e0 Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Add kernel uid/gid contexts Add the following kernel tracer context fields: - uid Real user ID - euid Effective user ID - uid Real user ID - suid Saved set-user ID - gid Real group ID - egid Effective group ID - sgid Effective saved set-user group ID - vuid Virtual real user ID: real user ID as seen from the point of view of the current user namespace - veuid Virtual effective user ID: effective user ID as seen from the point of view of the current user namespace - vsuid Virtual saved set-user ID: saved set-user ID as seen from the point of view of the current user namespace - vgid Virtual real group ID: real group ID as seen from the point of view of the current user namespace - vegid Virtual effective group ID: effective group ID as seen from the point of view of the current user namespace - vsgid Virtual saved set-group ID: saved set-group ID as seen from the point of view of the current user namespace Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Add kernel namespace contexts Add the following kernel namespace contexts: - cgroup_ns Cgroup root directory namespace: inode number of the current cgroup namespace in the proc filesystem. - ipc_ns System V IPC, POSIX message queues namespace: inode number of the current IPC namespace in the proc filesystem. - mnt_ns Mount points namespace: inode number of the current mount namespace in the proc filesystem. - net_ns Network devices, stacks, ports namespace: inode number of the current network namespace in the proc filesystem. - pid_ns Process IDs namespace: inode number of the current pid namespace in the proc filesystem. - user_ns User and group IDs namespace: inode number of the current user namespace in the proc filesystem. - uts_ns Hostname and NIS domain name namespace: inode number of the current uts namespace in the proc filesystem. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: liblttng-ctl: config and mi strings inadvertantly exported abidiff reports that a number of configuration and MI string symbols are exported by liblttng-ctl: 'const char* const config_event_type_userspace_probe' {config_event_type_userspace_probe} 'const char* const mi_lttng_element_command_disable_rotation' {mi_lttng_element_command_disable_rotation} 'const char* const mi_lttng_element_command_enable_rotation' {mi_lttng_element_command_enable_rotation} 'const char* const mi_lttng_element_command_rotate' {mi_lttng_element_command_rotate} Those strings are marked as LTTNG_HIDDEN. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>