[Sheepdog] [PATCH] logger: fix error return path

Liu Yuan namei.unix at gmail.com
Thu Sep 22 10:43:26 CEST 2011


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

We should return immediately when 'open' error-returns. This will make dangling
logger process disappear in error case.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 lib/logger.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/lib/logger.c b/lib/logger.c
index 146b83a..15f5055 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -387,8 +387,10 @@ int log_init(char *program_name, int size, int is_daemon, int level, char *outfi
 
 		if (outfile) {
 			fd = open(outfile, O_CREAT | O_RDWR | O_APPEND, 0644);
-			if (fd < 0)
+			if (fd < 0) {
 				syslog(LOG_ERR, "failed to open %s\n", outfile);
+				return 1;
+			}
 		} else {
 			fd = -1;
 			openlog(log_name, 0, LOG_DAEMON);
-- 
1.7.6.1




More information about the sheepdog mailing list