[CRIU] [PATCH 1/2] service: write pidfile before chdir to /, if going daemon

Ruslan Kuprieiev kupruser at gmail.com
Tue Oct 29 16:27:33 PDT 2013


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-service.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/cr-service.c b/cr-service.c
index 771944c..fbf9d20 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -303,7 +303,11 @@ int cr_service(bool daemon_mode)
 	}
 
 	if (daemon_mode) {
-		if (daemon(0, 0) == -1) {
+		/*
+		 * Will chdir to /, after writing pidfile,
+		 * so pidfile path will be resolved properly.
+		 */
+		if (daemon(1, 0) == -1) {
 			pr_perror("Can't run service server in the background");
 			goto err;
 		}
@@ -316,6 +320,14 @@ int cr_service(bool daemon_mode)
 		}
 	}
 
+	if (daemon_mode) {
+		/* And now we can chdir to /. */
+		if (chdir("/")) {
+			pr_perror("Can't chdir to /");
+			return -1;
+		}
+	}
+
 	/* FIXME Do not ignore children's return values */
 	signal(SIGCHLD, SIG_IGN);
 
-- 
1.8.1.2



More information about the CRIU mailing list