@@ -119,10 +119,7 @@ bool isInitViewMode()
119
119
120
120
bool g_veryFirstRun = false ;
121
121
122
- void exit_and_notify (int status) __attribute__ ((__noreturn__));
123
-
124
- void exit_and_notify (
125
- _In_ int status)
122
+ void notify_OA_about_syncd_exception ()
126
123
{
127
124
SWSS_LOG_ENTER ();
128
125
@@ -147,20 +144,6 @@ void exit_and_notify(
147
144
{
148
145
SWSS_LOG_ERROR (" Unknown runtime error" );
149
146
}
150
-
151
- if (options.disableExitSleep )
152
- {
153
- exit (status);
154
- }
155
-
156
- SWSS_LOG_WARN (" sleep forever to keep data plane active" );
157
-
158
- while (true )
159
- {
160
- sleep (UINT_MAX);
161
-
162
- SWSS_LOG_NOTICE (" sleep ended, sleeping again" );
163
- }
164
147
}
165
148
166
149
void sai_diag_shell (
@@ -2395,8 +2378,7 @@ sai_status_t handle_bulk_generic(
2395
2378
}
2396
2379
else
2397
2380
{
2398
- SWSS_LOG_ERROR (" api %d is not supported in bulk route" , api);
2399
- exit_and_notify (EXIT_FAILURE);
2381
+ SWSS_LOG_THROW (" api %d is not supported in bulk route" , api);
2400
2382
}
2401
2383
2402
2384
if (status != SAI_STATUS_SUCCESS)
@@ -2472,8 +2454,7 @@ sai_status_t processBulkEvent(
2472
2454
2473
2455
if (isInitViewMode ())
2474
2456
{
2475
- SWSS_LOG_ERROR (" bulk api (%d) is not supported in init view mode" , api);
2476
- exit_and_notify (EXIT_FAILURE);
2457
+ SWSS_LOG_THROW (" bulk api (%d) is not supported in init view mode" , api);
2477
2458
}
2478
2459
2479
2460
if (api != SAI_COMMON_API_BULK_GET)
@@ -2500,17 +2481,14 @@ sai_status_t processBulkEvent(
2500
2481
break ;
2501
2482
2502
2483
default :
2503
- SWSS_LOG_ERROR (" bulk api for %s is not supported yet, FIXME" ,
2484
+ SWSS_LOG_THROW (" bulk api for %s is not supported yet, FIXME" ,
2504
2485
sai_serialize_object_type (object_type).c_str ());
2505
- exit_and_notify (EXIT_FAILURE);
2506
2486
}
2507
2487
2508
2488
if (status != SAI_STATUS_SUCCESS)
2509
2489
{
2510
- SWSS_LOG_ERROR (" failed to execute bulk api: %s" ,
2490
+ SWSS_LOG_THROW (" failed to execute bulk api: %s" ,
2511
2491
sai_serialize_status (status).c_str ());
2512
-
2513
- exit_and_notify (EXIT_FAILURE);
2514
2492
}
2515
2493
2516
2494
return status;
@@ -3667,6 +3645,10 @@ int syncd_main(int argc, char **argv)
3667
3645
sai_switch_api_t *sai_switch_api = NULL ;
3668
3646
sai_api_query (SAI_API_SWITCH, (void **)&sai_switch_api);
3669
3647
3648
+ volatile bool runMainLoop = true ;
3649
+
3650
+ std::shared_ptr<swss::Select> s = std::make_shared<swss::Select>();
3651
+
3670
3652
try
3671
3653
{
3672
3654
SWSS_LOG_NOTICE (" before onSyncdStart" );
@@ -3681,16 +3663,32 @@ int syncd_main(int argc, char **argv)
3681
3663
3682
3664
SWSS_LOG_NOTICE (" syncd listening for events" );
3683
3665
3684
- std::shared_ptr<swss::Select> s = std::make_shared<swss::Select>();
3685
-
3686
3666
s->addSelectable (asicState.get ());
3687
3667
s->addSelectable (restartQuery.get ());
3688
3668
s->addSelectable (flexCounter.get ());
3689
3669
s->addSelectable (flexCounterGroup.get ());
3690
3670
3691
3671
SWSS_LOG_NOTICE (" starting main loop" );
3672
+ }
3673
+ catch (const std::exception &e)
3674
+ {
3675
+ SWSS_LOG_ERROR (" Runtime error during syncd init: %s" , e.what ());
3676
+
3677
+ notify_OA_about_syncd_exception ();
3692
3678
3693
- while (true )
3679
+ s = std::make_shared<swss::Select>();
3680
+
3681
+ s->addSelectable (restartQuery.get ());
3682
+
3683
+ SWSS_LOG_NOTICE (" starting main loop, ONLY restart query" );
3684
+
3685
+ if (options.disableExitSleep )
3686
+ runMainLoop = false ;
3687
+ }
3688
+
3689
+ while (runMainLoop)
3690
+ {
3691
+ try
3694
3692
{
3695
3693
swss::Selectable *sel = NULL ;
3696
3694
@@ -3719,6 +3717,7 @@ int syncd_main(int argc, char **argv)
3719
3717
if (shutdownType != SYNCD_RESTART_TYPE_PRE_SHUTDOWN)
3720
3718
{
3721
3719
// break out the event handling loop to shutdown syncd
3720
+ runMainLoop = false ;
3722
3721
break ;
3723
3722
}
3724
3723
@@ -3788,12 +3787,22 @@ int syncd_main(int argc, char **argv)
3788
3787
processEvent (*(swss::ConsumerTable*)sel);
3789
3788
}
3790
3789
}
3791
- }
3792
- catch (const std::exception &e)
3793
- {
3794
- SWSS_LOG_ERROR (" Runtime error: %s" , e.what ());
3790
+ catch (const std::exception &e)
3791
+ {
3792
+ SWSS_LOG_ERROR (" Runtime error: %s" , e.what ());
3793
+
3794
+ notify_OA_about_syncd_exception ();
3795
3795
3796
- exit_and_notify (EXIT_FAILURE);
3796
+ s = std::make_shared<swss::Select>();
3797
+
3798
+ s->addSelectable (restartQuery.get ());
3799
+
3800
+ if (options.disableExitSleep )
3801
+ runMainLoop = false ;
3802
+
3803
+ // make sure that if second exception will arise, then we break the loop
3804
+ options.disableExitSleep = true ;
3805
+ }
3797
3806
}
3798
3807
3799
3808
if (shutdownType == SYNCD_RESTART_TYPE_WARM)
0 commit comments