summaryrefslogtreecommitdiffstats
path: root/log_manager.cpp
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2017-02-28 12:53:37 -0600
committerAdriana Kobylak <anoo@us.ibm.com>2017-03-02 15:52:52 -0600
commit6721899ba8f85d201ba2f7f394f5b5027aedfd8b (patch)
treeb0ea12b360c7a0cfd1d92b83d2553ff5018a0df6 /log_manager.cpp
parent465aaeccc5c01a437b3a3b23a9566482af0c32b5 (diff)
downloadphosphor-logging-6721899ba8f85d201ba2f7f394f5b5027aedfd8b.tar.gz
phosphor-logging-6721899ba8f85d201ba2f7f394f5b5027aedfd8b.zip
Look for an exact match of transaction id
Currently the code would search for a matching string in the whole TRANSACTION_ID=1234 string, but there may cases that this could result in a false match. Change to extract the id number out of the string to do an exact compare. Change-Id: I2cc0e6b42937a36e9afb942c07c91c0b4469a963 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Diffstat (limited to 'log_manager.cpp')
-rw-r--r--log_manager.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/log_manager.cpp b/log_manager.cpp
index 507ff25..d8f233c 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -23,6 +23,7 @@ namespace logging
void Manager::commit(uint64_t transactionId, std::string errMsg)
{
constexpr const auto transactionIdVar = "TRANSACTION_ID";
+ constexpr const auto transactionIdVarSize = strlen(transactionIdVar);
sd_journal *j = nullptr;
int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
@@ -64,8 +65,10 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
continue;
}
- std::string result(data, length);
- if (result.find(transactionIdStr) == std::string::npos)
+ // The metadata field result will be TRANSACTION_ID=1234. Skip the
+ // TRANSACTION_ID piece and (=) sign to get the id number to compare.
+ if (strcmp((data + transactionIdVarSize + 1),
+ transactionIdStr.c_str()) != 0)
{
// The value of the TRANSACTION_ID metadata is not the requested
// transaction id number.
OpenPOWER on IntegriCloud