Do not assert on SIGTERM and backup modified buffers on signal induced termination
This commit is contained in:
parent
fa85f0fc32
commit
2adaa7bdfa
|
@ -105,6 +105,15 @@ void BufferManager::set_last_used_buffer(Buffer& buffer)
|
|||
m_buffers.emplace(m_buffers.begin(), &buffer);
|
||||
}
|
||||
|
||||
void BufferManager::backup_modified_buffers()
|
||||
{
|
||||
for (auto& buf : m_buffers)
|
||||
{
|
||||
if ((buf->flags() & Buffer::Flags::File) and buf->is_modified())
|
||||
write_buffer_to_backup_file(*buf);
|
||||
}
|
||||
}
|
||||
|
||||
CandidateList BufferManager::complete_buffer_name(StringView prefix,
|
||||
ByteCount cursor_pos)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
Buffer& get_buffer(StringView name);
|
||||
void set_last_used_buffer(Buffer& buffer);
|
||||
|
||||
void backup_modified_buffers();
|
||||
|
||||
CandidateList complete_buffer_name(StringView prefix,
|
||||
ByteCount cursor_pos = -1);
|
||||
|
||||
|
|
13
src/file.cc
13
src/file.cc
|
@ -209,6 +209,19 @@ void write_buffer_to_file(Buffer& buffer, StringView filename)
|
|||
buffer.run_hook_in_own_context("BufWritePost", buffer.name());
|
||||
}
|
||||
|
||||
void write_buffer_to_backup_file(Buffer& buffer)
|
||||
{
|
||||
char pattern[PATH_MAX+1];
|
||||
snprintf(pattern, PATH_MAX+1, ".%s.kak.XXXXXX",
|
||||
real_path(buffer.name()).c_str());
|
||||
int fd = mkstemp(pattern);
|
||||
if (fd >= 0)
|
||||
{
|
||||
write_buffer_to_fd(buffer, fd);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
String find_file(StringView filename, memoryview<String> paths)
|
||||
{
|
||||
struct stat buf;
|
||||
|
|
|
@ -36,6 +36,7 @@ Buffer* create_buffer_from_file(String filename);
|
|||
|
||||
void write_buffer_to_file(Buffer& buffer, StringView filename);
|
||||
void write_buffer_to_fd(Buffer& buffer, int fd);
|
||||
void write_buffer_to_backup_file(Buffer& buffer);
|
||||
|
||||
String find_file(StringView filename, memoryview<String> paths);
|
||||
|
||||
|
|
12
src/main.cc
12
src/main.cc
|
@ -252,10 +252,18 @@ void signal_handler(int signal)
|
|||
case SIGQUIT: text = "SIGQUIT"; break;
|
||||
case SIGTERM: text = "SIGTERM"; break;
|
||||
}
|
||||
on_assert_failed(text);
|
||||
if (signal != SIGTERM)
|
||||
on_assert_failed(text);
|
||||
|
||||
if (Server::has_instance())
|
||||
Server::instance().close_session();
|
||||
abort();
|
||||
if (BufferManager::has_instance())
|
||||
BufferManager::instance().backup_modified_buffers();
|
||||
|
||||
if (signal == SIGTERM)
|
||||
exit(-1);
|
||||
else
|
||||
abort();
|
||||
}
|
||||
|
||||
int run_client(StringView session, StringView init_command)
|
||||
|
|
Loading…
Reference in New Issue
Block a user