commit e65352bc8aa32302e2a939bdf0880d8dd2a7b11b
parent c8f530af936d1c0a6a12d829a6734e508c832e92
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 21 May 2016 12:45:10 +0200
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.
Diffstat:
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -165,8 +165,7 @@ void set_modified(void)
* origfilename: name of the file the lock is for
* modified: whether to set the modified bit in the file
*
- * Returns: 1 on success, 0 on failure (but continue loading), -1 on
- * failure and abort. */
+ * Returns 1 on success, and 0 on failure (but continue anyway). */
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
{
int cflags, fd;
@@ -186,7 +185,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
if ((mypwuid = getpwuid(myuid)) == NULL) {
statusline(MILD, _("Couldn't determine my identity for lock file "
"(getpwuid() failed)"));
- goto free_and_fail;
+ goto free_the_data;
}
mypid = getpid();
@@ -196,14 +195,14 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
else {
statusline(MILD, _("Couldn't determine hostname for lock file: %s"),
strerror(errno));
- goto free_and_fail;
+ goto free_the_data;
}
}
/* Check if the lock exists before we try to delete it...*/
if (stat(lockfilename, &fileinfo) != -1)
if (delete_lockfile(lockfilename) < 0)
- goto free_and_fail;
+ goto free_the_data;
if (ISSET(INSECURE_BACKUP))
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) {
statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno));
- free(lockdata);
- return 0;
+ goto free_the_data;
}
/* 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) {
statusline(MILD, _("Error writing lock file %s: %s"), lockfilename,
strerror(errno));
- goto free_and_fail;
+ goto free_the_data;
}
/* 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) {
statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, ferror(filestream));
- goto free_and_fail;
+ goto free_the_data;
}
#ifdef DEBUG
@@ -276,7 +274,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
if (fclose(filestream) == EOF) {
statusline(MILD, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno));
- goto free_and_fail;
+ goto free_the_data;
}
openfile->lock_filename = (char *) lockfilename;
@@ -284,9 +282,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
free(lockdata);
return 1;
- free_and_fail:
+ free_the_data:
free(lockdata);
- return -1;
+ return 0;
}
/* Less exciting, delete the lockfile. Return -1 if unsuccessful and