Skip to content

Commit 68d90e0

Browse files
Abhishek Dosipavel-shirshov
Abhishek Dosi
andcommitted
[teamsyncd][teammgrd] Graceful exit after receiving SIGTERM (sonic-net#1407)
* [teamsyncd][teammgrd] Graceful exit after receiving SIGTERM Signed-off-by: Sabareesh Kumar Anandan <[email protected]> * Update teammgrd.cpp * Update teamsyncd.cpp Co-authored-by: pavel-shirshov <[email protected]>
1 parent a8893ec commit 68d90e0

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

cfgmgr/teammgrd.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ int main(int argc, char **argv)
6565
s.addSelectables(o->getSelectables());
6666
}
6767

68-
while (true)
69-
{
70-
if(received_sigterm)
71-
{
72-
teammgr.cleanTeamProcesses(SIGTERM);
73-
received_sigterm = false;
74-
}
75-
68+
while (!received_sigterm)
69+
{
7670
Selectable *sel;
7771
int ret;
7872

@@ -91,6 +85,8 @@ int main(int argc, char **argv)
9185
auto *c = (Executor *)sel;
9286
c->execute();
9387
}
88+
teammgr.cleanTeamProcesses(SIGTERM);
89+
SWSS_LOG_NOTICE("Exiting");
9490
}
9591
catch (const exception &e)
9692
{

teamsyncd/teamsyncd.cpp

+18-26
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,28 @@ int main(int argc, char **argv)
3232
/* Register the signal handler for SIGTERM */
3333
signal(SIGTERM, sig_handler);
3434

35-
while (1)
35+
try
3636
{
37-
try
38-
{
39-
NetLink netlink;
40-
41-
netlink.registerGroup(RTNLGRP_LINK);
42-
cout << "Listens to teamd events..." << endl;
43-
netlink.dumpRequest(RTM_GETLINK);
44-
45-
s.addSelectable(&netlink);
46-
while (true)
47-
{
48-
if(received_sigterm)
49-
{
50-
sync.cleanTeamSync();
51-
received_sigterm = false;
52-
}
37+
NetLink netlink;
38+
netlink.registerGroup(RTNLGRP_LINK);
39+
cout << "Listens to teamd events..." << endl;
40+
netlink.dumpRequest(RTM_GETLINK);
5341

54-
Selectable *temps;
55-
s.select(&temps, 1000); // block for a second
56-
sync.periodic();
57-
}
58-
}
59-
catch (const std::exception& e)
42+
s.addSelectable(&netlink);
43+
while (!received_sigterm)
6044
{
61-
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
62-
return 0;
45+
Selectable *temps;
46+
s.select(&temps, 1000); // block for a second
47+
sync.periodic();
6348
}
49+
sync.cleanTeamSync();
50+
SWSS_LOG_NOTICE("Received SIGTERM Exiting");
51+
}
52+
catch (const std::exception& e)
53+
{
54+
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
55+
return 0;
6456
}
6557

66-
return 1;
58+
return 0;
6759
}

0 commit comments

Comments
 (0)