1
1

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.
Этот коммит содержится в:
Benno Schulenberg 2020-01-30 19:04:28 +01:00
родитель b856fc4664
Коммит f494bfcbb9

Просмотреть файл

@ -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;