9
0
Fork 0

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>
This commit is contained in:
Emmanuel Bretelle 2010-09-07 15:46:40 +02:00 committed by Harald Welte
parent 111e054543
commit 68521860e0
1 changed files with 19 additions and 4 deletions

View File

@ -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);
}