From 92fb3de8a8f255ea98fe79877e6784e3bf6738dd Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Wed, 21 Sep 2022 09:43:45 -0400 Subject: [PATCH] Respect $TMPDIR in chip-tool config (#22738) 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)