From 0fa9885cda0778467ca5737ac888ece5ef371b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 17 Jul 2015 14:38:36 +0200 Subject: vis: handle file truncation more gracefully If we use the file / virtual memory system as cache (using mmap(2)) and another process truncates the file we are editing, we have a problem. All we can do is catch the resulting SIGBUS, close the corresponding window and print a warning message. To test this use: $ dd if=/dev/zero of=TEST bs=8M count=1 $ vis TEST :! echo TRUNCATE > TEST --- text.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'text.c') diff --git a/text.c b/text.c index be9a8f5..5f516bc 100644 --- a/text.c +++ b/text.c @@ -1185,6 +1185,14 @@ bool text_modified(Text *txt) { return txt->saved_action != txt->history; } +bool text_sigbus(Text *txt, const char *addr) { + for (Buffer *buf = txt->buffers; buf; buf = buf->next) { + if (buf->type == MMAP && buf->data <= addr && addr < buf->data + buf->size) + return true; + } + return false; +} + enum TextNewLine text_newline_type(Text *txt){ if (!txt->newlines) { txt->newlines = TEXT_NEWLINE_NL; /* default to UNIX style \n new lines */ -- cgit v1.2.3