oem-ibm: write PELs using mktempfs
Instead of writing PELs to a predetermined location and a file, use mktempfs.
Change-Id: I48aacbe45f9932e45586681d9333c44235d3f1b0
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/meson.build b/meson.build
index 3a1e010..42e40af 100644
--- a/meson.build
+++ b/meson.build
@@ -19,7 +19,6 @@
conf_data.set_quoted('PDR_JSONS_DIR', '/usr/share/pldm/pdr')
if get_option('oem-ibm').enabled()
conf_data.set_quoted('FILE_TABLE_JSON', '/usr/share/pldm/fileTable.json')
- conf_data.set_quoted('PEL_TEMP_DIR', '/tmp/pel')
conf_data.set_quoted('LID_PERM_DIR', '/var/lib/pldm/lid')
conf_data.set_quoted('LID_TEMP_DIR', '/var/lib/pldm/lid/temp')
add_global_arguments('-DOEM_IBM', language : 'c')
diff --git a/oem/ibm/libpldmresponder/file_io_type_pel.cpp b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
index 01919b9..a5fa49a 100644
--- a/oem/ibm/libpldmresponder/file_io_type_pel.cpp
+++ b/oem/ibm/libpldmresponder/file_io_type_pel.cpp
@@ -40,15 +40,16 @@
int PelHandler::writeFromMemory(uint32_t offset, uint32_t length,
uint64_t address)
{
- fs::create_directories(PEL_TEMP_DIR);
-
- auto timeMs =
- std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::high_resolution_clock::now().time_since_epoch())
- .count();
- std::string fileName(PEL_TEMP_DIR);
- fileName += "/pel." + std::to_string(timeMs);
- fs::path path(std::move(fileName));
+ char tmpFile[] = "/tmp/pel.XXXXXX";
+ int fd = mkstemp(tmpFile);
+ if (fd == -1)
+ {
+ log<level::ERR>("failed to create a temporary pel",
+ entry("ERROR=%d", errno));
+ return PLDM_ERROR;
+ }
+ close(fd);
+ fs::path path(tmpFile);
auto rc = transferFileData(path, false, offset, length, address);
if (rc == PLDM_SUCCESS)