Open restart file in 0644 mode, fsync the file, don't

write to file if seek/truncate failed
This commit is contained in:
Nils O. Selåsdal
2014-09-11 23:09:41 +02:00
parent 5f89edc0d9
commit 711d734998
+5 -1
View File
@@ -33,7 +33,7 @@ UCRCResult uc_restart_counter_init(
counter->counter = 0;
counter->fd = -1;
fd = open(filename, O_CREAT|O_RDWR, 0600);
fd = open(filename, O_CREAT|O_RDWR, 0644);
if (fd == -1) {
return UC_RC_ERR_FILE_ACCESS_ERROR;
@@ -62,6 +62,7 @@ UCRCResult uc_restart_counter_init(
if (lseek(fd, 0, SEEK_SET) != 0 ||
ftruncate(fd,0) != 0) {
rc = UC_RC_ERR_UNSPECIFIED;
goto done;
}
@@ -75,6 +76,9 @@ UCRCResult uc_restart_counter_init(
rc = UC_RC_ERR_UNSPECIFIED;
}
fsync(fd);
done:
if ((flags & UC_RC_FL_LOCK_FILE) == 0) {
close(fd);
}