2021-02-24 01:25:15 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c)2013-2021 ZeroTier, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
* Change Date: 2026-01-01
|
2021-02-24 01:25:15 -08:00
|
|
|
*
|
|
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
|
|
|
|
*/
|
|
|
|
|
/****/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
*
|
|
|
|
|
* Custom signal handler
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-16 00:31:45 -07:00
|
|
|
#ifdef ZTS_ENABLE_PYTHON
|
2021-04-22 11:20:04 -07:00
|
|
|
/**
|
|
|
|
|
* In some situations (Python comes to mind) a signal may not make its
|
|
|
|
|
* way to libzt, for this reason we make sure to define a custom signal
|
|
|
|
|
* handler that can at least process SIGTERMs
|
|
|
|
|
*/
|
|
|
|
|
#define ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS 1
|
2021-03-16 00:31:45 -07:00
|
|
|
#endif
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
|
|
|
#ifdef ZTS_ENABLE_CUSTOM_SIGNAL_HANDLERS
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
#include "Signals.hpp"
|
2021-04-17 23:46:21 -07:00
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
#include "ZeroTierSockets.h"
|
2021-03-16 00:31:45 -07:00
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
#include <signal.h>
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
|
|
|
void _signal_handler(int signal)
|
|
|
|
|
{
|
2021-04-26 22:07:55 -07:00
|
|
|
/*
|
|
|
|
|
switch(signal)
|
|
|
|
|
{
|
|
|
|
|
case SIGINT:
|
|
|
|
|
fprintf(stderr, "SIGINT\n");
|
|
|
|
|
break;
|
|
|
|
|
case SIGABRT:
|
|
|
|
|
fprintf(stderr, "SIGABRT\n");
|
|
|
|
|
break;
|
|
|
|
|
case SIGILL:
|
|
|
|
|
fprintf(stderr, "SIGILL\n");
|
|
|
|
|
break;
|
|
|
|
|
case SIGSEGV:
|
|
|
|
|
fprintf(stderr, "SIGSEGV\n");
|
|
|
|
|
break;
|
|
|
|
|
case SIGFPE:
|
|
|
|
|
fprintf(stderr, "SIGFPE\n");
|
|
|
|
|
break;
|
|
|
|
|
case SIGTERM:
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "SIGTERM\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
exit(signal);
|
2021-02-24 01:25:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _install_signal_handlers()
|
|
|
|
|
{
|
2021-04-26 22:07:55 -07:00
|
|
|
signal(SIGINT, &_signal_handler);
|
|
|
|
|
/*
|
|
|
|
|
signal(SIGABRT, &_signal_handler);
|
|
|
|
|
signal(SIGFPE, &_signal_handler);
|
|
|
|
|
signal(SIGILL, &_signal_handler);
|
|
|
|
|
signal(SIGSEGV, &_signal_handler);
|
|
|
|
|
signal(SIGTERM, &_signal_handler);
|
|
|
|
|
*/
|
2021-02-24 01:25:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|