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.
master
Benno Schulenberg 2020-01-30 19:04:28 +01:00
parent b856fc4664
commit f494bfcbb9
1 changed files with 3 additions and 9 deletions

View File

@ -320,8 +320,9 @@ int do_lockfile(const char *filename, bool ask_the_user)
size_t readamt = 0, readtot = 0; size_t readamt = 0, readtot = 0;
if ((lockfd = open(lockfilename, O_RDONLY)) < 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)); lockfilename, strerror(errno));
retval = 0;
goto free_the_name; goto free_the_name;
} }
@ -333,14 +334,7 @@ int do_lockfile(const char *filename, bool ask_the_user)
close(lockfd); close(lockfd);
if (readtot < 1024) { if (readtot < 1024 || lockbuf[0] != 0x62 || lockbuf[1] != 0x30) {
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) {
statusline(ALERT, _("Bad lock file is ignored: %s"), lockfilename); statusline(ALERT, _("Bad lock file is ignored: %s"), lockfilename);
free(lockbuf); free(lockbuf);
retval = 0; retval = 0;