aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-04-12 21:47:58 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-04-12 23:00:40 +0200
commit0a8770ac7d382df8976b2448fccc6cfe434cd4d1 (patch)
tree5551617b6bd61b069c9d538f19aea2dbc94b44c1 /src/ring.c
parent0e3d6c84a52326a1069fe4f7adc2930b974dfa5f (diff)
GTK: SIGTERM/SIGHUP always terminates the program and dumps recovery files
* SIGTERM used to insert the ^KCLOSE key macro. However with the default ^KCLOSE macro, which inserts `EX`, this may fail to terminate the editor if buffers are modified. If the process is consequently killed by a non-ignorable signal, we may still loose data. * SIGTERM is used to gracefully shut down, so we now always terminate. Since we have recovery files, they are now dumped before terminating. This makes sure that recovery files are more up-to-date during unexpected but gracefull terminations. * The same functionality is planned on Curses, but requires more fundamental changes (TODO).
Diffstat (limited to 'src/ring.c')
-rw-r--r--src/ring.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ring.c b/src/ring.c
index 8bb825c..9feb444 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -143,7 +143,12 @@ teco_buffer_save(teco_buffer_t *ctx, const gchar *filename, GError **error)
static inline void
teco_buffer_free(teco_buffer_t *ctx)
{
- if (ctx->state > TECO_BUFFER_DIRTY_NO_DUMP) {
+ /*
+ * During graceful, but unexpected shutdowns (SIGTERM etc.),
+ * we must preserve the recovery files.
+ */
+ if (ctx->state > TECO_BUFFER_DIRTY_NO_DUMP &&
+ teco_interrupted != TECO_TERMINATED) {
g_autofree gchar *filename_recovery = teco_buffer_get_recovery(ctx);
g_unlink(filename_recovery);
}
@@ -317,7 +322,8 @@ guint teco_ring_recovery_interval = 2*60;
/**
* Create recovery files for all dirty buffers.
*
- * Should be called by the interface every teco_ring_recovery_interval seconds.
+ * Should be called by the interface every teco_ring_recovery_interval seconds
+ * or before graceful terminations (SIGTERM etc.).
* This does not generate or expect undo tokens, so it can be called
* even when idlying.
*/