locking: ignore the insecure-backup flag when creating a lock file

One microsecond before a lock file is created an existing lock file
has been deleted, and if that deletion failed, writing the lock file
is aborted.  So why should writing the lock file not be aborted when
the lock file cannot be exclusively created one microsecond later?
This makes no sense.  So... always include the O_EXCL flag, also
when the INSECURE_BACKUP flag is set.

(And anyway: lock files are not an essential part of editing, they
are just a small service to the user, AND they have nothing to do
with backups, so a backup flag should not influence them.)
master
Benno Schulenberg 2020-05-19 14:56:37 +02:00
parent 44fd299921
commit c45df589fa
1 changed files with 2 additions and 7 deletions

View File

@ -129,7 +129,7 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
struct passwd *mypwuid = getpwuid(myuid);
char myhostname[32];
struct stat fileinfo;
int cflags, fd;
int fd;
FILE *filestream;
char *lockdata;
size_t wroteamt;
@ -151,13 +151,8 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
if (!delete_lockfile(lockfilename))
return FALSE;
if (ISSET(INSECURE_BACKUP))
cflags = O_WRONLY | O_CREAT | O_APPEND;
else
cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND;
/* Try to create the lockfile. */
fd = open(lockfilename, cflags, RW_FOR_ALL);
fd = open(lockfilename, O_CREAT|O_EXCL|O_WRONLY, RW_FOR_ALL);
if (fd < 0) {
statusline(MILD, _("Error writing lock file %s: %s"),