From d7448b4c60fd884955850e4f5ddf0f51593da079 Mon Sep 17 00:00:00 2001 From: bluesky Date: Wed, 17 Jul 2024 14:49:46 +0800 Subject: [PATCH] fix: Create soft link for the watch file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在容器运行时给容器内的监听文件创建软链接。文件修改后也能获取到修改。 Log: --- libs/linglong/src/linglong/runtime/container.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libs/linglong/src/linglong/runtime/container.cpp b/libs/linglong/src/linglong/runtime/container.cpp index ea4252d45..d7f0888e3 100644 --- a/libs/linglong/src/linglong/runtime/container.cpp +++ b/libs/linglong/src/linglong/runtime/container.cpp @@ -205,6 +205,22 @@ Container::run(const ocppi::runtime::config::types::Process &process) noexcept .uidMappings = {}, }); + QStringList watchFilesPaths = {"localtime", "resolv.conf", "timezone"}; + for (const QString &watchFile: watchFilesPaths) { + if (symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8()) != 0) { + qCritical() << "Failed to create symlink for" << watchFile; + continue; + } + this->cfg.mounts->push_back(ocppi::runtime::config::types::Mount{ + .destination = "/etc/"+watchFile.toStdString(), + .gidMappings = {}, + .options = { { "rbind", "copy-symlink" } }, + .source = bundle.absoluteFilePath(watchFile).toStdString(), + .type = "bind", + .uidMappings = {}, + }); + } + nlohmann::json json = this->cfg; {