From e4a560ed1df2fdac855f2e3f87ad24288cab9456 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 13 Jan 2012 12:06:02 -0500 Subject: add support for demonization option --- proxy/src/gp_init.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'proxy/src/gp_init.c') diff --git a/proxy/src/gp_init.c b/proxy/src/gp_init.c index eed0380..04eb0e0 100644 --- a/proxy/src/gp_init.c +++ b/proxy/src/gp_init.c @@ -31,8 +31,34 @@ #include #include "gp_utils.h" -void init_server(void) +void init_server(bool daemonize) { + pid_t pid, sid; + int ret; + + if (daemonize) { + + pid = fork(); + if (pid == -1) { + /* fork error ? abort */ + exit(EXIT_FAILURE); + } + if (pid != 0) { + /* ok kill the parent */ + exit(EXIT_SUCCESS); + } + + sid = setsid(); + if (sid == -1) { + /* setsid error ? abort */ + exit(EXIT_FAILURE); + } + } + + ret = chdir("/"); + if (ret == -1) { + exit(EXIT_FAILURE); + } /* Set strict umask by default */ umask(0177); @@ -43,7 +69,6 @@ void init_server(void) openlog("gssproxy", LOG_CONS|LOG_NDELAY|LOG_NOWAIT|LOG_PERROR|LOG_PID, LOG_AUTHPRIV); - } void fini_server(void) -- cgit