diff --git a/cfgmgr/Makefile.am b/cfgmgr/Makefile.am index e11ec4635ae..c39f727998b 100644 --- a/cfgmgr/Makefile.am +++ b/cfgmgr/Makefile.am @@ -24,69 +24,69 @@ DBGFLAGS = -g endif vlanmgrd_SOURCES = vlanmgrd.cpp vlanmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -vlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vlanmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +vlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vlanmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) teammgrd_SOURCES = teammgrd.cpp teammgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -teammgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +teammgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) portmgrd_SOURCES = portmgrd.cpp portmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -portmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -portmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -portmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +portmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +portmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +portmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) intfmgrd_SOURCES = intfmgrd.cpp intfmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/lib/subintf.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -intfmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +intfmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) buffermgrd_SOURCES = buffermgrd.cpp buffermgr.cpp buffermgrdyn.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -buffermgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -buffermgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -buffermgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +buffermgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +buffermgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +buffermgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) vrfmgrd_SOURCES = vrfmgrd.cpp vrfmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -vrfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vrfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vrfmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +vrfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vrfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vrfmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) nbrmgrd_SOURCES = nbrmgrd.cpp nbrmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -nbrmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CFLAGS) -nbrmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CPPFLAGS) -nbrmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) $(LIBNL_LIBS) +nbrmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CFLAGS) $(CFLAGS_ASAN) +nbrmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CPPFLAGS) $(CFLAGS_ASAN) +nbrmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) $(LIBNL_LIBS) vxlanmgrd_SOURCES = vxlanmgrd.cpp vxlanmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -vxlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vxlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -vxlanmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +vxlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vxlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +vxlanmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) sflowmgrd_SOURCES = sflowmgrd.cpp sflowmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -sflowmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -sflowmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -sflowmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +sflowmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +sflowmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +sflowmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) natmgrd_SOURCES = natmgrd.cpp natmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -natmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -natmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -natmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +natmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +natmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +natmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) coppmgrd_SOURCES = coppmgrd.cpp coppmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -coppmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -coppmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -coppmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +coppmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +coppmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +coppmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) tunnelmgrd_SOURCES = tunnelmgrd.cpp tunnelmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -tunnelmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -tunnelmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -tunnelmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +tunnelmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +tunnelmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +tunnelmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) macsecmgrd_SOURCES = macsecmgrd.cpp macsecmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h -macsecmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -macsecmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -macsecmgrd_LDADD = $(COMMON_LIBS) $(SAIMETA_LIBS) +macsecmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +macsecmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +macsecmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) if GCOV_ENABLED vlanmgrd_LDADD += -lgcovpreload diff --git a/cfgmgr/buffermgrd.cpp b/cfgmgr/buffermgrd.cpp index 05932a9e3c5..e62bd789c28 100644 --- a/cfgmgr/buffermgrd.cpp +++ b/cfgmgr/buffermgrd.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "dbconnector.h" #include "select.h" @@ -29,6 +30,7 @@ using json = nlohmann::json; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -109,6 +111,11 @@ shared_ptr> load_json(string file) } } +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { int opt; @@ -119,6 +126,12 @@ int main(int argc, char **argv) Logger::linkToDbNative("buffermgrd"); SWSS_LOG_ENTER(); + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + SWSS_LOG_NOTICE("--- Starting buffermgrd ---"); while ((opt = getopt(argc, argv, "l:a:p:z:h")) != -1 ) @@ -234,7 +247,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -258,6 +271,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/coppmgrd.cpp b/cfgmgr/coppmgrd.cpp index 60b0a2442a9..5d0f3ca1d71 100644 --- a/cfgmgr/coppmgrd.cpp +++ b/cfgmgr/coppmgrd.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "exec.h" #include "coppmgr.h" @@ -24,6 +25,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -36,8 +38,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("coppmgrd"); SWSS_LOG_ENTER(); @@ -68,7 +81,7 @@ int main(int argc, char **argv) s.addSelectables(o->getSelectables()); } - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -92,6 +105,7 @@ int main(int argc, char **argv) catch (const exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return 1; } - return -1; + return 0; } diff --git a/cfgmgr/intfmgrd.cpp b/cfgmgr/intfmgrd.cpp index 9ed36533335..1b11bd191b2 100644 --- a/cfgmgr/intfmgrd.cpp +++ b/cfgmgr/intfmgrd.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "dbconnector.h" #include "select.h" #include "exec.h" @@ -24,6 +25,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -36,8 +38,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("intfmgrd"); SWSS_LOG_ENTER(); @@ -73,7 +86,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -97,6 +110,8 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + + return 0; } diff --git a/cfgmgr/macsecmgrd.cpp b/cfgmgr/macsecmgrd.cpp index 913c0ac4eef..b0373e73665 100644 --- a/cfgmgr/macsecmgrd.cpp +++ b/cfgmgr/macsecmgrd.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,7 @@ MacAddress gMacAddress; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -45,9 +47,18 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } try { @@ -73,7 +84,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -97,6 +108,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/natmgrd.cpp b/cfgmgr/natmgrd.cpp index c2baf7eb879..6aaf9c0ec25 100644 --- a/cfgmgr/natmgrd.cpp +++ b/cfgmgr/natmgrd.cpp @@ -47,6 +47,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -64,7 +65,7 @@ NotificationConsumer *flushNotificationsConsumer = NULL; std::shared_ptr cleanupNotifier; -void sigterm_handler(int signo) +void cleanup() { int ret = 0; std::string res; @@ -88,7 +89,7 @@ void sigterm_handler(int signo) cleanupNotifier->send("nat_cleanup", "all", entry); } - + if (natmgr) { natmgr->removeStaticNatIptables(); @@ -100,8 +101,19 @@ void sigterm_handler(int signo) } } +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action handler"); + exit(1); + } + Logger::linkToDbNative("natmgrd"); SWSS_LOG_ENTER(); @@ -129,16 +141,10 @@ int main(int argc, char **argv) cleanupNotifier = std::make_shared(&appDb, "NAT_DB_CLEANUP_NOTIFICATION"); - if (signal(SIGTERM, sigterm_handler) == SIG_ERR) - { - SWSS_LOG_ERROR("failed to setup SIGTERM action handler"); - exit(1); - } - natmgr = new NatMgr(&cfgDb, &appDb, &stateDb, cfg_tables); natmgr->isPortInitDone(&appDb); - + std::vector cfgOrchList = {natmgr}; swss::Select s; @@ -154,7 +160,7 @@ int main(int argc, char **argv) s.addSelectable(flushNotificationsConsumer); SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -197,10 +203,12 @@ int main(int argc, char **argv) auto *c = (Executor *)sel; c->execute(); } + cleanup(); } catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/nbrmgrd.cpp b/cfgmgr/nbrmgrd.cpp index 338d8d9d0d5..a7d9d8cd5e9 100644 --- a/cfgmgr/nbrmgrd.cpp +++ b/cfgmgr/nbrmgrd.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "select.h" #include "exec.h" @@ -28,6 +29,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -40,8 +42,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("nbrmgrd"); SWSS_LOG_ENTER(); @@ -89,7 +102,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -113,6 +126,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/portmgrd.cpp b/cfgmgr/portmgrd.cpp index 180bbc1d632..d95b22542ae 100644 --- a/cfgmgr/portmgrd.cpp +++ b/cfgmgr/portmgrd.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "exec.h" #include "portmgr.h" @@ -23,6 +24,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -35,8 +37,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("portmgrd"); SWSS_LOG_ENTER(); @@ -63,7 +76,7 @@ int main(int argc, char **argv) s.addSelectables(o->getSelectables()); } - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -87,6 +100,7 @@ int main(int argc, char **argv) catch (const exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/sflowmgrd.cpp b/cfgmgr/sflowmgrd.cpp index 7de5f15a2d3..965748da9df 100644 --- a/cfgmgr/sflowmgrd.cpp +++ b/cfgmgr/sflowmgrd.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "exec.h" #include "sflowmgr.h" @@ -23,6 +24,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -35,8 +37,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("sflowmgrd"); SWSS_LOG_ENTER(); @@ -63,7 +76,7 @@ int main(int argc, char **argv) s.addSelectables(o->getSelectables()); } - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -87,6 +100,7 @@ int main(int argc, char **argv) catch (const exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/tunnelmgrd.cpp b/cfgmgr/tunnelmgrd.cpp index 0165eb94b5f..e38df9cd60b 100644 --- a/cfgmgr/tunnelmgrd.cpp +++ b/cfgmgr/tunnelmgrd.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "dbconnector.h" #include "select.h" @@ -26,6 +27,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -38,8 +40,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("tunnelmgrd"); SWSS_LOG_NOTICE("--- Starting Tunnelmgrd ---"); @@ -65,7 +78,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -89,6 +102,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index b69dc781228..45a53da7761 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -5,6 +5,8 @@ #include #include #include +#include + #include "dbconnector.h" #include "select.h" #include "exec.h" @@ -31,6 +33,7 @@ MacAddress gMacAddress; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -43,8 +46,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("vlanmgrd"); SWSS_LOG_ENTER(); @@ -89,7 +103,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -113,6 +127,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/vrfmgrd.cpp b/cfgmgr/vrfmgrd.cpp index 735e59191d6..c07095c520f 100644 --- a/cfgmgr/vrfmgrd.cpp +++ b/cfgmgr/vrfmgrd.cpp @@ -1,6 +1,8 @@ #include #include #include +#include + #include "dbconnector.h" #include "select.h" #include "exec.h" @@ -24,6 +26,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -36,8 +39,19 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("vrfmgrd"); bool isWarmStart = false; SWSS_LOG_ENTER(); @@ -74,7 +88,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; static bool firstReadTimeout = true; @@ -107,6 +121,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/cfgmgr/vxlanmgrd.cpp b/cfgmgr/vxlanmgrd.cpp index d47893a614e..0a763bcab23 100644 --- a/cfgmgr/vxlanmgrd.cpp +++ b/cfgmgr/vxlanmgrd.cpp @@ -4,6 +4,8 @@ #include #include #include +#include + #include #include "dbconnector.h" #include "select.h" @@ -29,6 +31,7 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ +bool gExit = false; int gBatchSize = 0; bool gSwssRecord = false; bool gLogRotate = false; @@ -42,8 +45,19 @@ string gResponsePublisherRecordFile; mutex gDbMutex; MacAddress gMacAddress; +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("vxlanmgrd"); SWSS_LOG_NOTICE("--- Starting vxlanmgrd ---"); @@ -104,7 +118,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("starting main loop"); - while (true) + while (!gExit) { Selectable *sel; int ret; @@ -137,6 +151,7 @@ int main(int argc, char **argv) catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); + return -1; } - return -1; + return 0; } diff --git a/configure.ac b/configure.ac index 5e5ce44171a..b2c03c60154 100644 --- a/configure.ac +++ b/configure.ac @@ -121,6 +121,26 @@ fi AM_CONDITIONAL(GCOV_ENABLED, test x$enable_gcov = xyes) AC_MSG_RESULT($enable_gcov) +AC_ARG_ENABLE(asan, +[ --enable-asan Compile with address sanitizer], +[case "${enableval}" in + yes) asan_enabled=true ;; + no) asan_enabled=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-asan) ;; +esac],[asan_enabled=false]) + +if test "x$asan_enabled" = "xtrue"; then + CFLAGS_ASAN+=" -fsanitize=address" + CFLAGS_ASAN+=" -DASAN_ENABLED" + CFLAGS_ASAN+=" -ggdb" + AC_SUBST(CFLAGS_ASAN) + + LDFLAGS_ASAN+=" -lasan" + AC_SUBST(LDFLAGS_ASAN) +fi + +AM_CONDITIONAL(ASAN_ENABLED, test x$asan_enabled = xtrue) + AC_SUBST(CFLAGS_COMMON) AC_CONFIG_FILES([ diff --git a/debian/rules b/debian/rules index a8a8b835fba..bfcbfdeb959 100755 --- a/debian/rules +++ b/debian/rules @@ -27,11 +27,19 @@ include /usr/share/dpkg/default.mk # dh_auto_configure -- \ # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) +configure_opts = +ifeq ($(ENABLE_ASAN), y) + configure_opts += --enable-asan +endif + ifeq ($(ENABLE_GCOV), y) -override_dh_auto_configure: - dh_auto_configure -- --enable-gcov + configure_opts += --enable-gcov endif +override_dh_auto_configure: + $(info "override_dh_auto_configure called") + dh_auto_configure -- $(configure_opts) + override_dh_auto_install: dh_auto_install --destdir=debian/swss ifeq ($(ENABLE_GCOV), y) diff --git a/fdbsyncd/Makefile.am b/fdbsyncd/Makefile.am index 4ab2f5dddd6..54586ac9043 100644 --- a/fdbsyncd/Makefile.am +++ b/fdbsyncd/Makefile.am @@ -10,9 +10,9 @@ endif fdbsyncd_SOURCES = fdbsyncd.cpp fdbsync.cpp $(top_srcdir)/warmrestart/warmRestartAssist.cpp -fdbsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) -fdbsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) -fdbsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS) +fdbsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) $(CFLAGS_ASAN) +fdbsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) $(CFLAGS_ASAN) +fdbsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS) if GCOV_ENABLED fdbsyncd_LDADD += -lgcovpreload diff --git a/fdbsyncd/fdbsyncd.cpp b/fdbsyncd/fdbsyncd.cpp index a83b2693e11..f3b33ffd06a 100644 --- a/fdbsyncd/fdbsyncd.cpp +++ b/fdbsyncd/fdbsyncd.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "logger.h" #include "select.h" #include "netdispatcher.h" @@ -9,11 +10,26 @@ #include "fdbsyncd/fdbsync.h" #include "warm_restart.h" +#define SELECT_TIMEOUT 1000 + using namespace std; using namespace swss; +bool gExit = false; + +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("fdbsyncd"); DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); @@ -28,7 +44,7 @@ int main(int argc, char **argv) NetDispatcher::getInstance().registerMessageHandler(RTM_DELNEIGH, &sync); NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync); - while (1) + while (!gExit) { try { @@ -41,13 +57,13 @@ int main(int argc, char **argv) using namespace std::chrono; /* - * If WarmStart is enabled, restore the VXLAN-FDB and VNI + * If WarmStart is enabled, restore the VXLAN-FDB and VNI * tables and start a reconcillation timer */ if (sync.getRestartAssist()->isWarmStartInProgress()) { sync.getRestartAssist()->readTablesToMap(); - + steady_clock::time_point starttime = steady_clock::now(); while (!sync.isIntfRestoreDone()) { @@ -88,9 +104,9 @@ int main(int argc, char **argv) s.addSelectable(sync.getFdbStateTable()); s.addSelectable(sync.getMclagRemoteFdbStateTable()); s.addSelectable(sync.getCfgEvpnNvoTable()); - while (true) + while (!gExit) { - s.select(&temps); + s.select(&temps, SELECT_TIMEOUT); if (temps == (Selectable *)sync.getFdbStateTable()) { @@ -157,5 +173,5 @@ int main(int argc, char **argv) } } - return 1; + return 0; } diff --git a/fpmsyncd/Makefile.am b/fpmsyncd/Makefile.am index ef709db8767..909ac2c2306 100644 --- a/fpmsyncd/Makefile.am +++ b/fpmsyncd/Makefile.am @@ -10,9 +10,9 @@ endif fpmsyncd_SOURCES = fpmsyncd.cpp fpmlink.cpp routesync.cpp $(top_srcdir)/warmrestart/warmRestartHelper.cpp -fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -fpmsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon +fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +fpmsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon if GCOV_ENABLED fpmsyncd_LDADD += -lgcovpreload diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index 8f797e178ca..ea81797b392 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "logger.h" #include "select.h" #include "selectabletimer.h" @@ -8,10 +9,13 @@ #include "fpmsyncd/fpmlink.h" #include "fpmsyncd/routesync.h" +#define SELECT_TIMEOUT 1000 using namespace std; using namespace swss; +bool gExit = false; + /* * Default warm-restart timer interval for routing-stack app. To be used only if * no explicit value has been defined in configuration. @@ -44,8 +48,19 @@ static bool eoiuFlagsSet(Table &bgpStateTable) return true; } +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + swss::Logger::linkToDbNative("fpmsyncd"); DBConnector db("APPL_DB", 0); RedisPipeline pipeline(&db); @@ -57,7 +72,7 @@ int main(int argc, char **argv) NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync); NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &sync); - while (true) + while (!gExit) { try { @@ -68,7 +83,7 @@ int main(int argc, char **argv) SelectableTimer eoiuCheckTimer(timespec{0, 0}); // After eoiu flags are detected, start a hold timer before starting reconciliation. SelectableTimer eoiuHoldTimer(timespec{0, 0}); - + /* * Pipeline should be flushed right away to deal with state pending * from previous try/catch iterations. @@ -115,12 +130,12 @@ int main(int argc, char **argv) sync.m_warmStartHelper.setState(WarmStart::WSDISABLED); } - while (true) + while (!gExit) { Selectable *temps; /* Reading FPM messages forever (and calling "readMe" to read them) */ - s.select(&temps); + s.select(&temps, SELECT_TIMEOUT); /* * Upon expiration of the warm-restart timer or eoiu Hold Timer, proceed to run the diff --git a/gearsyncd/Makefile.am b/gearsyncd/Makefile.am index c9df85853a4..30c67e50442 100644 --- a/gearsyncd/Makefile.am +++ b/gearsyncd/Makefile.am @@ -10,9 +10,9 @@ endif gearsyncd_SOURCES = $(top_srcdir)/lib/gearboxutils.cpp gearsyncd.cpp gearparserbase.cpp gearboxparser.cpp phyparser.cpp $(top_srcdir)/cfgmgr/shellcmd.h -gearsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) $(ASAN_CFLAGS) +gearsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(COV_CFLAGS) $(CFLAGS_ASAN) -gearsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS) $(ASAN_LDFLAGS) +gearsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon $(COV_LDFLAGS) if GCOV_ENABLED gearsyncd_LDADD += -lgcovpreload diff --git a/mclagsyncd/Makefile.am b/mclagsyncd/Makefile.am index e7bed8de7de..383c7b61781 100644 --- a/mclagsyncd/Makefile.am +++ b/mclagsyncd/Makefile.am @@ -10,9 +10,9 @@ endif mclagsyncd_SOURCES = mclagsyncd.cpp mclaglink.cpp -mclagsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -mclagsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -mclagsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon +mclagsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +mclagsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +mclagsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon if GCOV_ENABLED mclagsyncd_LDADD += -lgcovpreload diff --git a/mclagsyncd/mclagsyncd.cpp b/mclagsyncd/mclagsyncd.cpp index bbd48a7e50d..b72b3b76b0a 100644 --- a/mclagsyncd/mclagsyncd.cpp +++ b/mclagsyncd/mclagsyncd.cpp @@ -18,6 +18,7 @@ * Maintainer: Jim Jiang from nephos */ #include +#include #include "logger.h" #include #include "select.h" @@ -27,11 +28,26 @@ #include "schema.h" #include +#define SELECT_TIMEOUT 1000 + using namespace std; using namespace swss; +bool gExit = false; + +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + swss::Logger::linkToDbNative("mclagsyncd"); DBConnector appl_db("APPL_DB", 0); @@ -41,7 +57,7 @@ int main(int argc, char **argv) SubscriberStateTable mclag_cfg_tbl(&config_db, CFG_MCLAG_TABLE_NAME); map learn_mode; - while (1) + while (!gExit) { try { @@ -63,13 +79,12 @@ int main(int argc, char **argv) s.addSelectable(&mclag_cfg_tbl); SWSS_LOG_NOTICE("MCLagSYNCD Adding mclag_cfg_tbl to selectables"); - while (true) + while (!gExit) { Selectable *temps; /* Reading MCLAG messages forever (and calling "readData" to read them) */ - s.select(&temps); - + s.select(&temps, SELECT_TIMEOUT); if(temps == (Selectable *)mclag.getStateFdbTable()) { @@ -83,7 +98,7 @@ int main(int argc, char **argv) mclag_cfg_tbl.pops(entries); mclag.processMclagDomainCfg(entries); } - else if ( temps == (Selectable *)mclag.getMclagIntfCfgTable() ) //Reading MCLAG Interface Config Table + else if ( temps == (Selectable *)mclag.getMclagIntfCfgTable() ) //Reading MCLAG Interface Config Table { SWSS_LOG_DEBUG("MCLAGSYNCD processing mclag_intf_cfg_tbl notifications"); std::deque entries; @@ -120,7 +135,7 @@ int main(int argc, char **argv) } } - return 1; + return 0; } diff --git a/natsyncd/Makefile.am b/natsyncd/Makefile.am index d8212ee4b4c..d92fca6f13e 100644 --- a/natsyncd/Makefile.am +++ b/natsyncd/Makefile.am @@ -10,9 +10,9 @@ endif natsyncd_SOURCES = natsyncd.cpp natsync.cpp $(top_srcdir)/warmrestart/warmRestartAssist.cpp -natsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -natsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -natsyncd_LDADD = -lnl-3 -lnl-route-3 -lnl-nf-3 -lswsscommon +natsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +natsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +natsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lnl-nf-3 -lswsscommon if GCOV_ENABLED natsyncd_LDADD += -lgcovpreload diff --git a/natsyncd/natsyncd.cpp b/natsyncd/natsyncd.cpp index c8591f2c063..70cfe2a04df 100644 --- a/natsyncd/natsyncd.cpp +++ b/natsyncd/natsyncd.cpp @@ -2,17 +2,33 @@ #include #include #include +#include #include "logger.h" #include "select.h" #include "netdispatcher.h" #include "natsync.h" #include +#define SELECT_TIMEOUT 1000 + using namespace std; using namespace swss; +bool gExit = false; + +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("natsyncd"); DBConnector appDb("APPL_DB", 0); @@ -28,7 +44,7 @@ int main(int argc, char **argv) NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_NEW), &sync); NetDispatcher::getInstance().registerMessageHandler(NFNLMSG_TYPE(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_DELETE), &sync); - while (1) + while (!gExit) { try { @@ -71,10 +87,10 @@ int main(int argc, char **argv) nfnl.dumpRequest(IPCTNL_MSG_CT_GET); s.addSelectable(&nfnl); - while (true) + while (!gExit) { Selectable *temps; - s.select(&temps); + s.select(&temps, SELECT_TIMEOUT); /* * If warmstart is in progress, we check the reconcile timer, * if timer expired, we stop the timer and start the reconcile process @@ -96,5 +112,5 @@ int main(int argc, char **argv) } } - return 1; + return 0; } diff --git a/neighsyncd/Makefile.am b/neighsyncd/Makefile.am index 23e76b6cd20..205cf943579 100644 --- a/neighsyncd/Makefile.am +++ b/neighsyncd/Makefile.am @@ -10,9 +10,9 @@ endif neighsyncd_SOURCES = neighsyncd.cpp neighsync.cpp $(top_srcdir)/warmrestart/warmRestartAssist.cpp -neighsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -neighsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -neighsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon +neighsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +neighsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +neighsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon if GCOV_ENABLED neighsyncd_LDADD += -lgcovpreload diff --git a/neighsyncd/neighsyncd.cpp b/neighsyncd/neighsyncd.cpp index a0882c28e27..c7afe8328a0 100644 --- a/neighsyncd/neighsyncd.cpp +++ b/neighsyncd/neighsyncd.cpp @@ -2,17 +2,33 @@ #include #include #include +#include #include "logger.h" #include "select.h" #include "netdispatcher.h" #include "netlink.h" #include "neighsyncd/neighsync.h" +#define SELECT_TIMEOUT 1000 + using namespace std; using namespace swss; +bool gExit = false; + +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("neighsyncd"); DBConnector appDb("APPL_DB", 0); @@ -25,7 +41,7 @@ int main(int argc, char **argv) NetDispatcher::getInstance().registerMessageHandler(RTM_NEWNEIGH, &sync); NetDispatcher::getInstance().registerMessageHandler(RTM_DELNEIGH, &sync); - while (1) + while (!gExit) { try { @@ -67,10 +83,10 @@ int main(int argc, char **argv) netlink.dumpRequest(RTM_GETNEIGH); s.addSelectable(&netlink); - while (true) + while (!gExit) { Selectable *temps; - s.select(&temps); + s.select(&temps, SELECT_TIMEOUT); /* * If warmstart is in progress, we check the reconcile timer, * if timer expired, we stop the timer and start the reconcile process @@ -92,5 +108,5 @@ int main(int argc, char **argv) } } - return 1; + return 0; } diff --git a/orchagent/Makefile.am b/orchagent/Makefile.am index 68aa474552b..807142d65b4 100644 --- a/orchagent/Makefile.am +++ b/orchagent/Makefile.am @@ -109,18 +109,18 @@ orchagent_SOURCES += p4orch/p4orch.cpp \ p4orch/wcmp_manager.cpp \ p4orch/mirror_session_manager.cpp -orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) -orchagent_LDADD = -lnl-3 -lnl-route-3 -lpthread -lsairedis -lsaimeta -lsaimetadata -lswsscommon -lzmq +orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) +orchagent_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lpthread -lsairedis -lsaimeta -lsaimetadata -lswsscommon -lzmq routeresync_SOURCES = routeresync.cpp -routeresync_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -routeresync_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -routeresync_LDADD = -lswsscommon +routeresync_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +routeresync_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +routeresync_LDADD = $(LDFLAGS_ASAN) -lswsscommon orchagent_restart_check_SOURCES = orchagent_restart_check.cpp -orchagent_restart_check_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) -orchagent_restart_check_LDADD = -lhiredis -lswsscommon -lpthread +orchagent_restart_check_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +orchagent_restart_check_LDADD = $(LDFLAGS_ASAN) -lhiredis -lswsscommon -lpthread if GCOV_ENABLED orchagent_LDADD += -lgcovpreload diff --git a/orchagent/bfdorch.cpp b/orchagent/bfdorch.cpp index 68295842b33..0b2888ea3d4 100644 --- a/orchagent/bfdorch.cpp +++ b/orchagent/bfdorch.cpp @@ -53,7 +53,7 @@ BfdOrch::BfdOrch(DBConnector *db, string tableName, TableConnector stateDbBfdSes { SWSS_LOG_ENTER(); - DBConnector *notificationsDb = new DBConnector("ASIC_DB", 0); + shared_ptr notificationsDb = make_shared("ASIC_DB", 0); m_bfdStateNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS"); auto bfdStateNotificatier = new Notifier(m_bfdStateNotificationConsumer, this, "BFD_STATE_NOTIFICATIONS"); Orch::addExecutor(bfdStateNotificatier); diff --git a/orchagent/bufferorch.cpp b/orchagent/bufferorch.cpp index e7204344d5a..0532459d7f4 100644 --- a/orchagent/bufferorch.cpp +++ b/orchagent/bufferorch.cpp @@ -28,12 +28,12 @@ static const vector bufferPoolWatermarkStatIds = }; type_map BufferOrch::m_buffer_type_maps = { - {APP_BUFFER_POOL_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PROFILE_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_QUEUE_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PG_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, new object_reference_map()}, - {APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, new object_reference_map()} + {APP_BUFFER_POOL_TABLE_NAME, make_shared()}, + {APP_BUFFER_PROFILE_TABLE_NAME, make_shared()}, + {APP_BUFFER_QUEUE_TABLE_NAME, make_shared()}, + {APP_BUFFER_PG_TABLE_NAME, make_shared()}, + {APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, make_shared()}, + {APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, make_shared()} }; map buffer_to_ref_table_map = { diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index daab3ad52ef..7ca24112459 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "logger.h" #include "tokenize.h" @@ -34,7 +35,7 @@ FdbOrch::FdbOrch(DBConnector* applDbConnector, vector app { for(auto it: appFdbTables) { - m_appTables.push_back(new Table(applDbConnector, it.first)); + m_appTables.push_back(make_shared(applDbConnector, it.first)); } m_portsOrch->attach(this); @@ -43,7 +44,7 @@ FdbOrch::FdbOrch(DBConnector* applDbConnector, vector app Orch::addExecutor(flushNotifier); /* Add FDB notifications support from ASIC */ - DBConnector *notificationsDb = new DBConnector("ASIC_DB", 0); + shared_ptr notificationsDb = make_shared("ASIC_DB", 0); m_fdbNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS"); auto fdbNotifier = new Notifier(m_fdbNotificationConsumer, this, "FDB_NOTIFICATIONS"); Orch::addExecutor(fdbNotifier); diff --git a/orchagent/fdborch.h b/orchagent/fdborch.h index 82611e686f6..067d22ba578 100644 --- a/orchagent/fdborch.h +++ b/orchagent/fdborch.h @@ -105,7 +105,7 @@ class FdbOrch: public Orch, public Subject, public Observer PortsOrch *m_portsOrch; map m_entries; fdb_entries_by_port_t saved_fdb_entries; - vector m_appTables; + vector> m_appTables; Table m_fdbStateTable; Table m_mclagFdbStateTable; NotificationConsumer* m_flushNotificationsConsumer; diff --git a/orchagent/flex_counter/flex_counter_manager.cpp b/orchagent/flex_counter/flex_counter_manager.cpp index 71731e84d3f..8113b9b6b7c 100644 --- a/orchagent/flex_counter/flex_counter_manager.cpp +++ b/orchagent/flex_counter/flex_counter_manager.cpp @@ -48,7 +48,7 @@ const unordered_map FlexCounterManager::counter_id_field_lo FlexManagerDirectory g_FlexManagerDirectory; -FlexCounterManager *FlexManagerDirectory::createFlexCounterManager(const string& group_name, +shared_ptr FlexManagerDirectory::createFlexCounterManager(const string& group_name, const StatsMode stats_mode, const uint polling_interval, const bool enabled, @@ -76,7 +76,7 @@ FlexCounterManager *FlexManagerDirectory::createFlexCounterManager(const string& } return m_managers[group_name]; } - FlexCounterManager *fc_manager = new FlexCounterManager(group_name, stats_mode, polling_interval, + shared_ptr fc_manager = make_shared(group_name, stats_mode, polling_interval, enabled, fv_plugin); m_managers[group_name] = fc_manager; return fc_manager; diff --git a/orchagent/flex_counter/flex_counter_manager.h b/orchagent/flex_counter/flex_counter_manager.h index 6e80feb8fba..3dbdea42515 100644 --- a/orchagent/flex_counter/flex_counter_manager.h +++ b/orchagent/flex_counter/flex_counter_manager.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "dbconnector.h" #include "producertable.h" #include "table.h" @@ -114,11 +115,11 @@ class FlexCounterManager class FlexManagerDirectory { public: - FlexCounterManager* createFlexCounterManager(const std::string& group_name, const StatsMode stats_mode, + std::shared_ptr createFlexCounterManager(const std::string& group_name, const StatsMode stats_mode, const uint polling_interval, const bool enabled, swss::FieldValueTuple fv_plugin = std::make_pair("","")); private: - std::unordered_map m_managers; + std::unordered_map> m_managers; }; #endif // ORCHAGENT_FLEX_COUNTER_MANAGER_H diff --git a/orchagent/main.cpp b/orchagent/main.cpp index de96234a2d4..79d2c468e87 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -61,6 +61,7 @@ bool gLogRotate = false; bool gSaiRedisLogRotate = false; bool gResponsePublisherLogRotate = false; bool gSyncMode = false; +bool gExit = false; sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC; string gAsicInstance; @@ -114,6 +115,11 @@ void sighup_handler(int signo) gResponsePublisherLogRotate = true; } +void sigterm_handler(int signo) +{ + gExit = true; +} + void syncd_apply_view() { SWSS_LOG_NOTICE("Notify syncd APPLY_VIEW"); @@ -328,6 +334,12 @@ int main(int argc, char **argv) exit(1); } + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + int opt; sai_status_t status; @@ -364,7 +376,7 @@ int main(int argc, char **argv) // Disable all recordings if atoi() fails i.e. returns 0 due to // invalid command line argument. record_type = atoi(optarg); - if (record_type < 0 || record_type > 7) + if (record_type < 0 || record_type > 7) { usage(); exit(EXIT_FAILURE); @@ -457,7 +469,7 @@ int main(int argc, char **argv) } // Disable/Enable response publisher recording. - if (gResponsePublisherRecord) + if (gResponsePublisherRecord) { gResponsePublisherRecordFile = record_location + "/" + responsepublisher_rec_filename; gResponsePublisherRecordOfs.open(gResponsePublisherRecordFile, std::ofstream::out | std::ofstream::app); @@ -466,8 +478,8 @@ int main(int argc, char **argv) SWSS_LOG_ERROR("Failed to open Response Publisher recording file %s", gResponsePublisherRecordFile.c_str()); gResponsePublisherRecord = false; - } - else + } + else { gResponsePublisherRecordOfs << getTimestamp() << "|recording started" << endl; diff --git a/orchagent/orch.h b/orchagent/orch.h index 46a5d446ce9..230e0e364ea 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -68,7 +68,7 @@ typedef struct } referenced_object; typedef std::map object_reference_map; -typedef std::map type_map; +typedef std::map> type_map; typedef std::map object_map; typedef std::pair object_map_pair; diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 0341f69ea94..e079e091236 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -21,6 +21,7 @@ using namespace swss; extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; extern bool gSaiRedisLogRotate; +extern bool gExit; extern void syncd_apply_view(); /* @@ -325,7 +326,7 @@ bool OrchDaemon::init() * when iterating ConsumerMap. This is ensured implicitly by the order of keys in ordered map. * For cases when Orch has to process tables in specific order, like PortsOrch during warm start, it has to override Orch::doTask() */ - m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, mux_orch, mux_cb_orch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, qos_orch, wm_orch, policer_orch, tunnel_decap_orch, sflow_orch, debug_counter_orch, gMacsecOrch, gBfdOrch, gSrv6Orch}; + m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, mux_orch, mux_cb_orch, gFdbOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, qos_orch, wm_orch, policer_orch, tunnel_decap_orch, sflow_orch, debug_counter_orch, gMacsecOrch, gBfdOrch, gSrv6Orch}; bool initialize_dtel = false; if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING) @@ -392,7 +393,6 @@ bool OrchDaemon::init() gPbhOrch = new PbhOrch(pbhTableConnectorList, gAclOrch, gPortsOrch); - m_orchList.push_back(gFdbOrch); m_orchList.push_back(gMirrorOrch); m_orchList.push_back(gAclOrch); m_orchList.push_back(gPbhOrch); @@ -661,7 +661,7 @@ void OrchDaemon::start() auto tstart = std::chrono::high_resolution_clock::now(); - while (true) + while (!gExit) { Selectable *s; int ret; diff --git a/orchagent/p4orch/p4orch.cpp b/orchagent/p4orch/p4orch.cpp index ada1fa2c778..d93586f565c 100644 --- a/orchagent/p4orch/p4orch.cpp +++ b/orchagent/p4orch/p4orch.cpp @@ -62,8 +62,8 @@ P4Orch::P4Orch(swss::DBConnector *db, std::vector tableNames, VRFOr m_aclCounterStatsTimer->start(); // Add port state change notification handling support - swss::DBConnector notificationsDb("ASIC_DB", 0); - m_portStatusNotificationConsumer = new swss::NotificationConsumer(¬ificationsDb, "NOTIFICATIONS"); + shared_ptr notificationsDb = make_shared("ASIC_DB", 0); + m_portStatusNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS"); auto portStatusNotifier = new Notifier(m_portStatusNotificationConsumer, this, "PORT_STATUS_NOTIFICATIONS"); Orch::addExecutor(portStatusNotifier); } diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index ada1f4bb920..7f6fdddeb06 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -543,7 +543,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector notificationsDb = make_shared("ASIC_DB", 0); m_portStatusNotificationConsumer = new swss::NotificationConsumer(notificationsDb, "NOTIFICATIONS"); auto portStatusNotificatier = new Notifier(m_portStatusNotificationConsumer, this, "PORT_STATUS_NOTIFICATIONS"); Orch::addExecutor(portStatusNotificatier); diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index 5a48b699695..1f086f073cf 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -65,19 +65,19 @@ map scheduler_meter_map = { }; type_map QosOrch::m_qos_maps = { - {CFG_DSCP_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_DOT1P_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_QUEUE_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_SCHEDULER_TABLE_NAME, new object_reference_map()}, - {CFG_WRED_PROFILE_TABLE_NAME, new object_reference_map()}, - {CFG_PORT_QOS_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_QUEUE_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_DSCP_TO_FC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_EXP_TO_FC_MAP_TABLE_NAME, new object_reference_map()}, + {CFG_DSCP_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_DOT1P_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_TC_TO_QUEUE_MAP_TABLE_NAME, make_shared()}, + {CFG_SCHEDULER_TABLE_NAME, make_shared()}, + {CFG_WRED_PROFILE_TABLE_NAME, make_shared()}, + {CFG_PORT_QOS_MAP_TABLE_NAME, make_shared()}, + {CFG_QUEUE_TABLE_NAME, make_shared()}, + {CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared()}, + {CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared()}, + {CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, make_shared()}, + {CFG_DSCP_TO_FC_MAP_TABLE_NAME, make_shared()}, + {CFG_EXP_TO_FC_MAP_TABLE_NAME, make_shared()} }; map qos_to_ref_table_map = { diff --git a/orchagent/vxlanorch.h b/orchagent/vxlanorch.h index 0b56e76faa5..7a95e49f308 100644 --- a/orchagent/vxlanorch.h +++ b/orchagent/vxlanorch.h @@ -373,9 +373,8 @@ class VxlanTunnelOrch : public Orch2 VTEPTable vtep_table_; Table m_stateVxlanTable; std::map m_pendingAddToFlexCntr; - FlexCounterManager vxlan_tunnel_stat_manager; bool m_isTunnelCounterMapGenerated = false; - FlexCounterManager *tunnel_stat_manager; + std::shared_ptr tunnel_stat_manager; unique_ptr
m_tunnelNameTable; unique_ptr
m_tunnelTypeTable; unique_ptr
m_vidToRidTable; diff --git a/portsyncd/Makefile.am b/portsyncd/Makefile.am index 5bba269ab26..c3d4132e544 100644 --- a/portsyncd/Makefile.am +++ b/portsyncd/Makefile.am @@ -10,9 +10,9 @@ endif portsyncd_SOURCES = $(top_srcdir)/lib/gearboxutils.cpp portsyncd.cpp linksync.cpp $(top_srcdir)/cfgmgr/shellcmd.h -portsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -portsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon +portsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +portsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon if GCOV_ENABLED portsyncd_LDADD += -lgcovpreload diff --git a/portsyncd/portsyncd.cpp b/portsyncd/portsyncd.cpp index c55c1685af1..5d174aa6135 100644 --- a/portsyncd/portsyncd.cpp +++ b/portsyncd/portsyncd.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "dbconnector.h" #include "select.h" #include "netdispatcher.h" @@ -22,6 +23,7 @@ using namespace swss; #define DEFAULT_SELECT_TIMEOUT 1000 /* ms */ +bool gExit = false; /* * This g_portSet contains all the front panel ports that the corresponding * host interfaces needed to be created. When this LinkSync class is @@ -48,8 +50,19 @@ void handleVlanIntfFile(string file); void handlePortConfig(ProducerStateTable &p, map &port_cfg_map); void checkPortInitDone(DBConnector *appl_db); +void sigterm_handler(int signo) +{ + gExit = true; +} + int main(int argc, char **argv) { + if (signal(SIGTERM, sigterm_handler) == SIG_ERR) + { + SWSS_LOG_ERROR("failed to setup SIGTERM action"); + exit(1); + } + Logger::linkToDbNative("portsyncd"); int opt; map port_cfg_map; @@ -95,7 +108,7 @@ int main(int argc, char **argv) s.addSelectable(&netlink); s.addSelectable(&portCfg); - while (true) + while (!gExit) { Selectable *temps; int ret; @@ -176,7 +189,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - return 1; + return 0; } static void notifyPortConfigDone(ProducerStateTable &p) @@ -247,7 +260,7 @@ void handlePortConfig(ProducerStateTable &p, map /* No support for port delete yet */ if (op == SET_COMMAND) { - + for (auto i : values) { auto field = fvField(i); @@ -272,7 +285,7 @@ void handlePortConfig(ProducerStateTable &p, map autoneg = fvValue(i); attrs.push_back(i); } - else + else { attrs.push_back(i); } diff --git a/swssconfig/Makefile.am b/swssconfig/Makefile.am index 590e7d9f562..e90827b3d20 100644 --- a/swssconfig/Makefile.am +++ b/swssconfig/Makefile.am @@ -10,15 +10,15 @@ endif swssconfig_SOURCES = swssconfig.cpp -swssconfig_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -swssconfig_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -swssconfig_LDADD = -lswsscommon +swssconfig_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +swssconfig_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +swssconfig_LDADD = $(LDFLAGS_ASAN) -lswsscommon swssplayer_SOURCES = swssplayer.cpp -swssplayer_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -swssplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -swssplayer_LDADD = -lswsscommon +swssplayer_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +swssplayer_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +swssplayer_LDADD = $(LDFLAGS_ASAN) -lswsscommon if GCOV_ENABLED swssconfig_LDADD += -lgcovpreload diff --git a/teamsyncd/Makefile.am b/teamsyncd/Makefile.am index 2939a52f2ad..e0e166a62ad 100644 --- a/teamsyncd/Makefile.am +++ b/teamsyncd/Makefile.am @@ -10,9 +10,9 @@ endif teamsyncd_SOURCES = teamsyncd.cpp teamsync.cpp -teamsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -teamsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -teamsyncd_LDADD = -lnl-3 -lnl-route-3 -lhiredis -lswsscommon -lteam +teamsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +teamsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +teamsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lhiredis -lswsscommon -lteam if GCOV_ENABLED teamsyncd_LDADD += -lgcovpreload diff --git a/tests/mock_tests/mock_orchagent_main.cpp b/tests/mock_tests/mock_orchagent_main.cpp index 62a03dc7700..924fa643d5f 100644 --- a/tests/mock_tests/mock_orchagent_main.cpp +++ b/tests/mock_tests/mock_orchagent_main.cpp @@ -25,6 +25,7 @@ string gMySwitchType = "switch"; int32_t gVoqMySwitchId = 0; string gMyHostName = "Linecard1"; string gMyAsicName = "Asic0"; +bool gExit = false; VRFOrch *gVrfOrch; diff --git a/tlm_teamd/Makefile.am b/tlm_teamd/Makefile.am index 6bf7574a8f6..b1ea69fac27 100644 --- a/tlm_teamd/Makefile.am +++ b/tlm_teamd/Makefile.am @@ -10,9 +10,9 @@ endif tlm_teamd_SOURCES = main.cpp teamdctl_mgr.cpp values_store.cpp -tlm_teamd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -tlm_teamd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(JANSSON_CFLAGS) -tlm_teamd_LDADD = -lhiredis -lswsscommon -lteamdctl $(JANSSON_LIBS) +tlm_teamd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN) +tlm_teamd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(JANSSON_CFLAGS) $(CFLAGS_ASAN) +tlm_teamd_LDADD = $(LDFLAGS_ASAN) -lhiredis -lswsscommon -lteamdctl $(JANSSON_LIBS) if GCOV_ENABLED tlm_teamd_LDADD += -lgcovpreload