Skip to content
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

Read base path for config files from TMPDIR env var #33846

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
KVS_PATH also use env var
Add suggestions by @locnnil
  • Loading branch information
jpm-canonical committed Jun 19, 2024
commit 76e44353321fd4f9ffd067d0458599ac74da22c2
4 changes: 1 addition & 3 deletions src/platform/Linux/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;

// ==================== Security Configuration Overrides ====================

#ifndef CHIP_CONFIG_KVS_PATH
#define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs"
#endif // CHIP_CONFIG_KVS_PATH
#define CHIP_DEFAULT_CONFIG_KVS_FILE_NAME "chip_kvs"
13 changes: 7 additions & 6 deletions src/platform/Linux/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ ChipLinuxStorage * PosixConfig::GetStorageForNamespace(Key key)

CHIP_ERROR PosixConfig::Init()
{
return PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
std::string filePath = GetFilePath(CHIP_DEFAULT_CONFIG_KVS_FILE_NAME);
return PersistedStorage::KeyValueStoreMgrImpl().Init(filePath.c_str());
}

CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)
Expand Down Expand Up @@ -453,17 +454,17 @@ bool PosixConfig::ConfigValueExists(Key key)
return storage->HasValue(key.Name);
}

std::string PosixConfig::GetFilePath(std::string defaultFileName)
std::string PosixConfig::GetFilePath(const std::string &defaultFileName)
{
// Match what GetFilename in ExamplePersistentStorage.cpp does.
const char * dir = getenv("TMPDIR");
const char *dir = std::getenv("TMPDIR");
if (dir == nullptr)
{
dir = "/tmp";
}
std::string storageDir = dir;

return storageDir + "/" + defaultFileName;
std::filesystem::path storageDir(dir);
std::filesystem::path filePath = storageDir / defaultFileName;
return filePath.string();
}

CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)
Expand Down
3 changes: 2 additions & 1 deletion src/platform/Linux/PosixConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <functional>
#include <string>
#include <filesystem>
#include <inttypes.h>

#include <lib/core/CHIPError.h>
Expand Down Expand Up @@ -112,7 +113,7 @@ class PosixConfig

private:
static ChipLinuxStorage * GetStorageForNamespace(Key key);
static std::string GetFilePath(std::string defaultFileName);
static std::string GetFilePath(const std::string &defaultFileName);
};

struct PosixConfig::Key
Expand Down
Loading