From e3ef7787562645251773212b4f7d2ee3805bb79b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 14 Jul 2021 09:53:18 +0200 Subject: [PATCH] files: when the buffer is nameless, include the PID in name of dump file Make sure that when multiple nanos with nameless buffers die, each of them tries saving those buffers to different files. This addresses https://savannah.gnu.org/bugs/?60902. Reported-by: Julian Rosen --- src/nano.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nano.c b/src/nano.c index 7fea3ace..4f053dc8 100644 --- a/src/nano.c +++ b/src/nano.c @@ -309,15 +309,17 @@ void do_exit(void) statusbar(_("Cancelled")); } -/* Save the current buffer under the given name (or under the name "nano" +/* Save the current buffer under the given name (or under "nano." * for a nameless buffer). If needed, the name is modified to be unique. */ -void emergency_save(const char *plainname) +void emergency_save(char *plainname) { bool saved = FALSE; char *targetname; - if (*plainname == '\0') - plainname = "nano"; + if (*plainname == '\0') { + plainname = nrealloc(plainname, 28); + sprintf(plainname, "nano.%u", getpid()); + } targetname = get_next_filename(plainname, ".save");