[CRIU] [PATCH 2/2] page-xfer: chdir(opts.root) if going daemon

Ruslan Kuprieiev kupruser at gmail.com
Sat Nov 2 17:36:16 PDT 2013


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
BTW, why we were returning -errno here?

 page-xfer.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/page-xfer.c b/page-xfer.c
index 087595f..10d83b4 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -267,12 +267,25 @@ int cr_page_server(bool daemon_mode)
 		goto out;
 	}
 
-	if (daemon_mode)
-		if(daemon(0, 0) == -1){
-			pr_perror("Can't run in the background");
-			return -errno;
+	if (daemon_mode) {
+		int nochdir = 0;
+
+		if (opts.root) {
+			if (chdir(opts.root)) {
+				pr_perror("Can't change directory to %s",
+								opts.root);
+				goto out;
+			}
+
+			nochdir = 1;
 		}
 
+		if (daemon(nochdir, 0) == -1) {
+			pr_perror("Can't run page-server in the background");
+			goto out;
+		}
+	}
+
 	if (opts.pidfile) {
 		if (write_pidfile(opts.pidfile, getpid()) == -1) {
 			pr_perror("Can't write pidfile");
-- 
1.8.1.2



More information about the CRIU mailing list