Skip to content

RDKEMW-15565: Can localtime plugin to track changes outside the container#420

Open
bgray-sky wants to merge 4 commits intordkcentral:developfrom
bgray-sky:RDKEMW-15565_bind_mount_etc_localtime
Open

RDKEMW-15565: Can localtime plugin to track changes outside the container#420
bgray-sky wants to merge 4 commits intordkcentral:developfrom
bgray-sky:RDKEMW-15565_bind_mount_etc_localtime

Conversation

@bgray-sky
Copy link
Copy Markdown
Contributor

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/localtime file within a container correctly changes when the timezone is changed on the device.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (doesn't fit into the above categories - e.g. documentation updates)

Requires Bitbake Recipe changes?

  • The base Bitbake recipe (meta-rdk-ext/recipes-containers/dobby/dobby.bb) must be modified to support the changes in this PR (beyond updating SRC_REV)

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.
Copilot AI review requested due to automatic review settings March 16, 2026 14:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 path option 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.

Comment on lines 22 to +24
## 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)];
Copy link
Copy Markdown
Contributor

@rdkcmf-jenkins rdkcmf-jenkins Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copilot AI review requested due to automatic review settings March 27, 2026 09:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TimeZoneMonitor component that uses inotify + polling to detect changes to a host timezone file and rewrite registered container paths.
  • Updated LocalTimePlugin to create /etc/localtime under the container rootfs and register it with TimeZoneMonitor.
  • 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 TimeZoneMonitor which 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.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +334 to +340
/**
* @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)
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +53
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));
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@bgray-sky bgray-sky changed the title RDKEMW-15565: Bind mount /etc/localtime into container. RDKEMW-15565: Can localtime plugin to track changes outside the container Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants