summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'proxy/src/gp_init.c')
-rw-r--r--proxy/src/gp_init.c29
1 files changed, 27 insertions, 2 deletions
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 <signal.h>
#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)