Skip to content

Commit 4359ae3

Browse files
kcudnikyejianquan
authored andcommitted
[syncd] Move logSet logGet under mutex to prevent race condition
Fixes: sonic-net/sonic-buildimage#21180
1 parent be0c83d commit 4359ae3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

syncd/VendorSai.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ sai_status_t VendorSai::logSet(
19491949
_In_ sai_api_t api,
19501950
_In_ sai_log_level_t log_level)
19511951
{
1952+
MUTEX();
19521953
SWSS_LOG_ENTER();
19531954

19541955
m_logLevelMap[api] = log_level;
@@ -1967,6 +1968,7 @@ sai_status_t VendorSai::queryApiVersion(
19671968
sai_log_level_t VendorSai::logGet(
19681969
_In_ sai_api_t api)
19691970
{
1971+
MUTEX();
19701972
SWSS_LOG_ENTER();
19711973

19721974
auto it = m_logLevelMap.find(api);

unittest/syncd/TestVendorSai.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,14 @@ TEST_F(VendorSaiTest, bulk_prefix_compression_entry)
15581558
EXPECT_EQ(SAI_STATUS_NOT_SUPPORTED,
15591559
m_vsai->bulkSet(0, e, nullptr, SAI_BULK_OP_ERROR_MODE_STOP_ON_ERROR, nullptr));
15601560
}
1561+
1562+
TEST(VendorSai, logSet_logGet)
1563+
{
1564+
VendorSai sai;
1565+
sai.apiInitialize(0, &test_services);
1566+
1567+
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.logSet(SAI_API_PORT, SAI_LOG_LEVEL_DEBUG));
1568+
1569+
EXPECT(SAI_LOG_LEVEL_DEBUG, sai.logGet(SAI_API_PORT));
1570+
EXPECT(SAI_LOG_LEVEL_NOTICE, sai.logGet(SAI_API_SWITCH));
1571+
}

0 commit comments

Comments
 (0)