Skip to content

Commit

Permalink
[teamsyncd][teammgrd] Graceful exit after receiving SIGTERM (#1407)
Browse files Browse the repository at this point in the history
* [teamsyncd][teammgrd] Graceful exit after receiving SIGTERM

Signed-off-by: Sabareesh Kumar Anandan <sanandan@marvell.com>
* Update teammgrd.cpp
* Update teamsyncd.cpp

Co-authored-by: pavel-shirshov <pavelsh@microsoft.com>
  • Loading branch information
Sabareesh-Kumar-Anandan and pavel-shirshov committed Sep 4, 2020
1 parent 1b89185 commit e54948a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
12 changes: 4 additions & 8 deletions cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,8 @@ int main(int argc, char **argv)
s.addSelectables(o->getSelectables());
}

while (true)
{
if(received_sigterm)
{
teammgr.cleanTeamProcesses(SIGTERM);
received_sigterm = false;
}

while (!received_sigterm)
{
Selectable *sel;
int ret;

Expand All @@ -91,6 +85,8 @@ int main(int argc, char **argv)
auto *c = (Executor *)sel;
c->execute();
}
teammgr.cleanTeamProcesses(SIGTERM);
SWSS_LOG_NOTICE("Exiting");
}
catch (const exception &e)
{
Expand Down
44 changes: 18 additions & 26 deletions teamsyncd/teamsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,28 @@ int main(int argc, char **argv)
/* Register the signal handler for SIGTERM */
signal(SIGTERM, sig_handler);

while (1)
try
{
try
{
NetLink netlink;

netlink.registerGroup(RTNLGRP_LINK);
cout << "Listens to teamd events..." << endl;
netlink.dumpRequest(RTM_GETLINK);

s.addSelectable(&netlink);
while (true)
{
if(received_sigterm)
{
sync.cleanTeamSync();
received_sigterm = false;
}
NetLink netlink;
netlink.registerGroup(RTNLGRP_LINK);
cout << "Listens to teamd events..." << endl;
netlink.dumpRequest(RTM_GETLINK);

Selectable *temps;
s.select(&temps, 1000); // block for a second
sync.periodic();
}
}
catch (const std::exception& e)
s.addSelectable(&netlink);
while (!received_sigterm)
{
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
return 0;
Selectable *temps;
s.select(&temps, 1000); // block for a second
sync.periodic();
}
sync.cleanTeamSync();
SWSS_LOG_NOTICE("Received SIGTERM Exiting");
}
catch (const std::exception& e)
{
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
return 0;
}

return 1;
return 0;
}

0 comments on commit e54948a

Please sign in to comment.