-
Notifications
You must be signed in to change notification settings - Fork 11
RDKB-63306: cujo-agent agent.txt - add log rotation #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
8a494a1
8e88ea3
9750e24
0ffc625
0080884
9d5c66a
1868a67
ffd7edb
0034e57
62357f5
942b1a0
f6a1256
73fd38c
2136965
e8a8fa6
760dd0b
6b6d962
9f9b455
bb8ad44
d1d8fff
eb9ffe4
e263014
116f39e
5529ea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,9 @@ | |||||||||||||||
| #include "safec_lib_common.h" | ||||||||||||||||
| #include "secure_wrapper.h" | ||||||||||||||||
| #include <rbus/rbus.h> | ||||||||||||||||
| #include <sys/stat.h> | ||||||||||||||||
| #include <ev.h> | ||||||||||||||||
| #include <pthread.h> | ||||||||||||||||
| #if defined(_COSA_BCM_MIPS_) | ||||||||||||||||
| #include <ccsp/dpoe_hal.h> | ||||||||||||||||
| #else | ||||||||||||||||
|
|
@@ -91,6 +94,13 @@ | |||||||||||||||
| #define SAFEBRO_CONFIG_FILE_PATH "/tmp/safebro.json" | ||||||||||||||||
| #define ADVSEC_PRIMARY_WAN_IF_NAME "erouter0" | ||||||||||||||||
|
|
||||||||||||||||
| /* Logrotate configuration for agent.txt */ | ||||||||||||||||
| #define ADVSEC_AGENT_LOG_FILE "/rdklogs/logs/agent.txt" | ||||||||||||||||
| #define ADVSEC_AGENT_LOG_MAX_SIZE (2 * 1024 * 1024) /* 2MB */ | ||||||||||||||||
| #define ADVSEC_AGENT_LOG_INTERVAL 5.0 | ||||||||||||||||
| #define LOGROTATE_BINARY "/usr/sbin/logrotate" | ||||||||||||||||
| #define ADVSEC_AGENT_LOGROTATE_CONF "/etc/logrotate.d/advsec-agent" | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+97
to
+103
|
||||||||||||||||
| #ifdef CONFIG_CISCO | ||||||||||||||||
| #define CONFIG_VENDOR_NAME "Cisco" | ||||||||||||||||
| #endif | ||||||||||||||||
|
|
@@ -153,6 +163,8 @@ static char prevWanIfname[MAX_INTERFACE_SIZE] = {0}; | |||||||||||||||
|
|
||||||||||||||||
| void advsec_handle_sysevent_async(void); | ||||||||||||||||
| static void advsec_start_logger_thread(void); | ||||||||||||||||
| static void* agent_log_monitor_thread(void* arg); | ||||||||||||||||
|
||||||||||||||||
| static void* agent_log_monitor_thread(void* arg); | |
| void* agent_log_monitor_thread(void* arg); |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log monitor thread is detached and runs ev_run() indefinitely, but there’s no corresponding shutdown path (e.g., in CosaSecurityRemove/COSA_Unload). This can leave a background thread running after the component is unloaded, causing undefined behavior. Add a stop mechanism (ev_break + thread join/cancel) tied to the component lifecycle.
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log monitor thread is started unconditionally during initialization, even when Is_Device_Finger_Print_Enabled() is false (the logger thread is gated, but the monitor thread is not). This creates a detached thread running an event loop for the lifetime of the process even when the feature is disabled; consider gating this start on the same enable condition (or stopping it when disabled).
| advsec_start_log_monitor_thread(); | |
| advsec_handle_sysevent_async(); | |
| if(Value == 1) | |
| { | |
| advsec_start_log_monitor_thread(); | |
| advsec_handle_sysevent_async(); | |
| } |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New log rotation behavior is introduced here but there are existing gtest-based unit tests for this module; consider adding coverage for rotation triggering (size threshold) and the logrotate command execution path (success/failure) to prevent regressions.
Copilot
AI
Apr 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New log-rotation behavior (rotate_agent_log + libev watcher) isn’t covered by the existing gtest suite for this module. Adding unit tests that verify the logrotate command is invoked only when the file exceeds the threshold (with mocks for v_secure_system and stat/wrapper) would help prevent regressions.
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ADVSEC_AGENT_LOG_FILE is used here but is not defined anywhere in the repo (no #define/declaration found), which will fail compilation. Define the log path constant (e.g., to agent.txt) in an appropriate header or in this file before using it in stat()/ev_stat_init().
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New log-rotation behavior (size check + logrotate command execution) is introduced here, but there are existing unit tests for this module under source/test/CcspAdvSecurityDmlTest. Consider adding tests for rotate_agent_log() to verify it only invokes v_secure_system once the size threshold is exceeded and that failures are handled/logged correctly.
Copilot
AI
Apr 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
st.st_size is an off_t and isn’t guaranteed to fit %ld (it may be 64-bit on some platforms). This log line should use a format specifier/cast that is correct for off_t (e.g., cast to intmax_t and print with %jd, or use a platform-safe macro) to avoid undefined behavior or incorrect output.
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
st.st_size is an off_t; logging it with %ld is not portable and can be undefined on platforms where off_t is not long. Use an appropriate format (e.g., cast to intmax_t and print with %jd) to avoid incorrect output/UB.
Copilot
AI
Apr 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new logrotate invocation references ADVSEC_AGENT_LOGROTATE_CONF, but that macro isn't defined anywhere in the repo, so this won’t compile. Also, the command line passed to logrotate appears malformed: /tmp/logrotate-advsec.status is being passed as a positional argument rather than via -s <statefile>, which logrotate expects for the state file. Define the config path macro and update the logrotate command to pass a config file and state file using the correct flags.
Copilot
AI
Apr 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_log_stat_cb is only used within this translation unit but is defined with external linkage. Mark it static to avoid exporting the symbol from the library.
| void agent_log_stat_cb(EV_P_ ev_stat *w, int revents) | |
| static void agent_log_stat_cb(EV_P_ ev_stat *w, int revents) |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_log_monitor_thread is forward-declared as static but defined without static here. This is a storage-class mismatch that can fail compilation under strict flags; make the definition static (or drop static from the prototype) so they match.
| void* agent_log_monitor_thread(void* arg) | |
| static void* agent_log_monitor_thread(void* arg) |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new forward declaration marks agent_log_monitor_thread as static (internal linkage), but the definition is non-static. With -Wall -Werror this can fail to compile due to conflicting linkage. Make the definition static (and consider making the other helper functions in this block static as well since they’re file-local).
Copilot
AI
Apr 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stat_watcher is declared static inside agent_log_monitor_thread, which makes it shared across calls/threads and can cause hard-to-debug behavior if the monitor thread is ever started more than once. Prefer a non-static watcher allocated on the thread stack (or heap) so each thread has its own instance.
| static ev_stat stat_watcher; | |
| ev_stat stat_watcher; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding -lev in the library link flags introduces a new build dependency on libev. If libev isn’t guaranteed in all build environments, this may break the build; consider adding proper dependency detection (e.g., via configure/pkg-config) and using discovered CFLAGS/LIBS instead of a fixed -lev.