[sheepdog] [PATCH UPDATE] sheep: allow working direcotry to be specified as storage directory

Liu Yuan namei.unix at gmail.com
Tue Dec 4 07:02:02 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/sheep.c |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/sheep/sheep.c b/sheep/sheep.c
index c201d88..a54e008 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -334,7 +334,8 @@ int main(int argc, char **argv)
 {
 	int ch, longindex;
 	int ret, port = SD_LISTEN_PORT;
-	const char *dir = DEFAULT_OBJECT_DIR;
+	const char *dirp = DEFAULT_OBJECT_DIR;
+	char *dir;
 	bool is_daemon = true;
 	bool to_stdout = false;
 	int log_level = SDOG_INFO;
@@ -486,7 +487,17 @@ int main(int argc, char **argv)
 	}
 
 	if (optind != argc)
-		dir = argv[optind];
+		dirp = argv[optind];
+
+	ret = init_base_path(dirp);
+	if (ret)
+		exit(1);
+
+	dir = realpath(dirp, NULL);
+	if (!dir) {
+		fprintf(stderr, "%m\n");
+		exit(1);
+	}
 
 	snprintf(path, sizeof(path), "%s/" LOG_FILE_NAME, dir);
 
@@ -495,10 +506,6 @@ int main(int argc, char **argv)
 	if (is_daemon && daemon(0, 0))
 		exit(1);
 
-	ret = init_base_path(dir);
-	if (ret)
-		exit(1);
-
 	ret = log_init(program_name, LOG_SPACE_SIZE, to_stdout, log_level, path);
 	if (ret)
 		exit(1);
@@ -576,6 +583,7 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
+	free(dir);
 	vprintf(SDOG_NOTICE, "sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
 
 	while (sys->nr_outstanding_reqs != 0 ||
-- 
1.7.9.5




More information about the sheepdog mailing list