nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit f494bfcbb996a26765aab2e436a55ccdfe9252a6
parent b856fc4664e985f986fa38a76e38364d44a63be2
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 30 Jan 2020 19:04:28 +0100

locking: when a lock file is unreadable, open the file itself anyway

Unreadable or corrupt lock files are not a user error nor user intent,
so they should not keep the user from editing the corresponding file.

Also, combine some error conditions to compact the code.

This addresses https://savannah.gnu.org/bugs/?57700.

Diffstat:
Msrc/files.c | 12+++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -320,8 +320,9 @@ int do_lockfile(const char *filename, bool ask_the_user) size_t readamt = 0, readtot = 0; if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { - statusline(MILD, _("Error opening lock file %s: %s"), + statusline(ALERT, _("Error opening lock file %s: %s"), lockfilename, strerror(errno)); + retval = 0; goto free_the_name; } @@ -333,14 +334,7 @@ int do_lockfile(const char *filename, bool ask_the_user) close(lockfd); - if (readtot < 1024) { - statusline(MILD, _("Error reading lock file %s: " - "Not enough data read"), lockfilename); - free(lockbuf); - goto free_the_name; - } - - if (lockbuf[0] != 0x62 || lockbuf[1] != 0x30) { + if (readtot < 1024 || lockbuf[0] != 0x62 || lockbuf[1] != 0x30) { statusline(ALERT, _("Bad lock file is ignored: %s"), lockfilename); free(lockbuf); retval = 0;