blob: c2757a2fb7f4cb0a0d67a82e664e1fc7084d8541 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From ba71f768e6dbb1f2ac72ed3bd880bff75a48d345 Mon Sep 17 00:00:00 2001
2From: Roy Li <rongqing.li@windriver.com>
3Date: Wed, 19 Feb 2014 14:13:40 +0800
4Subject: [PATCH] babeld: close stdout once the background daemon is created
5
6Upstream-Status: pending
7
8Once babald becomes a background daemon, it should not output information to
9stdout, so need to close stdout.
10
11In fact, other daemons close their stdout when they run into background, like
12ospfd, isisd and bgpd, by calling daemon() which is in lib/daemon.c
13
14Closing the stdout can fix a tee hang issue { #/usr/sbin/babeld -d |tee tmp }
15
16Signed-off-by: Roy Li <rongqing.li@windriver.com>
17---
18 babeld/util.c | 10 +++++++++-
19 1 file changed, 9 insertions(+), 1 deletion(-)
20
21diff --git a/babeld/util.c b/babeld/util.c
22index 011f382..76203bc 100644
23--- a/babeld/util.c
24+++ b/babeld/util.c
25@@ -425,7 +425,7 @@ uchar_to_in6addr(struct in6_addr *dest, const unsigned char *src)
26 int
27 daemonise()
28 {
29- int rc;
30+ int rc, fd;
31
32 fflush(stdout);
33 fflush(stderr);
34@@ -441,5 +441,13 @@ daemonise()
35 if(rc < 0)
36 return -1;
37
38+ fd = open("/dev/null", O_RDWR, 0);
39+ if (fd != -1)
40+ {
41+ dup2(fd, STDOUT_FILENO);
42+ if (fd > 2)
43+ close(fd);
44+ }
45+
46 return 1;
47 }
48--
491.7.10.4
50