From 1ec9cb38cb51b9a11e5a1a01617efbf9e578d62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Thu, 11 Sep 2014 23:09:41 +0200 Subject: [PATCH] Open restart file in 0644 mode, fsync the file, don't write to file if seek/truncate failed --- src/restart_counter.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/restart_counter.c b/src/restart_counter.c index 958ade5..b785844 100644 --- a/src/restart_counter.c +++ b/src/restart_counter.c @@ -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); }