Skip to content

Commit

Permalink
[orchagent]: Avoid crash by setting g_syncMode flag before create_swi…
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhangalibaba authored and stcheng committed Aug 5, 2019
1 parent 34b582c commit 264e548
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,9 @@ int main(int argc, char **argv)
attrs.push_back(attr);
}

status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
exit(EXIT_FAILURE);
}
SWSS_LOG_NOTICE("Create a switch");

// SAI_REDIS_SWITCH_ATTR_SYNC_MODE attribute only setBuffer and g_syncMode to true
// since it is not using ASIC_DB, we can execute it before create_switch
// when g_syncMode is set to true here, create_switch will wait the response from syncd
if (gSyncMode)
{
attr.id = SAI_REDIS_SWITCH_ATTR_SYNC_MODE;
Expand All @@ -236,6 +231,15 @@ int main(int argc, char **argv)
sai_switch_api->set_switch_attribute(gSwitchId, &attr);
}


status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
exit(EXIT_FAILURE);
}
SWSS_LOG_NOTICE("Create a switch");

/* Get switch source MAC address if not provided */
if (!gMacAddress)
{
Expand Down

0 comments on commit 264e548

Please sign in to comment.