[sheepdog] [PATCH] sheep: write config data when config file is zero byte

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Oct 2 20:58:02 CEST 2012


If sheep is killed just after config file is created but before no
bytes is written, the size of the config file would be zero byte.  In
this case, we should recreate config file rather than exiting with a
version error.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/config.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/sheep/config.c b/sheep/config.c
index 04a934c..b2e9f58 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -77,15 +77,14 @@ int init_config_path(const char *base_path)
 			eprintf("failed to read config file, %m\n");
 			return -1;
 		}
-
-		config.version = SD_FORMAT_VERSION;
-		if (write_config() != SD_RES_SUCCESS)
-			return -1;
-
-		return 0;
+		goto create;
 	}
 
 	ret = xread(fd, &config, sizeof(config));
+	if (ret == 0) {
+		close(fd);
+		goto create;
+	}
 	if (ret < 0) {
 		eprintf("failed to read config file, %m\n");
 		goto out;
@@ -109,6 +108,12 @@ out:
 	close(fd);
 
 	return ret;
+create:
+	config.version = SD_FORMAT_VERSION;
+	if (write_config() != SD_RES_SUCCESS)
+		return -1;
+
+	return 0;
 }
 
 int set_cluster_ctime(uint64_t ct)
-- 
1.7.2.5




More information about the sheepdog mailing list