diff options
author | Simo Sorce <simo@redhat.com> | 2012-01-13 12:06:02 -0500 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-01-14 16:48:08 -0500 |
commit | e4a560ed1df2fdac855f2e3f87ad24288cab9456 (patch) | |
tree | 98fed545f289a035a1e004d96ffde15fe8d8f6c1 | |
parent | abcb0ac958269fbeecf05100f90cc8dd61d811f2 (diff) | |
download | gss-proxy-e4a560ed1df2fdac855f2e3f87ad24288cab9456.tar.gz gss-proxy-e4a560ed1df2fdac855f2e3f87ad24288cab9456.tar.xz gss-proxy-e4a560ed1df2fdac855f2e3f87ad24288cab9456.zip |
add support for demonization option
-rw-r--r-- | proxy/src/gp_init.c | 29 | ||||
-rw-r--r-- | proxy/src/gp_utils.h | 2 | ||||
-rw-r--r-- | proxy/src/gssproxy.c | 2 |
3 files changed, 29 insertions, 4 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) diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h index ac690ac..8f0ae81 100644 --- a/proxy/src/gp_utils.h +++ b/proxy/src/gp_utils.h @@ -42,7 +42,7 @@ struct gp_config { struct gp_config *read_config(char *config_file, int opt_daemonize); /* from gp_init.c */ -void init_server(void); +void init_server(bool daemonize); void fini_server(void); verto_ctx *init_event_loop(void); diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index 5fc80cb..f1d679f 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -82,7 +82,7 @@ int main(int argc, const char *argv[]) config = read_config(opt_config_file, opt_daemon); - init_server(); + init_server(config->daemonize); fd = init_unix_socket(config->socket_name); if (fd == -1) { |