Handle SIGTERM as a graceful exit, similar to the :kill!
command
Do not backup modified files, go through graceful destruction of singletons. Fixes #3528
This commit is contained in:
parent
91914a8501
commit
60dda1a597
10
src/main.cc
10
src/main.cc
|
@ -713,6 +713,7 @@ int run_server(StringView session, StringView server_init,
|
||||||
ConstArrayView<StringView> files)
|
ConstArrayView<StringView> files)
|
||||||
{
|
{
|
||||||
static bool terminate = false;
|
static bool terminate = false;
|
||||||
|
set_signal_handler(SIGTERM, [](int) { terminate = true; });
|
||||||
if (flags & ServerFlags::Daemon)
|
if (flags & ServerFlags::Daemon)
|
||||||
{
|
{
|
||||||
if (session.empty())
|
if (session.empty())
|
||||||
|
@ -727,7 +728,6 @@ int run_server(StringView session, StringView server_init,
|
||||||
session, child));
|
session, child));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
set_signal_handler(SIGTERM, [](int) { terminate = true; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventManager event_manager;
|
EventManager event_manager;
|
||||||
|
@ -992,25 +992,19 @@ void signal_handler(int signal)
|
||||||
case SIGSEGV: text = "SIGSEGV"; break;
|
case SIGSEGV: text = "SIGSEGV"; break;
|
||||||
case SIGFPE: text = "SIGFPE"; break;
|
case SIGFPE: text = "SIGFPE"; break;
|
||||||
case SIGQUIT: text = "SIGQUIT"; break;
|
case SIGQUIT: text = "SIGQUIT"; break;
|
||||||
case SIGTERM: text = "SIGTERM"; break;
|
|
||||||
case SIGPIPE: text = "SIGPIPE"; break;
|
case SIGPIPE: text = "SIGPIPE"; break;
|
||||||
}
|
}
|
||||||
if (signal != SIGTERM)
|
|
||||||
{
|
|
||||||
auto msg = format("Received {}, exiting.\nPid: {}\nCallstack:\n{}",
|
auto msg = format("Received {}, exiting.\nPid: {}\nCallstack:\n{}",
|
||||||
text, getpid(), Backtrace{}.desc());
|
text, getpid(), Backtrace{}.desc());
|
||||||
write_stderr(msg);
|
write_stderr(msg);
|
||||||
notify_fatal_error(msg);
|
notify_fatal_error(msg);
|
||||||
}
|
|
||||||
|
|
||||||
if (Server::has_instance())
|
if (Server::has_instance())
|
||||||
Server::instance().close_session();
|
Server::instance().close_session();
|
||||||
if (BufferManager::has_instance())
|
if (BufferManager::has_instance())
|
||||||
BufferManager::instance().backup_modified_buffers();
|
BufferManager::instance().backup_modified_buffers();
|
||||||
|
|
||||||
if (signal == SIGTERM)
|
if (signal == SIGSEGV)
|
||||||
exit(-1);
|
|
||||||
else if (signal == SIGSEGV)
|
|
||||||
{
|
{
|
||||||
// generate core dump
|
// generate core dump
|
||||||
::signal(SIGSEGV, SIG_DFL);
|
::signal(SIGSEGV, SIG_DFL);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user