Source
xxxxxxxxxx
/* the parent process can either politely ask a child process to finish it's work and perform cleanup */
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
int sig_parent_pid = -1;
static volatile sig_atomic_t sig_exiting;
static volatile sig_atomic_t sig_exit_on_terminate = 1;
static zbx_on_exit_t zbx_on_exit_cb = NULL;
void zbx_set_exiting_with_fail(void)
{
sig_exiting = ZBX_EXIT_FAILURE;
}
void zbx_set_exiting_with_succeed(void)
{
sig_exiting = ZBX_EXIT_SUCCESS;
}
int ZBX_IS_RUNNING(void)
{
return ZBX_EXIT_NONE == sig_exiting;
}
int ZBX_EXIT_STATUS(void)
{
return ZBX_EXIT_SUCCESS == sig_exiting ? SUCCEED : FAIL;
}
static void log_fatal_signal(int sig, siginfo_t *siginfo, void *context)
{
SIG_CHECK_PARAMS(sig, siginfo, context);
zabbix_log(LOG_LEVEL_CRIT, "Got signal [signal:%d(%s),reason:%d,refaddr:%p]. Crashing ...",
sig, get_signal_name(sig),
SIG_CHECKED_FIELD(siginfo, si_code),
SIG_CHECKED_FIELD_TYPE(siginfo, si_addr, void *));
}
static void exit_with_failure(void)
{
zbx_tls_free_on_signal();
_exit(EXIT_FAILURE);
}
/******************************************************************************
* *
* Purpose: handle fatal signals: SIGILL, SIGFPE, SIGSEGV, SIGBUS *
* *
******************************************************************************/
static void fatal_signal_handler(int sig, siginfo_t *siginfo, void *context)
{
log_fatal_signal(sig, siginfo, context);
zbx_log_fatal_info(context, ZBX_FATAL_LOG_FULL_INFO);
exit_with_failure();
}
/******************************************************************************
* *
* Purpose: same as fatal_signal_handler() but customized for metric thread - *
* does not log memory map *