RDKEMW-15565: Can localtime plugin to track changes outside the container#420
RDKEMW-15565: Can localtime plugin to track changes outside the container#420bgray-sky wants to merge 4 commits intordkcentral:developfrom
Conversation
Changed the LocalTime plugin so that it bind mounts the localtime file into the container rather than copying it. This allows the symlink outside the container to change, and since it's bind mounted inside the container then the symlink should change inside the container as well.
There was a problem hiding this comment.
Pull request overview
Updates the RDK LocalTime plugin to configure container timezone via an OCI bind mount instead of creating a symlink in the extracted rootfs, aiming to keep /etc/localtime in sync with host changes.
Changes:
- Switch
LocalTimePlugin::postInstallation()from creating a symlink to adding a bind mount for/etc/localtime. - Add basic validation/fallback for a configured timezone file path.
- Update README to describe the new
pathoption behavior (bind mount).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| rdkPlugins/LocalTime/source/LocalTimePlugin.cpp | Replaces symlink creation with an addMount bind mount and adds path validation/logging. |
| rdkPlugins/LocalTime/README.md | Updates the path option description to reflect bind-mounting into /etc/localtime. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ## Options | ||
| ### path | ||
| Optional parameter, if set, localtime symlink path should be set, else the default path `etc/localtime` is set. | ||
| Optional parameter, if set, then the given file is bind mounted to `/etc/localtime` in the container. Defaults to `/etc/localtime` if not set. |
Switched to use inotify to monitor for changes in the localtime files and echo them into the container's /etc/localtime file.
|
|
||
| std::string randomSuffix = ".tmp."; | ||
| for (int i = 0; i < 6; i++) | ||
| randomSuffix += letters[rand() % (sizeof(letters) - 1)]; |
There was a problem hiding this comment.
Coverity issue no longer present as of: undefined
Show issue
Coverity Issue - Calling risky function
"rand" should not be used for security-related applications, because linear congruential algorithms are too easy to break.
Low Impact, CWE-676
DC.WEAK_CRYPTO
How to fix
Use a compliant random number generator, such as "/dev/random" or "/dev/urandom" on Unix-like systems, and CNG (Cryptography API: Next Generation) on Windows.
Worked around coverity complaint about non-terminated string.
There was a problem hiding this comment.
Pull request overview
This PR updates the LocalTime RDK plugin to keep /etc/localtime inside the container in sync with the host by introducing a background monitor that detects host timezone changes and updates the container’s timezone file accordingly.
Changes:
- Added a new
TimeZoneMonitorcomponent that uses inotify + polling to detect changes to a host timezone file and rewrite registered container paths. - Updated
LocalTimePluginto create/etc/localtimeunder the container rootfs and register it withTimeZoneMonitor. - Updated build configuration and README to reflect the new approach (though documentation/implementation are currently inconsistent).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| rdkPlugins/LocalTime/source/TimeZoneMonitor.h | New monitor interface for tracking timezone file changes and updating container paths. |
| rdkPlugins/LocalTime/source/TimeZoneMonitor.cpp | New inotify-based implementation that reads host TZ data and atomically rewrites container TZ files. |
| rdkPlugins/LocalTime/source/LocalTimePlugin.h | Plugin updated to hold a TimeZoneMonitor instance (comments still reference symlinks). |
| rdkPlugins/LocalTime/source/LocalTimePlugin.cpp | Plugin now initializes the monitor and registers /etc/localtime in the container rootfs for updates. |
| rdkPlugins/LocalTime/README.md | Updated path option description (currently disagrees with implementation and other README text). |
| rdkPlugins/LocalTime/CMakeLists.txt | Adds TimeZoneMonitor.cpp and enables C++17 for <filesystem> usage. |
Comments suppressed due to low confidence (1)
rdkPlugins/LocalTime/source/LocalTimePlugin.h:34
- The header comment still says the plugin "creates a symlink" in the container rootfs, but this change introduces
TimeZoneMonitorwhich writes/updates the timezone file contents instead. Please update the class comment to reflect the new behavior (and the intended bind-mount approach, if that's still the goal).
* @brief Dobby LocalTime plugin.
*
* This plugin simply creates a symlink to the real /etc/localtime file
* in the rootfs of the container.
*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ## Options | ||
| ### path | ||
| Optional parameter, if set, localtime symlink path should be set, else the default path `etc/localtime` is set. | ||
| Optional parameter, if set, then the given file is bind mounted to `/etc/localtime` in the container. Defaults to `/etc/localtime` if not set. |
There was a problem hiding this comment.
README is now inconsistent with the implementation and even with itself: it still says the plugin will "symlink" the path (Quick Start section), but the updated path option claims a bind-mount into /etc/localtime. Current code in LocalTimePlugin writes/updates a file in the container rootfs and does not call addMount to create a bind mount. Please align the README (and option semantics) with the actual behavior, or implement the bind-mount approach described here.
| /** | ||
| * @brief Updates a symlink to point to the new target of the time zone file. | ||
| * | ||
| * Overwrites the existing symlink at \a linkPath to point to \a targetPath. | ||
| */ | ||
| void TimeZoneMonitor::updateTimeZoneFile(const std::filesystem::path &linkPath, | ||
| const std::vector<uint8_t> &tzData) |
There was a problem hiding this comment.
The docstring for updateTimeZoneFile (and several other comments in this file) still describes updating a symlink/target path, but the implementation writes TZ bytes into a regular file and atomically renames it into place. Updating the comments to match the actual behavior will avoid confusion for future maintainers.
| std::error_code ec; | ||
| std::filesystem::path tzFilePath; | ||
| if (containerConfig->rdk_plugins->localtime->data->path) | ||
| { | ||
| tzFilePath = containerConfig->rdk_plugins->localtime->data->path; | ||
| if (tzFilePath.empty() || !std::filesystem::is_regular_file(tzFilePath, ec)) | ||
| { | ||
| AI_LOG_ERROR("invalid timezone file path '%s', reverting to '/etc/localtime'", tzFilePath.c_str()); | ||
| tzFilePath = "/etc/localtime"; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| tzFilePath = "/etc/localtime"; | ||
| } | ||
|
|
||
| mTimeZoneMonitor = std::make_unique<TimeZoneMonitor>(std::move(tzFilePath)); |
There was a problem hiding this comment.
The meaning/usage of the localtime.data.path setting appears to have changed: it is now treated as a host timezone file to monitor, but postInstallation() always writes to .../etc/localtime in the container rootfs (ignoring any configured destination path). This is a behavior/API change from the previous "symlink path" semantics; please either preserve the prior destination-path behavior or update the schema/README and implement the bind-mount behavior described in the PR.
Description
Changed the LocalTime plugin so that it bind mounts the localtime file into the container rather than copying it.
This allows the symlink outside the container to change, and since it's bind mounted inside the container then the symlink should change inside the container as well.
Test Procedure
Check that the
/etc/localtimefile within a container correctly changes when the timezone is changed on the device.Type of Change
Requires Bitbake Recipe changes?
meta-rdk-ext/recipes-containers/dobby/dobby.bb) must be modified to support the changes in this PR (beyond updatingSRC_REV)