diff options
author | Emmanuel Bretelle <chantra@debuntu.org> | 2010-09-07 15:46:40 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-10-20 11:04:51 +0200 |
commit | 68521860e0fbd513c24ec47aa54c2b39c13b6f8c (patch) | |
tree | ae149307505ccb6280ac1d89bb4d84ac68f02654 /ggsn | |
parent | 111e0545436af44862e2d373a2b9f1c9523845ce (diff) |
Fixed compile warning,exit if cant daemonize
Relevant output of make:
ggsn.c: In function ‘main’:
ggsn.c:436: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:437: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:438: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:439: warning: ignoring return value of ‘daemon’, declared with
attribute warn_unused_result
Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
Diffstat (limited to 'ggsn')
-rw-r--r-- | ggsn/ggsn.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 52a2022..8b71884 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -430,13 +430,28 @@ int main(int argc, char **argv) /* If flag not given run as a daemon */ if (!args_info.fg_flag) { + FILE *f; + int rc; closelog(); /* Close the standard file descriptors. */ /* Is this really needed ? */ - freopen("/dev/null", "w", stdout); - freopen("/dev/null", "w", stderr); - freopen("/dev/null", "r", stdin); - daemon(0, 0); + f = freopen("/dev/null", "w", stdout); + if (f == NULL) { + sys_err(LOG_WARNING, __FILE__, __LINE__, 0, "Could not redirect stdout to /dev/null"); + } + f = freopen("/dev/null", "w", stderr); + if (f == NULL) { + sys_err(LOG_WARNING, __FILE__, __LINE__, 0, "Could not redirect stderr to /dev/null"); + } + f = freopen("/dev/null", "r", stdin); + if (f == NULL) { + sys_err(LOG_WARNING, __FILE__, __LINE__, 0, "Could not redirect stdin to /dev/null"); + } + rc = daemon(0, 0); + if (rc != 0) { + sys_err(LOG_ERR, __FILE__, __LINE__, rc, "Could not daemonize"); + exit(1); + } /* Open log again. This time with new pid */ openlog(PACKAGE, LOG_PID, LOG_DAEMON); } |