Sternum Linux SDK
|
This repository contains the files of the Sternum Linux SDK, a versatile and flexible tool to add observability and traceability to Linux devices using C/C++.
The SDK package is organized into three main directories:
Linux SDK requires OpenSSL for encrypted transmission. OpenSSL is provided as source in the SDK package.
Before building or compiling the OpenSSL module, ensure that you have the necessary development packages installed on your Linux system. The required packages may vary depending on your Linux distribution. Typically, you'll need development tools and libraries. Here's how to install the prerequisites on Debian-based systems (such as Ubuntu):
Update the package index:
Install the necessary development packages for OpenSSL:
This command installs essential development tools including compilers and libraries required for building OpenSSL.
Change into the OpenSSL submodule directory by running the following command:
Configure OpenSSL build:
This command configures OpenSSL build environment based on your system's architecture and installed libraries.
When cross-compiling, ensure to modify the build parameters accordingly. An example is provided in the Cross Compilation section.
Build OpenSSL:
This command compiles OpenSSL from the source code.
(Optional) Run tests:
This command runs the OpenSSL test suite to ensure that the build is successful and the library functions correctly.
The compiled libraries will be located in the modules/openssl
directory. During the SDK build process, these libraries will be placed into the sternum_linux_sdk/linux/output
directory.
The following example demonstrates how to cross-compile OpenSSL for AARCH64.
Assuming your cross-compilation toolchain is accessible as aarch64-linux-gnu-, the OpenSSL configuration can be done as follows:
Adapt the parameters to your toolchain and architecture as needed.
Once you have built OpenSSL successfully, you can build Sternum SDK library. Navigate to Linux SDK directory:
To configure the SDK build for your host environment with default features, use the following command:
This command generates the necessary build files based on your environment, including your system architecture and the default SDK feature settings. It prepares the project for compilation, tailored to your specific development environment.
The sternum_linux_sdk/linux/output
directory will contain generated SDK library libsternum_linux_sdk.so
, OpenSSL libraries libssl.so
, libcrypto.so
, and include
directory encompassing all necessary SDK headers.
After building the SDK, move created libraries (libsternum_linux_sdk.so
, libssl.so
, libcrypto.so
) to target device and ensure that they are accessible for dynamic linker. You have three options to make these libraries accessible:
In your target project's CMakeLists.txt, set the RPATH to include the directory where the SDK's shared libraries are located. This ensures that the dynamic linker can find the libraries at runtime without requiring additional environment variables.
For example, if the shared libraries are in the lib/ directory relative to the executable:
Set the LD_LIBRARY_PATH environment variable on your target device to include the paths to these libraries. This allows the dynamic linker to find the libraries at runtime. For example:
Alternatively, you can move the libraries to a standard system directory where the dynamic linker automatically searches for shared libraries. Common default paths include /usr/lib
or /usr/local/lib
.
By following these steps, you ensure that your target device can locate and use the SDK and its dependencies correctly.
When cross-compiling the SDK, adjust the build parameters to match the target architecture. Detailed instructions are provided in this section.
Create a toolchain file that specifies the necessary variables for cross-compilation. Below is an example for AArch64 (ARM 64-bit architecture) that utilizes a previously defined CROSS_COMPILE environment variable.
Example: aarch64-toolchain.cmake
To build the library using the toolchain file, run the following command:
You can customize various features of the SDK by adding CMake options when configuring the build. Here are the available options:
-DAPPEND_PROCESS_NAME=ON/OFF
: Enable or disable adding the executing process name to each trace (default: ON).-DENABLE_CRASH_DETECTION=ON/OFF
: Enable or disable crash detection feature (default: ON).-DLOG_LEVEL=0..3
: Specify the log level (Default: 2).The log level determines the verbosity of logging messages generated by the library. Accepted values are:
The Crash Detection feature automatically captures program state information when the program crashes due to certain signals, including SIGSEGV
, SIGBUS
, SIGILL
, SIGABRT
, SIGFPE
, SIGSYS
, and SIGTERM
. This information is stored in a crash dump file in the cache. On the next boot of the program, the stored crash dump is automatically transmitted to Sternum Platform within TRACE_CRASH
. This allows developers to analyze the crash and diagnose the root cause more effectively.
If APPEND_PROCESS_NAME
is enabled, executing process name will be included automatically to each transmitted trace.
Your project will need the SDK headers, SDK library libsternum_linux_sdk.so
, and its dependencies (libssl.so
, libcrypto.so
) in order to instrument and build your applications with the SDK.
Copy and paste the contents of sternum_linux_sdk/linux/output
to your project or general location on your device. You can create new folder in your project structure for this purpose, for instance sternum_sdk
.
Adjust the configuration according to your build system to include the SDK directory and link with SDK library. If you are using CMake, an example of configuration is documented next.
To build your application with the SDK, update your CMake configuration as follows:
Add sternum_sdk/include
directory to the list of include directories for your project:
Link your application with Sternum SDK library:
If you're using a different build system, adjust the configuration accordingly to include the SDK directory and link with SDK library.
You must initialize Sternum SDK before using it.
Transmission initialization:
File cache initialization:
Traces are cached in a file cache. If transmission fails, they will remain stored in the file cache until successfully sent. Once transmitted, they are then removed from the cache. The file cache maintains persistence across multiple application executions and must be unique for each application instance.
For more information about the initialization structure, refer to the documentation of struct sternum_settings_t .
Below is an example of how to initialize the SDK:
The SDK library is thread-safe.
Calling the sternum_sdk_flush() method initiates the secure transmission of traces to the cloud via TLS/OpenSSL. If transmission is impossible, traces will be retained in the cache until a successful connection can be established, ensuring no data loss occurs.