files: when writing a lockfile fails, continue loading the file
Only when the user decides not to override an existing lockfile should loading the corresponding file be skipped. Any failure to write the lockfile should be ignored -- the file itself should be loaded anyway. This fixes https://savannah.gnu.org/bugs/?47945.master
parent
c8f530af93
commit
e65352bc8a
22
src/files.c
22
src/files.c
|
@ -165,8 +165,7 @@ void set_modified(void)
|
||||||
* origfilename: name of the file the lock is for
|
* origfilename: name of the file the lock is for
|
||||||
* modified: whether to set the modified bit in the file
|
* modified: whether to set the modified bit in the file
|
||||||
*
|
*
|
||||||
* Returns: 1 on success, 0 on failure (but continue loading), -1 on
|
* Returns 1 on success, and 0 on failure (but continue anyway). */
|
||||||
* failure and abort. */
|
|
||||||
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
|
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
|
||||||
{
|
{
|
||||||
int cflags, fd;
|
int cflags, fd;
|
||||||
|
@ -186,7 +185,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if ((mypwuid = getpwuid(myuid)) == NULL) {
|
if ((mypwuid = getpwuid(myuid)) == NULL) {
|
||||||
statusline(MILD, _("Couldn't determine my identity for lock file "
|
statusline(MILD, _("Couldn't determine my identity for lock file "
|
||||||
"(getpwuid() failed)"));
|
"(getpwuid() failed)"));
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
}
|
}
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|
||||||
|
@ -196,14 +195,14 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
else {
|
else {
|
||||||
statusline(MILD, _("Couldn't determine hostname for lock file: %s"),
|
statusline(MILD, _("Couldn't determine hostname for lock file: %s"),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the lock exists before we try to delete it...*/
|
/* Check if the lock exists before we try to delete it...*/
|
||||||
if (stat(lockfilename, &fileinfo) != -1)
|
if (stat(lockfilename, &fileinfo) != -1)
|
||||||
if (delete_lockfile(lockfilename) < 0)
|
if (delete_lockfile(lockfilename) < 0)
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
|
|
||||||
if (ISSET(INSECURE_BACKUP))
|
if (ISSET(INSECURE_BACKUP))
|
||||||
cflags = O_WRONLY | O_CREAT | O_APPEND;
|
cflags = O_WRONLY | O_CREAT | O_APPEND;
|
||||||
|
@ -218,8 +217,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
statusline(MILD, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
free(lockdata);
|
goto free_the_data;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now we've got a safe file stream. If the previous open() call
|
/* Now we've got a safe file stream. If the previous open() call
|
||||||
|
@ -229,7 +227,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if (fd < 0 || filestream == NULL) {
|
if (fd < 0 || filestream == NULL) {
|
||||||
statusline(MILD, _("Error writing lock file %s: %s"), lockfilename,
|
statusline(MILD, _("Error writing lock file %s: %s"), lockfilename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Okay, so at the moment we're following this state for how to
|
/* Okay, so at the moment we're following this state for how to
|
||||||
|
@ -266,7 +264,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if (wroteamt < lockdatalen) {
|
if (wroteamt < lockdatalen) {
|
||||||
statusline(MILD, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, ferror(filestream));
|
lockfilename, ferror(filestream));
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -276,7 +274,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
if (fclose(filestream) == EOF) {
|
if (fclose(filestream) == EOF) {
|
||||||
statusline(MILD, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
goto free_and_fail;
|
goto free_the_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfile->lock_filename = (char *) lockfilename;
|
openfile->lock_filename = (char *) lockfilename;
|
||||||
|
@ -284,9 +282,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
||||||
free(lockdata);
|
free(lockdata);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
free_and_fail:
|
free_the_data:
|
||||||
free(lockdata);
|
free(lockdata);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Less exciting, delete the lockfile. Return -1 if unsuccessful and
|
/* Less exciting, delete the lockfile. Return -1 if unsuccessful and
|
||||||
|
|
Loading…
Reference in New Issue