summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_init.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-01-03 12:10:36 -0500
committerGünther Deschner <gdeschner@redhat.com>2014-01-15 17:55:32 +0100
commitbd8ffcf67be8fdbe14bc49a65a8eafe904119d88 (patch)
treee67afcbe336c0775a4933024eb3986556aed43fc /proxy/src/gp_init.c
parent58a39677c961c72b052eae0b9d94b992254d6e10 (diff)
downloadgss-proxy-bd8ffcf67be8fdbe14bc49a65a8eafe904119d88.tar.gz
gss-proxy-bd8ffcf67be8fdbe14bc49a65a8eafe904119d88.tar.xz
gss-proxy-bd8ffcf67be8fdbe14bc49a65a8eafe904119d88.zip
Block parent process until child is initialized.
This way the init system will not proceed starting dependencies until gssproxy is actually ready to serve requests. In particular this is used to make sure the nfsd proc file has been touched before the nfsd server is started. Resolves: https://fedorahosted.org/gss-proxy/ticket/114 Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Günther Deschner <gdeschner@redhat.com>
Diffstat (limited to 'proxy/src/gp_init.c')
-rw-r--r--proxy/src/gp_init.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/proxy/src/gp_init.c b/proxy/src/gp_init.c
index 830ae16..6207a78 100644
--- a/proxy/src/gp_init.c
+++ b/proxy/src/gp_init.c
@@ -37,12 +37,22 @@
#include <grp.h>
#include "gp_proxy.h"
-void init_server(bool daemonize)
+void init_server(bool daemonize, int *wait_fd)
{
pid_t pid, sid;
int ret;
+ *wait_fd = -1;
+
if (daemonize) {
+ int pipefd[2];
+ char buf[1];
+
+ /* create parent-child pipe */
+ ret = pipe(pipefd);
+ if (ret == -1) {
+ exit(EXIT_FAILURE);
+ }
pid = fork();
if (pid == -1) {
@@ -50,10 +60,22 @@ void init_server(bool daemonize)
exit(EXIT_FAILURE);
}
if (pid != 0) {
- /* ok kill the parent */
- exit(EXIT_SUCCESS);
+ /* wait for child to signal it is ready */
+ close(pipefd[1]);
+ ret = gp_safe_read(pipefd[0], buf, 1);
+ if (ret == 1) {
+ /* child signaled all ok */
+ exit(EXIT_SUCCESS);
+ } else {
+ /* lost child, something went wrong */
+ exit(EXIT_FAILURE);
+ }
}
+ /* child */
+ close(pipefd[0]);
+ *wait_fd = pipefd[1];
+
sid = setsid();
if (sid == -1) {
/* setsid error ? abort */
@@ -78,6 +100,20 @@ void init_server(bool daemonize)
gp_logging_init();
}
+void init_done(int wait_fd)
+{
+ char buf = 0;
+ int ret;
+
+ if (wait_fd != -1) {
+ ret = gp_safe_write(wait_fd, &buf, 1);
+ if (ret != 1) {
+ exit(EXIT_FAILURE);
+ }
+ close(wait_fd);
+ }
+}
+
void fini_server(void)
{
closelog();