[CRIU] [PATCH 1/2] service: chdir(opts.root) if going daemon

Ruslan Kuprieiev kupruser at gmail.com
Sat Nov 2 17:36:15 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 510553f..6f54247 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -368,7 +368,19 @@ int cr_service(bool daemon_mode)
 	}
 
 	if (daemon_mode) {
-		if (daemon(0, 0) == -1) {
+		int nochdir = 0;
+
+		if (opts.root) {
+			if (chdir(opts.root)) {
+				pr_perror("Can't change directory to %s",
+								opts.root);
+				goto err;
+			}
+
+			nochdir = 1;
+		}
+
+		if (daemon(nochdir, 0) == -1) {
 			pr_perror("Can't run service server in the background");
 			goto err;
 		}
-- 
1.8.1.2



More information about the CRIU mailing list