From f494bfcbb996a26765aab2e436a55ccdfe9252a6 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 30 Jan 2020 19:04:28 +0100 Subject: [PATCH] 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. --- src/files.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/files.c b/src/files.c index c0efa32e..037f13ed 100644 --- 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;