[CRIU] [PATCH 6/7] img-cache: Daemonize on start

Radostin Stoyanov rstoyanov1 at gmail.com
Sun Jul 8 19:47:10 MSK 2018


When the --daemon option is passed to image-cache, it will wait until a
connection with image-proxy is established, and then will continue its
execution in the background (daemonize).

This commit will daemonize image-cache immediately after start. This
enables the following two commands to be executed sequentially (in a
single terminal window):

$ criu image-cache -d --port 1234 -o img-cache.log
$ criu image-proxy -d --port 1234 --address 0.0.0.0 -o img-proxy.log

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 criu/img-cache.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/criu/img-cache.c b/criu/img-cache.c
index ac737150..91f473fb 100644
--- a/criu/img-cache.c
+++ b/criu/img-cache.c
@@ -65,6 +65,13 @@ int image_cache(bool background, char *local_cache_path, unsigned short cache_wr
 			cache_write_port, local_cache_path);
 	restoring = true;
 
+	if (background) {
+		if (daemon(1, 0) == -1) {
+			pr_perror("Can't run service server in the background");
+			return -1;
+		}
+	}
+
 	if (opts.ps_socket != -1) {
 		proxy_to_cache_fd = opts.ps_socket;
 		pr_info("Re-using ps socket %d\n", proxy_to_cache_fd);
@@ -89,13 +96,6 @@ int image_cache(bool background, char *local_cache_path, unsigned short cache_wr
 
 	}
 
-	if (background) {
-		if (daemon(1, 0) == -1) {
-			pr_perror("Can't run service server in the background");
-			return -1;
-		}
-	}
-
 	accept_image_connections();
 	pr_info("Finished image cache.");
 	return 0;
-- 
2.17.1



More information about the CRIU mailing list