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 --- editor.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'editor.h') diff --git a/editor.h b/editor.h index 76a3136..3e8e644 100644 --- a/editor.h +++ b/editor.h @@ -5,6 +5,7 @@ #include #include #include +#include typedef struct Editor Editor; typedef struct File File; @@ -190,6 +191,7 @@ enum Mark { struct File { Text *text; const char *name; + volatile sig_atomic_t truncated; bool is_stdin; struct stat stat; int refcount; @@ -244,6 +246,8 @@ struct Editor { Mode *mode_before_prompt; /* user mode which was active before entering prompt */ volatile bool running; /* exit main loop once this becomes false */ volatile sig_atomic_t cancel_filter; /* abort external command */ + volatile sig_atomic_t sigbus; + sigjmp_buf sigbus_jmpbuf; }; Editor *editor_new(Ui*); -- cgit v1.2.3