From 6de582a1e40757cc0d4a4f605d9f836f568b649c Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Mon, 19 Sep 2022 14:37:32 -0400 Subject: [PATCH] Respect $TMPDIR in chip-tool config Some systems may have a different temporary directory. Respect this in chip-tool. --- examples/chip-tool/config/PersistentStorage.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/config/PersistentStorage.cpp b/examples/chip-tool/config/PersistentStorage.cpp index f8ceb248095709..62cf6efdfbd890 100644 --- a/examples/chip-tool/config/PersistentStorage.cpp +++ b/examples/chip-tool/config/PersistentStorage.cpp @@ -41,11 +41,19 @@ constexpr LogCategory kDefaultLoggingLevel = kLogCategory_Automation; std::string GetFilename(const char * name) { + const char * tmpdir = getenv("TMPDIR"); + + if (tmpdir == nullptr) + { + tmpdir = "/tmp"; + } + if (name == nullptr) { - return "/tmp/chip_tool_config.ini"; + return std::string(tmpdir) + "/chip_tool_config.ini"; } - return "/tmp/chip_tool_config." + std::string(name) + ".ini"; + + return std::string(tmpdir) + "/chip_tool_config." + std::string(name) + ".ini"; } CHIP_ERROR PersistentStorage::Init(const char * name)