From 1af9fe843209593caeb1dcedd0841cf7cd8fd19c 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)