feat(os): add Linux syslog OS wrapper for score::os::Syslog - #502
btirunagaru wants to merge 1 commit into
Conversation
| public: | ||
| static score::cpp::pmr::unique_ptr<Syslog> Default(score::cpp::pmr::memory_resource* memory_resource) noexcept; | ||
|
|
||
| /* KW_SUPPRESS_START:MISRA.VAR.HIDDEN:Wrapper function is identifiable through namespace usage */ |
There was a problem hiding this comment.
Please do not add KW_ markers. These are legacy and should actually be removed from the entire codebase.
There was a problem hiding this comment.
Done. Fixed in the new review.
| Syslog() = default; | ||
|
|
||
| virtual ~Syslog() = default; | ||
| // Below special member functions declared to avoid autosar_cpp14_a12_0_1_violation |
There was a problem hiding this comment.
Please do not add this comment. This repo aims to adhere to MISRA guidelines and not AUTOSAR
There was a problem hiding this comment.
Done. Fixed in the new review.
| @@ -0,0 +1,52 @@ | |||
| /******************************************************************************** | |||
| * Copyright (c) 2025 Contributors to the Eclipse Foundation | |||
There was a problem hiding this comment.
Done. Fixed in the new review.
|
|
||
| /// @brief Object-seam wrapper around the POSIX/glibc syslog(3) family. | ||
| /// | ||
| /// Mirrors the QNX @ref score::os::qnx::Slog2 wrapper so that the platform-native |
There was a problem hiding this comment.
This comment looks redundant. The slog2 API is completely different.
There was a problem hiding this comment.
Done. Fixed in the new review.
| ], | ||
| features = COMPILER_WARNING_FEATURES, | ||
| tags = ["FFI"], | ||
| target_compatible_with = ["@platforms//os:linux"], |
There was a problem hiding this comment.
But the idea to use slog on qnx and only syslog on linux providing the equivalent functionality on target.
There was a problem hiding this comment.
Why not to give freedom to use it also on QNX? I would add qnx target as far as code is the same
There was a problem hiding this comment.
as i mentioned - the kSystem log mode on QNX is already filled by slog and its widely used on QNX and it make sense to use that.
so i would assume the choice of the users to use slog vs syslog on QNX is more of a different ask. Till the community show interest to have this dual choice. its best we treat this and compile for Linux only and enable for QNX later (until we find a genuine user for this back end)
If there is a interest and the enablement for QNX can come later as a different requirement if that's the need.
|
Documentation preview for this pull request is available at: |
a0a3faa to
408be67
Compare
Yes, i raised another commit with fixes for those CI workflows - please review. |
| ::openlog(ident, option, facility); | ||
| } | ||
|
|
||
| // coverity[autosar_cpp14_a8_4_1_violation]: see above |
There was a problem hiding this comment.
I do not see any argumentation for the suppression.
There was a problem hiding this comment.
Please do not add KW_ markers. These are legacy and should actually be removed from the entire codebase.
This was the comment provided to me earlier so had to remove those annotation or argumentation - see my first review those should be there - let me know if you want me to bring it in.
| const std::int32_t option, | ||
| const std::int32_t facility) const noexcept override; | ||
|
|
||
| // coverity[autosar_cpp14_a8_4_1_violation]: see above |
408be67 to
37847ba
Compare
37847ba to
500cc96
Compare
Add a Linux implementation of the Syslog object seam that forwards openlog(), syslog(), and closelog() calls to the POSIX API. - Add the Syslog interface, Linux implementation, and default factory. - Add a mock implementation and Linux unit tests. - Include the production implementation in the coverage scope. - Preserve the POSIX-compatible C-style variadic interface. - Retain only the required clang-tidy suppressions for the variadic adapters. - Remove the stale Coverity 'see above' comments from the Linux syslog declaration and definition. Verification: - Linux syslog unit test passed. - C++ formatting check passed. - Targeted clang-tidy build passed. - Coverage scope check passed. - git diff --check passed.
500cc96 to
253fd2e
Compare
| #include <cstdio> | ||
| #include <string> | ||
|
|
||
| namespace score |
| void MockSyslog::syslog(std::int32_t priority, const char* format, ...) const noexcept | ||
| { | ||
| // Create a va_list to hold the variable arguments | ||
| va_list args; |
| { | ||
| // Create a va_list to hold the variable arguments | ||
| va_list args; | ||
| va_start(args, format); |
| va_start(args, format); | ||
|
|
||
| // Determine required buffer size | ||
| const auto message_length = std::vsnprintf(nullptr, 0, format, args); |
| const auto message_length = std::vsnprintf(nullptr, 0, format, args); | ||
|
|
||
| // Reset the va_list to be able to use it again | ||
| va_end(args); |
|
|
||
| // Googletest does not support variadic arguments. Therefore we pass through the formatted string so that we can | ||
| // use it with MOCK_METHOD. | ||
| MOCK_METHOD(void, MockedSyslog, (std::int32_t priority, const std::string& message), (const, noexcept)); |
|
|
||
| #include "score/os/syslog_impl.h" | ||
|
|
||
| namespace score |
|
|
||
| #include <syslog.h> | ||
|
|
||
| namespace score |
|
|
||
| #include <cstdarg> | ||
|
|
||
| namespace score |
|
|
||
| #include "score/os/syslog.h" | ||
|
|
||
| namespace score |
Description
Adds
score::os::Syslog, a new OS-abstraction wrapper (interface +impl + mock) around glibc's openlog(3)/syslog(3)/closelog(3),
following the existing score::os::qnx::Slog2 pattern. Includes unit
tests under score/os/test/linux/, reusing the existing generic
OS-wrapper requirement SCR-46010294.
This is a prerequisite for a companion contribution to the logging
component (eclipse-score/logging#270), which consumes
@score_baselibs//score/os:syslog to implement the LogMode::kSystem
backend for mw::log on Linux.
Related ticket
closes #501