Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rdkPlugins/LocalTime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ project(LocalTimePlugin)
add_library( ${PROJECT_NAME}
SHARED
source/LocalTimePlugin.cpp
source/TimeZoneMonitor.cpp
)

target_compile_features( ${PROJECT_NAME}
PRIVATE
cxx_std_17
)

target_include_directories(${PROJECT_NAME}
PRIVATE
$<TARGET_PROPERTY:DobbyDaemonLib,INTERFACE_INCLUDE_DIRECTORIES>
)
)

install(
TARGETS ${PROJECT_NAME}
Expand All @@ -39,6 +45,6 @@ install(

target_link_libraries(${PROJECT_NAME}
DobbyRdkPluginCommonLib
)
)

set_target_properties( ${PROJECT_NAME} PROPERTIES SOVERSION 1 )
2 changes: 1 addition & 1 deletion rdkPlugins/LocalTime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you already have other RDK plugins in the bundle, then just add the localtime

## 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.
Comment on lines 22 to +24
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.

### setTZ
Optional parameter, if set it should contain a path to file holding time stamp. This time stamp will be placed in containers env variable called TZ
67 changes: 30 additions & 37 deletions rdkPlugins/LocalTime/source/LocalTimePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

#include "LocalTimePlugin.h"
#include "TimeZoneMonitor.h"

#include <Logging.h>

Comment thread
bgray-sky marked this conversation as resolved.
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>

REGISTER_RDK_PLUGIN(LocalTimePlugin);

Expand All @@ -35,8 +35,23 @@ LocalTimePlugin::LocalTimePlugin(std::shared_ptr<rt_dobby_schema> &containerConf
mContainerConfig(containerConfig),
mUtils(utils)
{
AI_LOG_FN_ENTRY();
AI_LOG_FN_EXIT();
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));
Comment on lines +38 to +54
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.
}

unsigned LocalTimePlugin::hookHints() const
Expand All @@ -58,47 +73,25 @@ bool LocalTimePlugin::postInstallation()
{
AI_LOG_FN_ENTRY();

std::string path;
// the absolute path to the /etc/localtime file in the container rootfs
const std::filesystem::path localTimePath = mRootfsPath + "/etc/localtime";
const std::filesystem::path etcDirPath = localTimePath.parent_path();

if (mContainerConfig->rdk_plugins->localtime->data->path)
// create the /etc directory in the container rootfs if it doesn't already exist
if (mUtils->mkdirRecursive(etcDirPath.string(), 0755) || (errno == EEXIST))
{
path = mContainerConfig->rdk_plugins->localtime->data->path;
std::size_t found = path.find_last_of("/");
std::string dirPath = path.substr(0, found);

if (mUtils->mkdirRecursive(mRootfsPath + dirPath, 0755) || (errno == EEXIST))
AI_LOG_INFO("Set localtime path %s", path.c_str());
else
AI_LOG_SYS_ERROR(errno, "failed to create dir. %s", path.c_str());
AI_LOG_INFO("set localtime path %s/localtime", etcDirPath.c_str());
}
else
{
path = "/etc/localtime";
AI_LOG_INFO("Set default path %s", path.c_str());
}

// get the real path to the correct local time zone
char pathBuf[PATH_MAX];
ssize_t len = readlink(path.c_str(), pathBuf, sizeof(pathBuf));
if (len <= 0)
{
AI_LOG_SYS_ERROR_EXIT(errno, "readlink failed on %s", path.c_str());
AI_LOG_SYS_ERROR(errno, "failed to create dir @ %s", etcDirPath.c_str());
return false;
}

const std::string localtimeInHost(pathBuf, len);
const std::string localtimeInContainer = mRootfsPath + path;

if (localtimeInHost.empty())
{
AI_LOG_ERROR_EXIT("missing real timezone file path");
return false;
}
else if (symlink(localtimeInHost.c_str(), localtimeInContainer.c_str()) < 0)
{
AI_LOG_SYS_ERROR_EXIT(errno, "failed to create %s symlink", path.c_str());
return false;
}
// add the /etc/localtime file to the time zone monitor, it will create the
// initial file in the container rootfs and update it whenever the real time
// zone file changes on the host
mTimeZoneMonitor->addPathToUpdate(localTimePath);

AI_LOG_FN_EXIT();
return true;
Expand Down
7 changes: 6 additions & 1 deletion rdkPlugins/LocalTime/source/LocalTimePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include <RdkPluginBase.h>

#include <memory>

class TimeZoneMonitor;

/**
* @brief Dobby LocalTime plugin.
*
Expand Down Expand Up @@ -54,8 +58,9 @@ class LocalTimePlugin : public RdkPluginBase
private:
const std::string mName;
const std::string mRootfsPath;
std::shared_ptr<rt_dobby_schema> mContainerConfig;
const std::shared_ptr<rt_dobby_schema> mContainerConfig;
const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
std::unique_ptr<TimeZoneMonitor> mTimeZoneMonitor;
};

#endif // !defined(LOCALTIMEPLUGIN_H)
Loading
Loading