[Sheepdog] [PATCH] sheep: stop logger process before terminating
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Sun Aug 14 08:18:58 CEST 2011
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/sheep.c | 44 +++++++++++++++++++++++++++++---------------
sheep/sheep_priv.h | 1 +
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 695aa95..8b35777 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -75,6 +75,7 @@ int main(int argc, char **argv)
char path[PATH_MAX];
int64_t zone = -1;
char *p;
+ int status = 0;
signal(SIGPIPE, SIG_IGN);
@@ -129,34 +130,47 @@ int main(int argc, char **argv)
srandom(port);
ret = init_store(dir);
- if (ret)
- exit(1);
+ if (ret) {
+ status = 1;
+ goto out;
+ }
ret = log_init(program_name, LOG_SPACE_SIZE, is_daemon, log_level, path);
- if (ret)
- exit(1);
+ if (ret) {
+ status = 1;
+ goto out;
+ }
- if (is_daemon && daemon(0, 0))
- exit(1);
+ if (is_daemon && daemon(0, 0)) {
+ status = 1;
+ goto out;
+ }
jrnl_recover();
ret = init_event(EPOLL_SIZE);
- if (ret)
- exit(1);
+ if (ret) {
+ status = 1;
+ goto out;
+ }
ret = init_work_queue(NR_WORKER_THREAD);
- if (ret)
- exit(1);
+ if (ret) {
+ status = 1;
+ goto out;
+ }
ret = create_listen_port(port, sys);
- if (ret)
- exit(1);
+ if (ret) {
+ status = 1;
+ goto out;
+ }
ret = create_cluster(port, zone);
if (ret) {
eprintf("failed to create sheepdog cluster.\n");
- exit(1);
+ status = 1;
+ goto out;
}
vprintf(SDOG_NOTICE "Sheepdog daemon (version %s) started\n", PACKAGE_VERSION);
@@ -165,8 +179,8 @@ int main(int argc, char **argv)
event_loop(-1);
vprintf(SDOG_INFO "shutdown\n");
-
+out:
log_close();
- return 0;
+ return status;
}
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index f8f8c65..b80c747 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -292,6 +292,7 @@ static inline int is_myself(uint8_t *addr, uint16_t port)
#define panic(fmt, args...) \
({ \
vprintf(SDOG_EMERG fmt, ##args); \
+ log_close(); \
exit(1); \
})
--
1.7.2.5
More information about the sheepdog
mailing list