Skip to content

Commit

Permalink
[asan] Trigger reports generation from SIGTERM handler.
Browse files Browse the repository at this point in the history
- Add SIGTERM handler to each application.
  • Loading branch information
oleksandrivantsiv committed Mar 17, 2022
1 parent 8e9b06e commit 380fb43
Show file tree
Hide file tree
Showing 22 changed files with 444 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cfgmgr/buffermgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <getopt.h>
#include <vector>
#include <mutex>
#include <signal.h>
#include "dbconnector.h"
#include "select.h"
#include "exec.h"
Expand All @@ -14,6 +15,10 @@
#include "json.hpp"
#include "warm_restart.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;
using json = nlohmann::json;
Expand Down Expand Up @@ -109,6 +114,15 @@ shared_ptr<vector<KeyOpFieldsValuesTuple>> load_json(string file)
}
}

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
int opt;
Expand All @@ -121,6 +135,14 @@ int main(int argc, char **argv)

SWSS_LOG_NOTICE("--- Starting buffermgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

while ((opt = getopt(argc, argv, "l:a:p:z:h")) != -1 )
{
switch (opt)
Expand Down
22 changes: 22 additions & 0 deletions cfgmgr/coppmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
#include <mutex>
#include <unistd.h>
#include <vector>
#include <signal.h>

#include "exec.h"
#include "coppmgr.h"
#include "schema.h"
#include "select.h"
#include "warm_restart.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand All @@ -36,13 +41,30 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
Logger::linkToDbNative("coppmgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting coppmgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
vector<string> cfg_copp_tables = {
Expand Down
23 changes: 23 additions & 0 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <unistd.h>
#include <vector>
#include <mutex>
#include <signal.h>

#include "dbconnector.h"
#include "select.h"
#include "exec.h"
Expand All @@ -10,6 +12,10 @@
#include <iostream>
#include "warm_restart.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand All @@ -36,13 +42,30 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
Logger::linkToDbNative("intfmgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting intfmgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
vector<string> cfg_intf_tables = {
Expand Down
20 changes: 20 additions & 0 deletions cfgmgr/macsecmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <mutex>
#include <algorithm>
#include <signal.h>

#include <logger.h>
#include <producerstatetable.h>
Expand All @@ -17,6 +18,10 @@

#include "macsecmgr.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand Down Expand Up @@ -45,9 +50,24 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
Expand Down
10 changes: 10 additions & 0 deletions cfgmgr/natmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "shellcmd.h"
#include "warm_restart.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand Down Expand Up @@ -98,6 +102,12 @@ void sigterm_handler(int signo)
natmgr->cleanupMangleIpTables();
natmgr->cleanupPoolIpTable();
}

#if defined(ASAN_ENABLED)
__lsan_do_leak_check();
#endif
signal(signo, SIG_DFL);
raise(signo);
}

int main(int argc, char **argv)
Expand Down
22 changes: 22 additions & 0 deletions cfgmgr/nbrmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
#include <fstream>
#include <iostream>
#include <chrono>
#include <signal.h>

#include "select.h"
#include "exec.h"
#include "schema.h"
#include "nbrmgr.h"
#include "warm_restart.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand Down Expand Up @@ -40,13 +45,30 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
Logger::linkToDbNative("nbrmgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting nbrmgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
vector<string> cfg_nbr_tables = {
Expand Down
22 changes: 22 additions & 0 deletions cfgmgr/portmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#include <mutex>
#include <unistd.h>
#include <vector>
#include <signal.h>

#include "exec.h"
#include "portmgr.h"
#include "schema.h"
#include "select.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand All @@ -35,13 +40,30 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
Logger::linkToDbNative("portmgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting portmgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
vector<string> cfg_port_tables = {
Expand Down
22 changes: 22 additions & 0 deletions cfgmgr/sflowmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#include <mutex>
#include <unistd.h>
#include <vector>
#include <signal.h>

#include "exec.h"
#include "sflowmgr.h"
#include "schema.h"
#include "select.h"

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand All @@ -35,13 +40,30 @@ string gResponsePublisherRecordFile;
/* Global database mutex */
mutex gDbMutex;

#if defined(ASAN_ENABLED)
void sigterm_handler(int signo)
{
__lsan_do_leak_check();
signal(signo, SIG_DFL);
raise(signo);
}
#endif

int main(int argc, char **argv)
{
Logger::linkToDbNative("sflowmgrd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting sflowmgrd ---");

#if defined(ASAN_ENABLED)
if (signal(SIGTERM, sigterm_handler) == SIG_ERR)
{
SWSS_LOG_ERROR("failed to setup SIGTERM action");
exit(1);
}
#endif

try
{
vector<string> cfg_sflow_tables = {
Expand Down
7 changes: 7 additions & 0 deletions cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "warm_restart.h"
#include <signal.h>

#if defined(ASAN_ENABLED)
#include <sanitizer/lsan_interface.h>
#endif

using namespace std;
using namespace swss;

Expand All @@ -26,6 +30,9 @@ bool received_sigterm = false;

void sig_handler(int signo)
{
#if defined(ASAN_ENABLED)
__lsan_do_leak_check();
#endif
received_sigterm = true;
return;
}
Expand Down
Loading

0 comments on commit 380fb43

Please sign in to comment.