Skip to content

Commit 1cc0489

Browse files
committed
[syncd] Move logSet logGet under mutex to prevent race condition
Fixes: sonic-net/sonic-buildimage#21180
1 parent cfd46c4 commit 1cc0489

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

syncd/VendorSai.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ sai_status_t VendorSai::logSet(
16791679
_In_ sai_api_t api,
16801680
_In_ sai_log_level_t log_level)
16811681
{
1682+
MUTEX();
16821683
SWSS_LOG_ENTER();
16831684

16841685
m_logLevelMap[api] = log_level;
@@ -1689,6 +1690,7 @@ sai_status_t VendorSai::logSet(
16891690
sai_log_level_t VendorSai::logGet(
16901691
_In_ sai_api_t api)
16911692
{
1693+
MUTEX();
16921694
SWSS_LOG_ENTER();
16931695

16941696
auto it = m_logLevelMap.find(api);

unittest/syncd/TestVendorSai.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,3 +1405,15 @@ TEST(VendorSai, bulk_dash_outbound_ca_to_pa_entry)
14051405
remove_counter(sai, counter0);
14061406
remove_counter(sai, counter1);
14071407
}
1408+
1409+
TEST(VendorSai, logSet_logGet)
1410+
{
1411+
VendorSai sai;
1412+
sai.apiInitialize(0, &test_services);
1413+
1414+
EXPECT_EQ(SAI_STATUS_SUCCESS, sai.logSet(SAI_API_PORT, SAI_LOG_LEVEL_DEBUG));
1415+
1416+
EXPECT(SAI_LOG_LEVEL_DEBUG, sai.logGet(SAI_API_PORT));
1417+
EXPECT(SAI_LOG_LEVEL_NOTICE, sai.logGet(SAI_API_SWITCH));
1418+
}
1419+

0 commit comments

Comments
 (0)